From d419eb71933c55eccea36ac9cedef0a8fe11e85f Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 7 Nov 2025 09:07:29 +0700 Subject: move price in cart --- src-migrate/modules/cart/components/Item.tsx | 139 ++++++++++++++++----------- 1 file changed, 83 insertions(+), 56 deletions(-) (limited to 'src-migrate/modules/cart/components') diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 86d1dc43..a3aa2ac2 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -1,28 +1,28 @@ -import style from '../styles/item.module.css' +import style from '../styles/item.module.css'; import odooApi from '~/libs/odooApi'; import { useEffect, useState } from 'react'; -import { Skeleton, SkeletonProps, Tooltip } from '@chakra-ui/react' -import { InfoIcon } from 'lucide-react' -import Image from 'next/image' -import Link from 'next/link' +import { Skeleton, SkeletonProps, Tooltip } from '@chakra-ui/react'; +import { InfoIcon } from 'lucide-react'; +import Image from 'next/image'; +import Link from 'next/link'; -import { PROMO_CATEGORY } from '~/constants/promotion' -import formatCurrency from '~/libs/formatCurrency' -import { createSlug } from '~/libs/slug' -import { CartItem as CartItemProps } from '~/types/cart' +import { PROMO_CATEGORY } from '~/constants/promotion'; +import formatCurrency from '~/libs/formatCurrency'; +import { createSlug } from '~/libs/slug'; +import { CartItem as CartItemProps } from '~/types/cart'; -import CartItemAction from './ItemAction' -import CartItemPromo from './ItemPromo' -import CartItemSelect from './ItemSelect' +import CartItemAction from './ItemAction'; +import CartItemPromo from './ItemPromo'; +import CartItemSelect from './ItemSelect'; type Props = { - item: CartItemProps - editable?: boolean - selfPicking?: boolean - pilihSemuaCart?: boolean -} + item: CartItemProps; + editable?: boolean; + selfPicking?: boolean; + pilihSemuaCart?: boolean; +}; -const CartItem = ({ item, editable = true, selfPicking}: Props) => { +const CartItem = ({ item, editable = true, selfPicking }: Props) => { const [qtyPickUp, setQtyPickUp] = useState(0); useEffect(() => { const fetchData = async () => { @@ -36,10 +36,16 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => { }, [item]); return (
- {item.cart_type === 'promotion' && ( + {item.cart_type === 'promotion' && (
{item.promotion_type?.value && ( - +
Paket {PROMO_CATEGORY[item.promotion_type?.value].alias} @@ -79,27 +85,28 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
{item.cart_type === 'promotion' && (
- - Rp {formatCurrency((item.package_price || 0))} - Rp {formatCurrency(item.price.price)} + + Rp {formatCurrency(item.package_price || 0)} +
)} {item.cart_type === 'product' && (
+
+ {item.price.price_discount > 0 && + `Rp ${formatCurrency(item.price.price_discount)}`} + {item.price.price_discount === 0 && '-'} +
+ {item.price.discount_percentage > 0 && ( - Rp {formatCurrency((item.price.price || 0))} + Rp {formatCurrency(item.price.price || 0)} )} - -
- {item.price.price_discount > 0 && `Rp ${formatCurrency(item.price.price_discount)}`} - {item.price.price_discount === 0 && '-'} -
)} @@ -113,39 +120,58 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
-
- {item.products?.map((product) => )} - {item.free_products?.map((product) => )} +
+ {item.products?.map((product) => ( + + ))} + {item.free_products?.map((product) => ( + + ))}
- ) -} + ); +}; CartItem.Image = function CartItemImage({ item }: { item: CartItemProps }) { - const image = item?.image || item?.parent?.image - const imageProgram = item?.image_program ? item.image_program[0] : item?.parent?.image; + const image = item?.image || item?.parent?.image; + const imageProgram = item?.image_program + ? item.image_program[0] + : item?.parent?.image; - return ( + return ( <> {item.cart_type === 'promotion' && (
- {imageProgram && {item.name}} + {imageProgram && ( + {item.name} + )} {!imageProgram &&
No Image
}
)} {item.cart_type === 'product' && ( - {image && {item.name}} + {image && ( + {item.name} + )} {!image &&
No Image
} )} - ) -} + ); +}; CartItem.Name = function CartItemName({ item }: { item: CartItemProps }) { return ( @@ -156,25 +182,26 @@ CartItem.Name = function CartItemName({ item }: { item: CartItemProps }) { {item.cart_type === 'product' && ( {item.name} )} - ) -} + ); +}; -CartItem.Skeleton = function CartItemSkeleton(props: SkeletonProps & { count: number }) { +CartItem.Skeleton = function CartItemSkeleton( + props: SkeletonProps & { count: number } +) { return Array.from({ length: props.count }).map((_, index) => ( - - )) -} - -export default CartItem + + )); +}; + +export default CartItem; -- cgit v1.2.3