From 88088c2ed5c7041631e8ea318c5239b0e50dbcbf Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 7 Dec 2025 10:53:10 +0330 Subject: [PATCH] if selected delivery method then default set address --- .../order/checkout/[id]/components/AddressSection.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/AddressSection.tsx b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/AddressSection.tsx index 247b972..45d0a72 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/AddressSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/AddressSection.tsx @@ -20,7 +20,7 @@ const formatAddress = (address: Address) => { export const AddressSection = () => { const { mutate: setAddressCart } = useSetAddressCart(); - const { setIsSelectedAddress, selectedAddressId, setSelectedAddressId } = useCheckoutStore(); + const { setIsSelectedAddress, selectedAddressId, setSelectedAddressId, isSelectedShipment } = useCheckoutStore(); const params = useParams<{ name: string; id: string }>(); const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); const { data: addressesResponse, isLoading } = useGetAddresses(); @@ -29,8 +29,9 @@ export const AddressSection = () => { const { state: modalVisible, toggle: toggleModal, set: setModalVisible } = useToggle(false); // اگر آدرس پیش‌فرض وجود داشت، آن را تنظیم کن، در غیر این صورت آدرس اول غیر پیش‌فرض + // در صورتی که روش تحویل انتخاب شده بود آدرس رو ست کنه useEffect(() => { - if (!isLoading && addresses.length > 0 && !selectedAddressId) { + if (!isLoading && addresses.length > 0 && !selectedAddressId && isSelectedShipment) { const defaultAddress = addresses.find(addr => addr.isDefault); const addressToSet = defaultAddress || addresses.filter(addr => !addr.isDefault)[0]; if (addressToSet) { @@ -42,7 +43,7 @@ export const AddressSection = () => { }); } } - }, [isLoading, addresses, setAddressCart, setIsSelectedAddress, selectedAddressId, setSelectedAddressId]); + }, [isLoading, addresses, setAddressCart, setIsSelectedAddress, selectedAddressId, setSelectedAddressId, isSelectedShipment]); const handleSelectAddress = (addressId: string) => { setAddressCart(addressId, {