Skip to content

Commit

Permalink
feat: add link of product page to the cart item component
Browse files Browse the repository at this point in the history
  • Loading branch information
pooriaset committed May 24, 2024
1 parent 3c8124c commit 3228a6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/app/[locale]/(main)/(container)/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CartItemController from '@/components/CartItemController/CartItemControll
import { getFragmentData } from '@/graphql/types';
import {
CartItemContentFragmentDoc,
ProductContentSliceFragmentDoc,
ProductVariationContentSliceFragmentDoc,
StockStatusEnum,
} from '@/graphql/types/graphql';
Expand Down Expand Up @@ -153,13 +154,22 @@ const Page = () => {
ProductVariationContentSliceFragmentDoc,
_item.variation?.node,
)!;

const product = getFragmentData(
ProductContentSliceFragmentDoc,
_item.product?.node,
);

const isOutOfStock =
variant.stockStatus === StockStatusEnum.OutOfStock;

return (
<Grid item xs={12} key={_item?.key}>
<Stack spacing={2}>
<CartItem value={variant} />
<CartItem
value={variant}
href={`/products/${product?.databaseId}`}
/>
<Stack direction="row" spacing={1}>
<Box width={200}>
<CartItemController
Expand Down
23 changes: 17 additions & 6 deletions src/components/CartItem/CartItem.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { Box, Stack, Typography } from '@mui/material';
import { Box, Link, Stack, Typography } from '@mui/material';
import React, { FC } from 'react';
import Attributes from './components/Attributes';
import Image from '../common/Image';
import { ProductVariationContentSliceFragment } from '@/graphql/types/graphql';

export interface CartItemProps {
value: ProductVariationContentSliceFragment;
href?: string;
}
const CartItem: FC<CartItemProps> = ({ value }) => {
const CartItem: FC<CartItemProps> = ({ value, href = '#' }) => {
return (
<Stack gap={2} direction="row">
<Image width={80} height={80} src={value?.image?.sourceUrl} alt="Image" />
<Link href={href}>
<Image
width={80}
height={80}
src={value?.image?.sourceUrl}
alt="Image"
/>
</Link>
<Box flexGrow={1}>
<Stack gap={2}>
<Typography variant="body1" sx={{ fontWeight: 600 }}>
{value?.name}
</Typography>
<Link href={href}>
<Typography variant="body1" sx={{ fontWeight: 600 }}>
{value?.name}
</Typography>
</Link>

<Attributes
size={value?.attributes?.nodes?.[0]?.value?.toUpperCase()}
/>
Expand Down

0 comments on commit 3228a6a

Please sign in to comment.