fix summary section
This commit is contained in:
@@ -9,6 +9,9 @@ import { toast } from '@/components/Toast';
|
||||
import { useCreateOrder } from '../../hooks/useOrderData';
|
||||
import { extractErrorMessage } from '@/lib/func';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useGetCartItems } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData';
|
||||
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
type SummarySectionProps = {
|
||||
cartModal: boolean;
|
||||
@@ -22,6 +25,19 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
|
||||
const { mutate: createOrder } = useCreateOrder();
|
||||
const params = useParams();
|
||||
const name = params.name as string;
|
||||
const { isSuccess } = useGetProfile();
|
||||
const { data: cartData } = useGetCartItems(isSuccess);
|
||||
|
||||
const formatPrice = useCallback(
|
||||
(value: number) => value.toLocaleString('fa-IR'),
|
||||
[]
|
||||
);
|
||||
|
||||
const subTotal = cartData?.data?.subTotal ?? 0;
|
||||
const deliveryFee = cartData?.data?.deliveryFee ?? 0;
|
||||
const totalDiscount = cartData?.data?.totalDiscount ?? 0;
|
||||
const tax = cartData?.data?.tax ?? 0;
|
||||
const total = cartData?.data?.total ?? 0;
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!isSelectedAddress) {
|
||||
@@ -69,13 +85,15 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
|
||||
</div>
|
||||
<div className='mt-6 text-sm2 grid grid-cols-2 gap-4'>
|
||||
<span className=''>{t("SectionSummary.SumOfItemsLabel")}</span>
|
||||
<span className='font-medium place-self-end '>100,000 T</span>
|
||||
<span className='font-medium place-self-end '>{formatPrice(subTotal)} T</span>
|
||||
<span className=''>{t("SectionSummary.DeliveryLabel")}</span>
|
||||
<span className='font-medium place-self-end '>20,000 T</span>
|
||||
<span className='font-medium place-self-end '>{formatPrice(deliveryFee)} T</span>
|
||||
<span className='text-emerald-600'>{t("SectionSummary.DiscountLabel")}</span>
|
||||
<span className='font-medium place-self-end text-emerald-600'>10,000 T</span>
|
||||
<span className='font-medium place-self-end text-emerald-600'>{formatPrice(totalDiscount)} T</span>
|
||||
<span className=''>{t("SectionSummary.TaxLabel")}</span>
|
||||
<span className='font-medium place-self-end '>{formatPrice(tax)} T</span>
|
||||
<span className='font-medium '>{t("SectionSummary.TotalLabel")}</span>
|
||||
<span className='font-bold place-self-end'>110,000 T</span>
|
||||
<span className='font-bold place-self-end'>{formatPrice(total)} T</span>
|
||||
</div>
|
||||
<Button onClick={handleSubmit} className='mt-6'>
|
||||
{t("ButtonSubmit")}
|
||||
|
||||
@@ -93,6 +93,8 @@
|
||||
"DeliveryValue": "{shipping} T",
|
||||
"DiscountLabel": "تخفیف:",
|
||||
"DiscountValue": "{discount} T",
|
||||
"TaxLabel": "مالیات:",
|
||||
"TaxValue": "{tax} T",
|
||||
"TotalLabel": "جمع کل:",
|
||||
"TotalValue": "{total} T",
|
||||
"ButtonViewCart": "مشاهده اقلام"
|
||||
|
||||
Reference in New Issue
Block a user