From d67055cce9a9f437a875a0fa51733a56b45ae006 Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 9 Nov 2025 22:22:36 +0700 Subject: [PATCH] fix: Modal refresh + improved accordion UX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: ✅ Modal now shows newly added methods immediately ✅ Accordion chevron on right (standard pattern) ✅ Remove button moved to content area Changes: 1. Added useEffect to sync selectedZone with zones data - Modal now updates when methods are added/deleted 2. Restructured accordion: Before: [Truck Icon] Name/Price [Chevron] [Delete] After: [Truck Icon] Name/Price [Chevron →] 3. Button layout in expanded content: [Remove] | [Cancel] [Save] Benefits: ✅ Clearer visual hierarchy ✅ Remove action grouped with other actions ✅ Standard accordion pattern (chevron on right) ✅ Better mobile UX (no accidental deletes) Next: Research shipping addon integration patterns --- admin-spa/src/routes/Settings/Shipping.tsx | 227 +++++++++++---------- 1 file changed, 119 insertions(+), 108 deletions(-) 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() {
)} -
- +
+
+ + +
) : (