redirect to single order
This commit is contained in:
@@ -13,6 +13,8 @@ import { useGetCartItems, useSaveAllMethod } from '@/app/[name]/(Dialogs)/cart/h
|
||||
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useGetShipmentMethod } from '../../hooks/useOrderData';
|
||||
import { useGetProducts } from '@/app/[name]/(Main)/hooks/useMenuData';
|
||||
import { isVariablePricing } from '@/app/[name]/(Main)/types/Types';
|
||||
import CartItemsList from '@/app/[name]/(Dialogs)/cart/components/CartItemsList';
|
||||
import { useCartStore } from '@/app/[name]/(Dialogs)/cart/store/Store';
|
||||
|
||||
@@ -33,8 +35,22 @@ export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: S
|
||||
const name = params.name as string;
|
||||
const { isSuccess } = useGetProfile();
|
||||
const { data: cartData } = useGetCartItems(isSuccess);
|
||||
const { data: productsResponse } = useGetProducts();
|
||||
const { data: shipmentMethod } = useGetShipmentMethod();
|
||||
|
||||
const hasVariablePricingItem = useMemo(() => {
|
||||
const cartItems = cartData?.data?.items;
|
||||
const products = productsResponse?.data;
|
||||
if (!cartItems?.length || !products?.length) return false;
|
||||
|
||||
return cartItems.some((item) => {
|
||||
const product = products.find((p) =>
|
||||
p.variants?.some((v) => String(v.id) === String(item.variantId))
|
||||
);
|
||||
return product != null && isVariablePricing(product);
|
||||
});
|
||||
}, [cartData?.data?.items, productsResponse?.data]);
|
||||
|
||||
const selectedDeliveryMethod = useMemo(() => {
|
||||
if (!shipmentMethod?.data || !deliveryType) return null;
|
||||
return shipmentMethod.data.find((item) => item.id === deliveryType);
|
||||
@@ -132,8 +148,8 @@ export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: S
|
||||
onSuccess: (data) => {
|
||||
clear();
|
||||
resetCart();
|
||||
if (data?.data?.paymentUrl) {
|
||||
window.location.href = data?.data?.paymentUrl;
|
||||
if (!hasVariablePricingItem && data?.data?.paymentUrl) {
|
||||
window.location.href = data.data.paymentUrl;
|
||||
toast('در حال ریدایرکت به صفحه پرداخت...', 'success');
|
||||
} else {
|
||||
window.location.href = `/${name}/order/track/${data?.data?.order?.id}`;
|
||||
@@ -193,7 +209,7 @@ export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: S
|
||||
<div className='text-sm mt-2 font-semibold'>{formatPrice(total)} تومان</div>
|
||||
</div>
|
||||
<Button pending={isCreateOrderPending || isSaveAllMethodPending} onClick={handleSubmit} className='px-10 w-fit dark:bg-white dark:text-black! dark:hover:bg-gray-100'>
|
||||
{t("ButtonSubmit")}
|
||||
{hasVariablePricingItem ? t("ButtonRegister") : t("ButtonSubmit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
"Title": "اقلام سفارش"
|
||||
},
|
||||
"ButtonSubmit": "پرداخت",
|
||||
"ButtonRegister": "ثبت",
|
||||
"PayableAmountLabel": "مبلغ قابل پرداخت"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user