diff options
Diffstat (limited to 'src-migrate/modules')
| -rw-r--r-- | src-migrate/modules/cart/components/Item.tsx | 56 | ||||
| -rw-r--r-- | src-migrate/modules/cart/components/ItemPromo.tsx | 12 |
2 files changed, 54 insertions, 14 deletions
diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 48e568e0..7a4c22cc 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -1,17 +1,18 @@ import style from '../styles/item.module.css' -import Image from 'next/image' -import React from 'react' import { Skeleton, SkeletonProps, Tooltip } from '@chakra-ui/react' import { InfoIcon } from 'lucide-react' +import Image from 'next/image' import { PROMO_CATEGORY } from '~/constants/promotion' import formatCurrency from '~/libs/formatCurrency' import { CartItem as CartItemProps } from '~/types/cart' -import CartItemPromo from './ItemPromo' +import Link from 'next/link' +import { createSlug } from '~/libs/slug' import CartItemAction from './ItemAction' +import CartItemPromo from './ItemPromo' import CartItemSelect from './ItemSelect' type Props = { @@ -20,8 +21,6 @@ type Props = { } const CartItem = ({ item, editable = true }: Props) => { - const image = item?.image || item?.parent?.image - return ( <div className={style.wrapper}> {item.cart_type === 'promotion' && ( @@ -47,13 +46,12 @@ const CartItem = ({ item, editable = true }: Props) => { <div className={style.mainProdWrapper}> {editable && <CartItemSelect item={item} />} <div className='w-4' /> - <div className={style.image}> - {image && <Image src={image} alt={item.name} width={128} height={128} />} - {!image && <div className={style.noImage}>No Image</div>} - </div> + + <CartItem.Image item={item} /> <div className={style.details}> - <div className={style.name}>{item.name}</div> + <CartItem.Name item={item} /> + <div className='mt-2 flex justify-between w-full'> <div className='flex flex-col gap-y-1'> {item.cart_type === 'promotion' && ( @@ -97,6 +95,44 @@ const CartItem = ({ item, editable = true }: Props) => { ) } +CartItem.Image = function CartItemImage({ item }: { item: CartItemProps }) { + const image = item?.image || item?.parent?.image + + return ( + <> + {item.cart_type === 'promotion' && ( + <div className={style.image}> + {image && <Image src={image} alt={item.name} width={128} height={128} />} + {!image && <div className={style.noImage}>No Image</div>} + </div> + )} + + {item.cart_type === 'product' && ( + <Link href={createSlug('/shop/product/', item.name, item.id.toString())} className={style.image}> + {image && <Image src={image} alt={item.name} width={128} height={128} />} + {!image && <div className={style.noImage}>No Image</div>} + </Link> + )} + </> + ) +} + +CartItem.Name = function CartItemName({ item }: { item: CartItemProps }) { + return ( + <> + {item.cart_type === 'promotion' && ( + <div className={style.name}>{item.name}</div> + )} + + {item.cart_type === 'product' && ( + <Link href={createSlug('/shop/product/', item.name, item.id.toString())} className={style.name}> + {item.name} + </Link> + )} + </> + ) +} + CartItem.Skeleton = function CartItemSkeleton(props: SkeletonProps & { count: number }) { return Array.from({ length: props.count }).map((_, index) => ( <Skeleton key={index} diff --git a/src-migrate/modules/cart/components/ItemPromo.tsx b/src-migrate/modules/cart/components/ItemPromo.tsx index bc507578..d355c82a 100644 --- a/src-migrate/modules/cart/components/ItemPromo.tsx +++ b/src-migrate/modules/cart/components/ItemPromo.tsx @@ -1,7 +1,8 @@ import style from '../styles/item-promo.module.css' import Image from 'next/image' -import React from 'react' +import Link from 'next/link' +import { createSlug } from '~/libs/slug' import { CartProduct } from '~/types/cart' @@ -12,12 +13,15 @@ type Props = { const CartItemPromo = ({ product }: Props) => { return ( <div key={product.id} className={style.wrapper}> - <div className={style.imageWrapper}> + <Link href={createSlug('/shop/product/', product.name, product.id.toString())} className={style.imageWrapper}> {product?.image && <Image src={product.image} alt={product.name} width={128} height={128} className={style.image} />} - </div> + </Link> <div className={style.details}> - <div className={style.name}>{product.display_name}</div> + <Link href={createSlug('/shop/product/', product.name, product.id.toString())} className={style.name}> + {product.display_name} + </Link> + <div className='flex w-full'> <div className="flex flex-col"> <div className={style.code}>{product.code}</div> |
