if selected delivery method then default set address

This commit is contained in:
hamid zarghami
2025-12-07 10:53:10 +03:30
parent a8fa442b3f
commit 88088c2ed5
@@ -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, {