Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: clear tax ID fields on billing country change (#45182)

Ignacio Dobronich7739b7a540f0
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerDataForm.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerDataForm.tsx
index ac9341ef29b..a4a09a52903 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerDataForm.tsx
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/BillingCustomerDataForm.tsx
@@ -5,7 +5,7 @@ import type {
StripeAddressElementOptions,
} from '@stripe/stripe-js'
import { Check, ChevronsUpDown, Info, X } from 'lucide-react'
-import { useId, useMemo, useState } from 'react'
+import { useEffect, useId, useMemo, useRef, useState } from 'react'
import { UseFormReturn } from 'react-hook-form'
import {
Button,
@@ -87,6 +87,23 @@ export const BillingCustomerDataForm = ({
)
}, [addressCountry])
+ // Clear tax ID fields when the billing country changes so a stale tax ID
+ // from the previous country doesn't persist under the new one.
+ const prevCountryRef = useRef(addressCountry)
+ useEffect(() => {
+ if (!addressCountry) return
+
+ const isCountryChange =
+ prevCountryRef.current !== undefined && prevCountryRef.current !== addressCountry
+ prevCountryRef.current = addressCountry
+
+ if (isCountryChange) {
+ form.setValue('tax_id_type', '', { shouldDirty: true })
+ form.setValue('tax_id_value', '', { shouldDirty: true })
+ form.setValue('tax_id_name', '', { shouldDirty: true })
+ }
+ }, [addressCountry, form])
+
return (
<div className={cn('flex flex-col space-y-4', className)}>
<div className={cn('relative', disabled && 'opacity-50')}>