diff --git a/admin-spa/src/routes/Settings/Shipping.tsx b/admin-spa/src/routes/Settings/Shipping.tsx index 9cd7b3b..e008bda 100644 --- a/admin-spa/src/routes/Settings/Shipping.tsx +++ b/admin-spa/src/routes/Settings/Shipping.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { api } from '@/lib/api'; import { SettingsLayout } from './components/SettingsLayout'; @@ -53,6 +53,16 @@ export default function ShippingPage() { enabled: showAddMethod, }); + // Sync selectedZone with zones data when it changes + useEffect(() => { + if (selectedZone && zones.length > 0) { + const updatedZone = zones.find((z: any) => z.id === selectedZone.id); + if (updatedZone) { + setSelectedZone(updatedZone); + } + } + }, [zones]); + // Toggle shipping method mutation const toggleMutation = useMutation({ mutationFn: async ({ zoneId, instanceId, enabled }: { zoneId: number; instanceId: number; enabled: boolean }) => { @@ -334,37 +344,24 @@ export default function ShippingPage() { }}> {selectedZone.rates?.map((rate: any) => ( -
- -
- -
-
-
- - - {rate.enabled ? __('On') : __('Off')} - -
+ +
+ +
+
+
+ + + {rate.enabled ? __('On') : __('Off')} +
- - -
+
+
{methodSettings[rate.instance_id] ? (
@@ -422,36 +419,50 @@ export default function ShippingPage() {
)} -
- +
+
+ + +
) : ( @@ -512,38 +523,24 @@ export default function ShippingPage() { }}> {selectedZone.rates?.map((rate: any) => ( -
- -
- -
-
-
- - - {rate.enabled ? __('On') : __('Off')} - -
+ +
+ +
+
+
+ + + {rate.enabled ? __('On') : __('Off')} +
- - -
+
+
{methodSettings[rate.instance_id] ? (
@@ -592,36 +589,50 @@ export default function ShippingPage() {
)} -
- +
+
+ + +
) : (