Skip to content

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

fix(billing): trim Tax ID inputs to trigger required validation (#47311)

Kanishk Dudeja1f03c0dc0e6c
diff --git a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx
index a8b9da11623..cd4037b16a5 100644
--- a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx
+++ b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/NewPaymentMethodElement.tsx
@@ -51,7 +51,7 @@ import { getURL } from '@/lib/helpers'
export const BillingCustomerDataSchema = z.object({
tax_id_type: z.string(),
- tax_id_value: z.string().min(2, {
+ tax_id_value: z.string().trim().min(2, {
message: 'Tax ID needs to be set.',
}),
tax_id_name: z.string(),
@@ -140,7 +140,8 @@ export const NewPaymentMethodElement = forwardRef(
form.setValue('tax_id_name', name)
}
- const { tax_id_name, tax_id_value } = form.watch()
+ const { tax_id_name, tax_id_value: rawTaxIdValue } = form.watch()
+ const taxIdValue = rawTaxIdValue?.trim() ?? ''
const selectedTaxId = TAX_IDS.find((option) => option.name === tax_id_name)
const [purchasingAsBusiness, setPurchasingAsBusiness] = useState(currentTaxId != null)
@@ -149,16 +150,16 @@ export const NewPaymentMethodElement = forwardRef(
>(undefined)
useEffect(() => {
if (!onTaxIdChange) return
- if (purchasingAsBusiness && selectedTaxId && tax_id_value) {
+ if (purchasingAsBusiness && selectedTaxId && taxIdValue) {
onTaxIdChange({
country: getEffectiveTaxCountry(selectedTaxId),
type: selectedTaxId.type,
- value: tax_id_value,
+ value: taxIdValue,
})
} else {
onTaxIdChange(null)
}
- }, [purchasingAsBusiness, selectedTaxId, tax_id_value, onTaxIdChange])
+ }, [purchasingAsBusiness, selectedTaxId, taxIdValue, onTaxIdChange])
const addressCountry = stripeAddress?.address.country
const availableTaxIds = useMemo(() => {
@@ -212,7 +213,7 @@ export const NewPaymentMethodElement = forwardRef(
? {
country: getEffectiveTaxCountry(selectedTaxId),
type: selectedTaxId.type,
- value: form.getValues('tax_id_value'),
+ value: form.getValues('tax_id_value').trim(),
}
: null
}
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts
index 17ea604c872..d552eff33b3 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/BillingCustomerData/useBillingCustomerDataForm.ts
@@ -166,6 +166,7 @@ export function useBillingCustomerDataForm({
const taxIdValues = form.getValues()
const selectedTaxId = TAX_IDS.find((option) => option.name === taxIdValues.tax_id_name)
+ const taxIdValue = taxIdValues.tax_id_value?.trim() ?? ''
const payload = {
address: {
@@ -178,11 +179,11 @@ export function useBillingCustomerDataForm({
},
billing_name: address.name.trim(),
tax_id:
- selectedTaxId && taxIdValues.tax_id_type?.length && taxIdValues.tax_id_value?.length
+ selectedTaxId && taxIdValues.tax_id_type?.length && taxIdValue.length
? {
type: taxIdValues.tax_id_type,
value: sanitizeTaxIdValue({
- value: taxIdValues.tax_id_value,
+ value: taxIdValue,
name: taxIdValues.tax_id_name,
}),
country: getEffectiveTaxCountry(selectedTaxId),