From 1170c52c8dc532f7447d0f10093bd3531767f57e Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 19 Feb 2024 13:16:08 +0700 Subject: Add link to product on cart item --- src-migrate/modules/cart/components/Item.tsx | 56 +++++++++++++++++++---- src-migrate/modules/cart/components/ItemPromo.tsx | 12 +++-- 2 files changed, 54 insertions(+), 14 deletions(-) (limited to 'src-migrate') 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 (
{item.cart_type === 'promotion' && ( @@ -47,13 +46,12 @@ const CartItem = ({ item, editable = true }: Props) => {
{editable && }
-
- {image && {item.name}} - {!image &&
No Image
} -
+ +
-
{item.name}
+ +
{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' && ( +
+ {image && {item.name}} + {!image &&
No Image
} +
+ )} + + {item.cart_type === 'product' && ( + + {image && {item.name}} + {!image &&
No Image
} + + )} + + ) +} + +CartItem.Name = function CartItemName({ item }: { item: CartItemProps }) { + return ( + <> + {item.cart_type === 'promotion' && ( +
{item.name}
+ )} + + {item.cart_type === 'product' && ( + + {item.name} + + )} + + ) +} + CartItem.Skeleton = function CartItemSkeleton(props: SkeletonProps & { count: number }) { return Array.from({ length: props.count }).map((_, index) => ( { return (
-
+ {product?.image && {product.name}} -
+
-
{product.display_name}
+ + {product.display_name} + +
{product.code}
-- cgit v1.2.3