Skip to content

Commit 3228a6a

Browse files
committed
feat: add link of product page to the cart item component
1 parent 3c8124c commit 3228a6a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/app/[locale]/(main)/(container)/cart/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CartItemController from '@/components/CartItemController/CartItemControll
55
import { getFragmentData } from '@/graphql/types';
66
import {
77
CartItemContentFragmentDoc,
8+
ProductContentSliceFragmentDoc,
89
ProductVariationContentSliceFragmentDoc,
910
StockStatusEnum,
1011
} from '@/graphql/types/graphql';
@@ -153,13 +154,22 @@ const Page = () => {
153154
ProductVariationContentSliceFragmentDoc,
154155
_item.variation?.node,
155156
)!;
157+
158+
const product = getFragmentData(
159+
ProductContentSliceFragmentDoc,
160+
_item.product?.node,
161+
);
162+
156163
const isOutOfStock =
157164
variant.stockStatus === StockStatusEnum.OutOfStock;
158165

159166
return (
160167
<Grid item xs={12} key={_item?.key}>
161168
<Stack spacing={2}>
162-
<CartItem value={variant} />
169+
<CartItem
170+
value={variant}
171+
href={`/products/${product?.databaseId}`}
172+
/>
163173
<Stack direction="row" spacing={1}>
164174
<Box width={200}>
165175
<CartItemController

src/components/CartItem/CartItem.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
import { Box, Stack, Typography } from '@mui/material';
1+
import { Box, Link, Stack, Typography } from '@mui/material';
22
import React, { FC } from 'react';
33
import Attributes from './components/Attributes';
44
import Image from '../common/Image';
55
import { ProductVariationContentSliceFragment } from '@/graphql/types/graphql';
66

77
export interface CartItemProps {
88
value: ProductVariationContentSliceFragment;
9+
href?: string;
910
}
10-
const CartItem: FC<CartItemProps> = ({ value }) => {
11+
const CartItem: FC<CartItemProps> = ({ value, href = '#' }) => {
1112
return (
1213
<Stack gap={2} direction="row">
13-
<Image width={80} height={80} src={value?.image?.sourceUrl} alt="Image" />
14+
<Link href={href}>
15+
<Image
16+
width={80}
17+
height={80}
18+
src={value?.image?.sourceUrl}
19+
alt="Image"
20+
/>
21+
</Link>
1422
<Box flexGrow={1}>
1523
<Stack gap={2}>
16-
<Typography variant="body1" sx={{ fontWeight: 600 }}>
17-
{value?.name}
18-
</Typography>
24+
<Link href={href}>
25+
<Typography variant="body1" sx={{ fontWeight: 600 }}>
26+
{value?.name}
27+
</Typography>
28+
</Link>
29+
1930
<Attributes
2031
size={value?.attributes?.nodes?.[0]?.value?.toUpperCase()}
2132
/>

0 commit comments

Comments
 (0)