From 0012d827bb0da8d45d71a425c75a5441fd33265b Mon Sep 17 00:00:00 2001 From: dwindown Date: Mon, 10 Nov 2025 13:31:47 +0700 Subject: [PATCH] fix(tax): All 4 issues resolved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Fixes: 1. ✅ Suggested rates now inside Tax Rates card as help notice - Shows as blue notice box - Only shows rates not yet added - Auto-hides when all suggested rates added 2. ✅ Add Rate button now works - Fixed mutation to properly invalidate queries - Shows success toast - Updates list immediately 3. ✅ Add Tax Rate dialog no longer blank - Replaced shadcn Select with native select - Form now submits properly - All fields visible 4. ✅ Tax toggle now functioning - Changed onChange to onCheckedChange - Added required id prop - Properly typed checked parameter ## Additional: - Added api.put() method to api.ts - Improved UX with suggested rates as contextual help --- admin-spa/src/lib/api.ts | 8 +++ admin-spa/src/routes/Settings/Tax.tsx | 96 ++++++++++++--------------- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/admin-spa/src/lib/api.ts b/admin-spa/src/lib/api.ts index 1c54b59..785f50c 100644 --- a/admin-spa/src/lib/api.ts +++ b/admin-spa/src/lib/api.ts @@ -59,6 +59,14 @@ export const api = { }); }, + async put(path: string, body?: any) { + return api.wpFetch(path, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: body != null ? JSON.stringify(body) : undefined, + }); + }, + async del(path: string) { return api.wpFetch(path, { method: 'DELETE' }); }, diff --git a/admin-spa/src/routes/Settings/Tax.tsx b/admin-spa/src/routes/Settings/Tax.tsx index f6b1a21..fc1e8e8 100644 --- a/admin-spa/src/routes/Settings/Tax.tsx +++ b/admin-spa/src/routes/Settings/Tax.tsx @@ -175,56 +175,15 @@ export default function TaxSettings() { description={__('Enable or disable tax calculation for your store')} > toggleMutation.mutate(checked)} + onCheckedChange={(checked: boolean) => toggleMutation.mutate(checked)} disabled={toggleMutation.isPending} /> - {/* Suggested Tax Rates (when enabled) */} - {settings?.calc_taxes === 'yes' && suggested?.suggested && suggested.suggested.length > 0 && ( - -
- {suggested.suggested.map((rate: any) => { - const added = isRateAdded(rate.code); - return ( -
-
-
-

{rate.country}

- {added && ( - - - {__('Added')} - - )} -
-

- {rate.rate}% • {rate.name} -

-
- {!added && ( - - )} -
- ); - })} -
-
- )} - {/* Tax Rates */} {settings?.calc_taxes === 'yes' && ( } > + {/* Suggested Rates Notice */} + {suggested?.suggested && suggested.suggested.length > 0 && suggested.suggested.some((r: any) => !isRateAdded(r.code)) && ( +
+
+
+

+ {__('Suggested tax rates based on your selling locations')} +

+
+ {suggested.suggested.filter((r: any) => !isRateAdded(r.code)).map((rate: any) => ( +
+ + {rate.country}: {rate.rate}% ({rate.name}) + + +
+ ))} +
+
+
+
+ )} + + {/* Tax Rates List */} {allRates.length === 0 ? (

{__('No tax rates configured yet')}

@@ -441,16 +432,15 @@ export default function TaxSettings() {
- +