File tree Expand file tree Collapse file tree 3 files changed +90
-5
lines changed
app/[locale]/(main)/(container)/cart Expand file tree Collapse file tree 3 files changed +90
-5
lines changed Original file line number Diff line number Diff line change 1+ import { Stack } from '@mui/material' ;
2+ import React , { FC , ReactNode } from 'react' ;
3+
4+ export interface CheckoutBoxProps {
5+ items : { key : ReactNode ; value : ReactNode } [ ] ;
6+ }
7+
8+ const CheckoutBox : FC < CheckoutBoxProps > = ( { items } ) => {
9+ return (
10+ < Stack spacing = { 1 } >
11+ { items . map ( ( item , index ) => {
12+ return (
13+ < Stack
14+ key = { index }
15+ justifyContent = "space-between"
16+ direction = "row"
17+ alignItems = "center"
18+ >
19+ { item . key }
20+ { item . value }
21+ </ Stack >
22+ ) ;
23+ } ) }
24+ </ Stack >
25+ ) ;
26+ } ;
27+
28+ export default CheckoutBox ;
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ import Image from 'next/image';
3030import Header from './components/Header' ;
3131import CartItemSkeleton from '@/components/CartItem/components/CartItemSkeleton' ;
3232import OutOfStock from '@/components/common/OutOfStock' ;
33+ import CheckoutBox , { CheckoutBoxProps } from './components/CheckoutBox' ;
34+ import PriceLabel from '@/components/common/PriceLabel' ;
3335
3436const Page = ( ) => {
3537 const t = useTranslations ( ) ;
@@ -135,6 +137,55 @@ const Page = () => {
135137 ) ;
136138 }
137139
140+ const checkoutBoxItems : CheckoutBoxProps [ 'items' ] = [
141+ {
142+ key : (
143+ < Typography variant = "body2" color = "gray" sx = { { fontWeight : 600 } } >
144+ قیمت کالاها ({ cart ?. contents ?. itemCount } )
145+ </ Typography >
146+ ) ,
147+ value : (
148+ < PriceLabel
149+ value = { cart . subtotal }
150+ TypographyProps = { {
151+ fontWeight : 600 ,
152+ color : 'gray' ,
153+ } }
154+ />
155+ ) ,
156+ } ,
157+ {
158+ key : (
159+ < Typography variant = "body2" sx = { { fontWeight : 600 } } >
160+ جمع سبد خرید
161+ </ Typography >
162+ ) ,
163+ value : (
164+ < PriceLabel
165+ value = { cart . total }
166+ TypographyProps = { {
167+ fontWeight : 600 ,
168+ } }
169+ />
170+ ) ,
171+ } ,
172+ {
173+ key : (
174+ < Typography color = "error" variant = "body2" sx = { { fontWeight : 600 } } >
175+ سود شما از خرید
176+ </ Typography >
177+ ) ,
178+ value : (
179+ < PriceLabel
180+ value = { cart . discountTotal }
181+ TypographyProps = { {
182+ fontWeight : 600 ,
183+ } }
184+ />
185+ ) ,
186+ } ,
187+ ] ;
188+
138189 return (
139190 < >
140191 < Grid container spacing = { 2 } >
@@ -200,7 +251,9 @@ const Page = () => {
200251 < Grid item lg = { 3 } md = { 6 } xs = { 12 } >
201252 < Stack spacing = { 2 } >
202253 < Card variant = "outlined" >
203- < CardContent > </ CardContent >
254+ < CardContent >
255+ < CheckoutBox items = { checkoutBoxItems } />
256+ </ CardContent >
204257 < CardActions >
205258 < Button
206259 fullWidth
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { extractNumbers, getMinOfRangePrice } from '@/utils/price';
66import { useTranslations } from 'next-intl' ;
77
88export interface PriceLabelProps {
9- value ?: string | null ;
9+ value ?: string | number | null ;
1010 TypographyProps ?: Partial < TypographyProps > ;
1111}
1212
@@ -19,11 +19,15 @@ const PriceLabel: FC<PriceLabelProps> = ({
1919 } ,
2020} ) => {
2121 const t = useTranslations ( ) ;
22+
23+ const _value =
24+ typeof value === 'string'
25+ ? extractNumbers ( getMinOfRangePrice ( value ) )
26+ : value ;
27+
2228 return (
2329 < Box display = "flex" alignItems = "center" >
24- < Typography { ...TypographyProps } >
25- { extractNumbers ( getMinOfRangePrice ( value ) ) ?. toLocaleString ( ) }
26- </ Typography >
30+ < Typography { ...TypographyProps } > { _value ?. toLocaleString ( ) } </ Typography >
2731 < PriceUnit title = { t ( 'units.price' ) } />
2832 </ Box >
2933 ) ;
You can’t perform that action at this time.
0 commit comments