Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed issues with cart window & demo header + Breadcrumbs Kafka #14

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/components/cart/MutateCartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ export const MutateCartButton: FC<MutateCartButtonProps> = ({
className
)}>
<PlusCircleIcon
onClick={incrementProductQuantity}
onClick={(e) => {
e.stopPropagation();
incrementProductQuantity();
}}
size={iconConfig?.plusIconSize}
strokeWidth={iconConfig?.plusIconStrokeWidth}
/>
<span className="ml-2 mr-2">{cartItem.quantity}</span>
<MinusCircleIcon
onClick={decrementProductQuantity}
onClick={(e) => {
e.stopPropagation();
decrementProductQuantity();
}}
size={iconConfig?.minusIconSize}
strokeWidth={iconConfig?.minusIconStrokeWidth}
/>
Expand Down
2 changes: 1 addition & 1 deletion app/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Header = () => {
</Link>
<NavMenu />
</div>
<div className="absolute top-[20px] right-[10px] md:right-[30px]">
<div className="absolute top-[40px] sm:top-[30px] md:top-[20px] right-[10px] md:right-[30px]">
<div className="w-full h-full flex flex-row gap-2 md:gap-4 items-center justify-center">
<UserButtons />
<CartDropdownMenu />
Expand Down
18 changes: 17 additions & 1 deletion app/components/header/breadcrumb/CategoryPart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';
import {useGetCategoryQuery} from '@/app/lib/api/categories-slice';
import {dispatchUserEvent} from '@/app/lib/kafka/dispatch/user-events';
import {useUser} from '@clerk/nextjs';
import {HomeIcon} from 'lucide-react';
import Link from 'next/link';
import {FC, useMemo} from 'react';
Expand All @@ -13,6 +15,8 @@ export const BreadcrumbCategoryPart: FC<BreadcrumbCategoryPartProps> = ({
}) => {
// fetch data
const categoryFetch = useGetCategoryQuery(categoryId);
// user data for recording events
const {user} = useUser();

// Method to get the categories part of the breadcrumb
const getCategoriesPart = useMemo(() => {
Expand All @@ -28,7 +32,19 @@ export const BreadcrumbCategoryPart: FC<BreadcrumbCategoryPartProps> = ({
<Link
key="category"
href={`/category/${categoryId}`}
className="cursor-pointer">
className="cursor-pointer"
onClick={(e) => {
e.preventDefault();
if (user) {
dispatchUserEvent({
user_id: user.id,
event_type: 'click',
core_component: 'breadcrumb',
description: `Clicked on category in breadcrumb for category ${categoryFetch.data?.name}`,
metadata: {category_id: categoryId},
});
}
}}>
{categoryFetch.data.name}
</Link>
</>
Expand Down
18 changes: 17 additions & 1 deletion app/components/header/breadcrumb/ProductPart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';
import {useGetProductQuery} from '@/app/lib/api/products-api-slice';
import {dispatchUserEvent} from '@/app/lib/kafka/dispatch/user-events';
import {useUser} from '@clerk/nextjs';
import Link from 'next/link';
import {FC, useMemo} from 'react';

Expand All @@ -16,6 +18,8 @@ export const BreadcrumbProductPart: FC<BreadcrumbProductPartProps> = ({
}) => {
// fetch data
const productFetch = useGetProductQuery(productId);
// user data for recording events
const {user} = useUser();

// Method to get the products part of the breadcrumb
const getProductsPart = useMemo(() => {
Expand All @@ -28,7 +32,19 @@ export const BreadcrumbProductPart: FC<BreadcrumbProductPartProps> = ({
<Link
key="product"
href={`/category/${categoryId}/subcategory/${subCategoryId}/product/${productId}`}
className="cursor-pointer">
className="cursor-pointer"
onClick={(e) => {
e.preventDefault();
if (user) {
dispatchUserEvent({
user_id: user.id,
event_type: 'click',
core_component: 'breadcrumb',
description: `Clicked on product in breadcrumb for product ${productFetch.data?.name}`,
metadata: {product_id: productId},
});
}
}}>
{productFetch.data.name}
</Link>
</>
Expand Down
18 changes: 17 additions & 1 deletion app/components/header/breadcrumb/SubCategoryPart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';
import {useGetSubCategoryQuery} from '@/app/lib/api/categories-slice';
import {dispatchUserEvent} from '@/app/lib/kafka/dispatch/user-events';
import {useUser} from '@clerk/nextjs';
import Link from 'next/link';
import {FC, useMemo} from 'react';

Expand All @@ -13,6 +15,8 @@ export const BreadcrumbSubCategortPart: FC<BreadcrumbSubCategortPartProps> = ({
subCategoryId,
}) => {
const subCategoryFetch = useGetSubCategoryQuery(subCategoryId);
// user data for recording events
const {user} = useUser();

// Method to get the subcategories part of the breadcrumb
const getSubCategoriesPart = useMemo(() => {
Expand All @@ -25,7 +29,19 @@ export const BreadcrumbSubCategortPart: FC<BreadcrumbSubCategortPartProps> = ({
<Link
key="subcategory"
href={`/category/${categoryId}/subcategory/${subCategoryId}`}
className="cursor-pointer">
className="cursor-pointer"
onClick={(e) => {
e.preventDefault();
if (user) {
dispatchUserEvent({
user_id: user.id,
event_type: 'click',
core_component: 'breadcrumb',
description: `Clicked on subcategory in breadcrumb for subcategory ${subCategoryFetch.data?.name}`,
metadata: {subcategory_id: subCategoryId},
});
}
}}>
{subCategoryFetch.data.name}
</Link>
</>
Expand Down