The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: use new tax id endpoints (#27246)
Kevin Grünebergf54110719627
diff --git a/apps/studio/components/interfaces/BranchManagement/BranchStatusBadge.tsx b/apps/studio/components/interfaces/BranchManagement/BranchStatusBadge.tsxindex f094cc0e65f..b58cc28e327 100644--- a/apps/studio/components/interfaces/BranchManagement/BranchStatusBadge.tsx+++ b/apps/studio/components/interfaces/BranchManagement/BranchStatusBadge.tsx@@ -43,6 +43,9 @@ const STATUS_TO_LABEL: Record<Status, string> = {MIGRATIONS_PASSED: 'Migrations applied successfully',FUNCTIONS_DEPLOYED: 'Functions deployed',FUNCTIONS_FAILED: 'Functions failed to deploy',+ PAUSE_FAILED: 'Pause failed',+ RESTORE_FAILED: 'Restore failed',+ RESTARTING: 'Restarting',}const BranchStatusBadge = ({ status }: BranchStatusBadgeProps) => {diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.ts b/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.tsindex 24fccf80fb8..08e48d3aaed 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.ts+++ b/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.constants.ts@@ -5,7 +5,7 @@// https://stripe.com/docs/api/customer_tax_ids/createexport interface TaxId {name: string- code: string+ type: stringcountry: stringplaceholder: stringvatPrefix?: string@@ -14,535 +14,535 @@ export interface TaxId {export const TAX_IDS: TaxId[] = [{name: 'AE TRN',- code: 'ae_trn',+ type: 'ae_trn',country: 'United Arab Emirates',placeholder: '123456789012345',},{name: 'AT VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Austria',placeholder: 'ATU12345678',vatPrefix: 'ATU',},{name: 'AD NRT',- code: 'ad_nrt',+ type: 'ad_nrt',country: 'Andorra',placeholder: 'A-123456-Z',},{name: 'AR CUIT',- code: 'ar_cuit',+ type: 'ar_cuit',country: 'Argentina',placeholder: '12-3456789-01',},{name: 'AU ABN',- code: 'au_abn',+ type: 'au_abn',country: 'Australia',placeholder: '12345678912',},{name: 'AU ARN',- code: 'au_arn',+ type: 'au_arn',country: 'Australia',placeholder: '123456789123',},{name: 'BE VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Belgium',placeholder: 'BE0123456789',vatPrefix: 'BE',},{name: 'BO TIN',- code: 'bo_tin',+ type: 'bo_tin',country: 'Bolivia',placeholder: '123456789',},{name: 'BG VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Bulgaria',placeholder: 'BG0123456789',vatPrefix: 'BG',},{name: 'BR CNPJ',- code: 'br_cnpj',+ type: 'br_cnpj',country: 'Brazil',placeholder: '01.234.456/5432-10',},{name: 'BR CPF',- code: 'br_cpf',+ type: 'br_cpf',country: 'Brazil',placeholder: '123.456.789-87',},{name: 'CA BN',- code: 'ca_bn',+ type: 'ca_bn',country: 'Canada',placeholder: '123456789',},{name: 'CA GST/HST',- code: 'ca_gst_hst',+ type: 'ca_gst_hst',country: 'Canada',placeholder: '123456789RT0002',},{name: 'CA PST-BC',- code: 'ca_pst_bc',+ type: 'ca_pst_bc',country: 'Canada',placeholder: 'PST-1234-5678',},{name: 'CA PST-MB',- code: 'ca_pst_mb',+ type: 'ca_pst_mb',country: 'Canada',placeholder: '123456-7',},{name: 'CA PST-SK',- code: 'ca_pst_mb',+ type: 'ca_pst_mb',country: 'Canada',placeholder: '1234567',},{name: 'CA QST',- code: 'ca_qst',+ type: 'ca_qst',country: 'Canada',placeholder: '1234567890TQ1234',},{name: 'CH VAT',- code: 'ch_vat',+ type: 'ch_vat',country: 'Switzerland',placeholder: 'CHE-123.456.789 MWST',vatPrefix: 'CHE',},{name: 'CL TIN',- code: 'cl_tin',+ type: 'cl_tin',country: 'Chile',placeholder: '12.345.678-K',},{name: 'CN TIN',- code: 'cn_tin',+ type: 'cn_tin',country: 'China',placeholder: '123456789012345678',},{name: 'CO NIT',- code: 'co_nit',+ type: 'co_nit',country: 'Colombia',placeholder: '123.456.789-0',},{name: 'CR TIN',- code: 'cr_tin',+ type: 'cr_tin',country: 'Costa Rica',placeholder: '1-234-567890',},{name: 'CY VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Cyprus',placeholder: 'CY12345678Z',vatPrefix: 'CY',},{name: 'CZ VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Czech Republic',placeholder: 'CZ1234567890',vatPrefix: 'CZ',},{name: 'DE VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Germany',placeholder: 'DE123456789',vatPrefix: 'DE',},{name: 'DK VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Denmark',placeholder: 'DK12345678',vatPrefix: 'DK',},{name: 'DO RCN',- code: 'do_rcn',+ type: 'do_rcn',country: 'Dominican Republic',placeholder: '123-4567890-1',},{name: 'EE VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Estonia',placeholder: 'EE123456789',vatPrefix: 'EE',},{name: 'ES CIF',- code: 'es_cif',+ type: 'es_cif',country: 'Spain',placeholder: 'A12345678',},{name: 'ES VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Spain',placeholder: 'ESX1234567Z',vatPrefix: 'ES',},{name: 'FI VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Finland',placeholder: 'FI12345678',vatPrefix: 'FI',},{name: 'FR VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'France',placeholder: 'FRAB123456789',vatPrefix: 'FR',},{name: 'GB VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'United Kingdom',placeholder: 'GB123456789',vatPrefix: 'GB',},{name: 'GE VAT',- code: 'ge_vat',+ type: 'ge_vat',country: 'Georgia',placeholder: '123456789',},{name: 'EL VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Greece',placeholder: 'EL123456789',vatPrefix: 'EL',},{name: 'HK BR',- code: 'hk_br',+ type: 'hk_br',country: 'Hong Kong SAR China',placeholder: '12345678',},{name: 'HR VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Croatia',placeholder: 'HR12345678912',vatPrefix: 'HR',},{name: 'HU VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Hungary',placeholder: 'HU12345678912',vatPrefix: 'HU',},{name: 'ID NPWP',- code: 'id_npwp',+ type: 'id_npwp',country: 'Indonesia',placeholder: '12.345.678.9-012.345',},{name: 'IE VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Ireland',placeholder: 'IE1234567AB',vatPrefix: 'IE',},{name: 'IL VAT',- code: 'il_vat',+ type: 'il_vat',country: 'Israel',placeholder: '000012345',},{name: 'IN GST',- code: 'in_gst',+ type: 'in_gst',country: 'India',placeholder: '12ABCDE3456FGZH',},{name: 'IS VAT',- code: 'is_vat',+ type: 'is_vat',country: 'Iceland',placeholder: '123456',},{name: 'IT VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Italy',placeholder: 'IT12345678912',vatPrefix: 'IT',},{name: 'JP CN',- code: 'jp_cn',+ type: 'jp_cn',country: 'Japan',placeholder: '1234567891234',},{name: 'KE PIN',- code: 'ke_pin',+ type: 'ke_pin',country: 'Kenya',placeholder: 'P000111111A',},{name: 'JP RN',- code: 'jp_rn',+ type: 'jp_rn',country: 'Japan',placeholder: '12345',},{name: 'KR BRN',- code: 'kr_brn',+ type: 'kr_brn',country: 'Korea',placeholder: '123-45-67890',},{name: 'LI UID',- code: 'li_uid',+ type: 'li_uid',country: 'Liechtenstein',placeholder: 'CHE123456789',},{name: 'LT VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Lithuania',placeholder: 'LT123456789123',vatPrefix: 'LT',},{name: 'LU VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Luxembourg',placeholder: 'LU12345678',vatPrefix: 'LU',},{name: 'LV VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Latvia',placeholder: 'LV12345678912',vatPrefix: 'LV',},{name: 'MT VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Malta',placeholder: 'MT12345678',vatPrefix: 'MT',},{name: 'MX RFC',- code: 'mx_rfc',+ type: 'mx_rfc',country: 'Mexico',placeholder: 'ABC010203AB9',},{name: 'MY FRP',- code: 'my_frp',+ type: 'my_frp',country: 'Malaysia',placeholder: '12345678',},{name: 'MY ITN',- code: 'my_itn',+ type: 'my_itn',country: 'Malaysia',placeholder: 'C 1234567890',},{name: 'MY SST',- code: 'my_sst',+ type: 'my_sst',country: 'Malaysia',placeholder: 'A12-3456-78912345',},{name: 'NL VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Netherlands',placeholder: 'NL123456789B12',vatPrefix: 'NL',},{name: 'NO VAT',- code: 'no_vat',+ type: 'no_vat',country: 'Norway',placeholder: '123456789MVA',},{name: 'PE RUC',- code: 'pe_ruc',+ type: 'pe_ruc',country: 'Peru',placeholder: '12345678901',},{name: 'PH TIN',- code: 'ph_tin',+ type: 'ph_tin',country: 'Philippines',placeholder: '123456789012',},{name: 'NZ GST',- code: 'nz_gst',+ type: 'nz_gst',country: 'New Zealand',placeholder: '123456789',},{name: 'PL VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Poland',placeholder: 'PL1234567890',vatPrefix: 'PL',},{name: 'PT VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Portugal',placeholder: 'PT123456789',vatPrefix: 'PT',},{name: 'RO VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Romania',placeholder: 'RO1234567891',vatPrefix: 'RO',},{name: 'RU INN',- code: 'ru_inn',+ type: 'ru_inn',country: 'Russia',placeholder: '1234567891',},{name: 'RU KPP',- code: 'ru_kpp',+ type: 'ru_kpp',country: 'Russia',placeholder: '123456789',},{name: 'SA VAT',- code: 'sa_vat',+ type: 'sa_vat',country: 'Saudi Arabia',placeholder: '123456789012345',},{name: 'RS PIB',- code: 'rs_pib',+ type: 'rs_pib',country: 'Serbia',placeholder: '123456789',},{name: 'SE VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Sweden',placeholder: 'SE123456789123',vatPrefix: 'SE',},{name: 'SG GST',- code: 'sg_gst',+ type: 'sg_gst',country: 'Singapore',placeholder: 'M12345678X',},{name: 'SG UEN',- code: 'sg_uen',+ type: 'sg_uen',country: 'Singapore',placeholder: '123456789F',},{name: 'SI VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Slovenia',placeholder: 'SI12345678',vatPrefix: 'SI',},{name: 'SK VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'Slovakia',placeholder: 'SK1234567891',vatPrefix: 'SK',},{name: 'TH VAT',- code: 'th_vat',+ type: 'th_vat',country: 'Thailand',placeholder: '1234567891234',},{name: 'TR TIN',- code: 'tr_tin',+ type: 'tr_tin',country: 'Turkey',placeholder: '0123456789',},{name: 'TW VAT',- code: 'tw_vat',+ type: 'tw_vat',country: 'Taiwan',placeholder: '12345678',},{name: 'UA VAT',- code: 'ua_vat',+ type: 'ua_vat',country: 'Ukraine',placeholder: '123456789',},{name: 'US EIN',- code: 'us_ein',+ type: 'us_ein',country: 'United States',placeholder: '12-3456789',},{name: 'XI VAT',- code: 'eu_vat',+ type: 'eu_vat',country: 'United Kingdom (Northern Ireland)',placeholder: 'XI123456789',vatPrefix: 'XI',},{name: 'ZA VAT',- code: 'za_vat',+ type: 'za_vat',country: 'South Africa',placeholder: '4123456789',},{name: 'UY RUC',- code: 'uy_ruc',+ type: 'uy_ruc',country: 'Uruguay',placeholder: '123456789012',},{name: 'VE RIF',- code: 've_rif',+ type: 've_rif',country: 'Venezuela',placeholder: 'A-12345678-9',},{name: 'VN TIN',- code: 'vn_tin',+ type: 'vn_tin',country: 'Vietnam',placeholder: '1234567890',},diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsxindex 83d38e71b92..97f2c03c6e7 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx+++ b/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx@@ -1,5 +1,5 @@import { PermissionAction } from '@supabase/shared-types/out/constants'-import { useEffect, useState } from 'react'+import { useEffect, useMemo } from 'react'import toast from 'react-hot-toast'import { useParams } from 'common'@@ -9,127 +9,118 @@ import {ScaffoldSectionDetail,} from 'components/layouts/Scaffold'import AlertError from 'components/ui/AlertError'-import { FormActions, FormPanel, FormSection, FormSectionContent } from 'components/ui/Forms'+import { FormActions } from 'components/ui/Forms'import NoPermission from 'components/ui/NoPermission'import ShimmeringLoader from 'components/ui/ShimmeringLoader'-import { TaxId, useOrganizationTaxIDsQuery } from 'data/organizations/organization-tax-ids-query'-import {- TaxIdValue,- useOrganizationTaxIDsUpdateMutation,-} from 'data/organizations/organization-tax-ids-update-mutation'+import { useOrganizationTaxIdQuery } from 'data/organizations/organization-tax-id-query'+import { useOrganizationTaxIdUpdateMutation } from 'data/organizations/organization-tax-id-update-mutation'import { useCheckPermissions } from 'hooks'-import { uuidv4 } from 'lib/helpers'-import { Button, Form, IconPlus, IconX, Input, Listbox } from 'ui'+import {+ Button,+ FormControl_Shadcn_,+ FormField_Shadcn_,+ FormItem_Shadcn_,+ Form_Shadcn_,+ Input_Shadcn_,+ SelectContent_Shadcn_,+ SelectGroup_Shadcn_,+ SelectItem_Shadcn_,+ SelectTrigger_Shadcn_,+ SelectValue_Shadcn_,+ Select_Shadcn_,+} from 'ui'import { TAX_IDS } from './TaxID.constants'-import { checkTaxIdsEqual, sanitizeTaxID } from './TaxID.utils'+import { checkTaxIdEqual as checkTaxIdEqual, sanitizeTaxIdValue } from './TaxID.utils'+import * as z from 'zod'+import { X as IconX } from 'lucide-react'+import { useForm } from 'react-hook-form'+import { zodResolver } from '@hookform/resolvers/zod'+import Panel from 'components/ui/Panel'const TaxID = () => {const { slug } = useParams()- const {- data: taxIds,- error,- isLoading,- isSuccess,- isError,- } = useOrganizationTaxIDsQuery({ slug })- const { mutate: updateTaxIDs, isLoading: isUpdating } = useOrganizationTaxIDsUpdateMutation({- onSuccess: (res) => {- const { created, errors } = res- setErrors(errors?.map((taxId) => taxId.id) ?? [])- const updatedTaxIds =- created?.map((x) => {- return {- id: x.id,- type: x.type,- value: x.value,- name:- x.type === 'eu_vat'- ? `${x.country} VAT`- : TAX_IDS.find((option) => option.code === x.type)?.name ?? '',- }- }) ?? []- setTaxIdValues(updatedTaxIds)-- if (errors !== undefined && errors.length > 0) {- errors.forEach((taxId: any) => {- toast.error(taxId.result.error.message)- })- } else {- toast.success('Successfully updated tax IDs')- }+ const { data: taxId, error, isLoading, isSuccess, isError } = useOrganizationTaxIdQuery({ slug })+ const { mutate: updateTaxId, isLoading: isUpdating } = useOrganizationTaxIdUpdateMutation({+ onSuccess: () => {+ toast.success('Successfully updated tax id')},})- const [errors, setErrors] = useState<string[]>([])- const [taxIdValues, setTaxIdValues] = useState<TaxIdValue[]>([])+ const FormSchema = z.object({ type: z.string(), value: z.string(), name: z.string() })+ const form = useForm<z.infer<typeof FormSchema>>({+ mode: 'onBlur',+ reValidateMode: 'onBlur',+ resolver: zodResolver(FormSchema),+ defaultValues: { type: '', value: '', name: '' },+ })- const formattedTaxIds =- taxIds?.map((taxId: TaxId) => {- return {- id: taxId.id,+ const formattedTaxId = taxId+ ? {type: taxId.type,value: taxId.value,name:taxId.type === 'eu_vat'? `${taxId.country} VAT`- : TAX_IDS.find((option) => option.code === taxId.type)?.name ?? '',+ : TAX_IDS.find((option) => option.type === taxId.type)?.name ?? '',}- }) ?? []+ : { type: '', value: '', name: '' }- const formId = 'tax-id-form'- const hasChanges = !checkTaxIdsEqual(taxIdValues, formattedTaxIds)- const canReadTaxIds = useCheckPermissions(PermissionAction.BILLING_READ, 'stripe.tax_ids')- const canUpdateTaxIds = useCheckPermissions(PermissionAction.BILLING_WRITE, 'stripe.tax_ids')+ const hasChanges = !checkTaxIdEqual(form.getValues(), formattedTaxId)+ const canReadTaxId = useCheckPermissions(PermissionAction.BILLING_READ, 'stripe.tax_ids')+ const canUpdateTaxId = useCheckPermissions(PermissionAction.BILLING_WRITE, 'stripe.tax_ids')useEffect(() => {- if (isSuccess) {- if (taxIdValues.length === 0) {- setTaxIdValues(formattedTaxIds)- } else {- const erroredTaxIds = taxIdValues.filter((taxId: any) => errors.includes(taxId.id))- setTaxIdValues(formattedTaxIds.concat(erroredTaxIds))- }+ if (isSuccess && formattedTaxId) {+ form.setValue('type', formattedTaxId.type)+ form.setValue('value', formattedTaxId.value)+ form.setValue('name', formattedTaxId.name)}// eslint-disable-next-line react-hooks/exhaustive-deps}, [isSuccess])- const onUpdateTaxId = (id: string, key: string, value: string) => {- const updatedTaxIds = taxIdValues.map((taxId: any) => {- if (taxId.id === id) {- if (key === 'name') {- const selectedTaxIdOption = TAX_IDS.find((option) => option.name === value)- return { ...taxId, [key]: value, type: selectedTaxIdOption?.code }- } else {- return { ...taxId, [key]: value }- }- }- return taxId+ const onSaveTaxId = async () => {+ if (!slug) return console.error('Slug is required')++ const { type, value } = form.getValues()++ if (type?.length && !value?.length) {+ form.setError('value', { message: 'Value is required' })+ return+ }++ updateTaxId({+ slug,+ taxId:+ type?.length && value?.length+ ? {+ type: type,+ value: sanitizeTaxIdValue({ type, value }),+ }+ : null,})- setTaxIdValues(updatedTaxIds)}- const onAddNewTaxId = () => {- const newTaxId = { id: uuidv4(), type: TAX_IDS[0].code, value: '', name: TAX_IDS[0].name }- const updatedTaxIds = taxIdValues.concat([newTaxId])- setTaxIdValues(updatedTaxIds)+ const onResetTaxIds = () => {+ form.setValue('type', formattedTaxId.type)+ form.setValue('value', formattedTaxId.value)+ form.setValue('name', formattedTaxId.name)}- const onRemoveTaxId = (id: string) => {- const updatedTaxIds = taxIdValues.filter((taxId) => taxId.id !== id)- setTaxIdValues(updatedTaxIds)+ const onSelectTaxIdType = (name: string) => {+ const selectedTaxIdOption = TAX_IDS.find((option) => option.name === name)+ if (!selectedTaxIdOption) return+ form.setValue('type', selectedTaxIdOption.type)+ form.setValue('value', '')+ form.setValue('name', name)}- const onResetTaxIds = () => {- setTaxIdValues(formattedTaxIds)+ const onRemoveTaxId = () => {+ form.reset()}- const onSaveTaxIds = async (values: any) => {- if (!slug) return console.error('Slug is required')- if (taxIds === undefined) return console.error('Tax IDs are required')+ const { name } = form.watch()- const newIds = taxIdValues.map((x) => sanitizeTaxID(x))- updateTaxIDs({ slug, existingIds: taxIds, newIds })- }+ const selectedTaxId = TAX_IDS.find((option) => option.name === name)return (<ScaffoldSection>@@ -137,7 +128,7 @@ const TaxID = () => {<div className="sticky space-y-2 top-12"><p className="text-foreground text-base m-0">Tax ID</p><p className="text-sm text-foreground-light pr-4 m-0">- Add tax ID(s) to have them appear in your invoices. Old invoices are not affected.+ Add a tax ID to your invoices. Changes only apply to future invoices.</p><p className="text-sm text-foreground-light m-0">Make sure the tax ID looks exactly like the placeholder text.@@ -145,8 +136,8 @@ const TaxID = () => {</div></ScaffoldSectionDetail><ScaffoldSectionContent>- {!canReadTaxIds ? (- <NoPermission resourceText="view this organization's tax IDs" />+ {!canReadTaxId ? (+ <NoPermission resourceText="view this organization's tax ID" />) : (<>{isLoading && (@@ -158,98 +149,93 @@ const TaxID = () => {)}{isError && (- <AlertError error={error} subject="Failed to retrieve organization tax IDs" />+ <AlertError error={error} subject="Failed to retrieve organization tax Id" />)}{isSuccess && (- <Form validateOnBlur id={formId} initialValues={{}} onSubmit={onSaveTaxIds}>- {() => (- <FormPanel- footer={- <div className="flex py-4 px-8">- <FormActions- form={formId}- isSubmitting={isUpdating}- hasChanges={hasChanges}- handleReset={() => onResetTaxIds()}- helper={- !canUpdateTaxIds- ? "You need additional permissions to manage this organization's tax IDs"- : undefined- }- />- </div>+ <Panel+ className="mb-8"+ footer={+ <FormActions+ form="tax-id-form"+ isSubmitting={isUpdating}+ hasChanges={hasChanges}+ handleReset={() => onResetTaxIds()}+ helper={+ !canUpdateTaxId+ ? "You need additional permissions to manage this organization's tax ID"+ : undefined}+ />+ }+ >+ <Form_Shadcn_ {...form}>+ <form+ id="tax-id-form"+ className="grid grid-cols-2 gap-2 w-full py-8 px-8 items-center"+ onSubmit={form.handleSubmit(() => onSaveTaxId())}>- <FormSection>- <FormSectionContent fullWidth loading={false}>- {taxIdValues.length >= 1 ? (- <div className="w-full space-y-2">- {taxIdValues.map((taxId, idx: number) => {- const selectedTaxId = TAX_IDS.find(- (option) => option.name === taxId.name- )- return (- <div key={`tax-id-${idx}`} className="flex items-center space-x-2">- <Listbox- value={selectedTaxId?.name}- onChange={(e: any) => onUpdateTaxId(taxId.id, 'name', e)}- disabled={!canUpdateTaxIds}- className="w-[200px]"- >- {TAX_IDS.sort((a, b) => a.country.localeCompare(b.country)).map(- (option) => (- <Listbox.Option- key={option.name}- value={option.name}- label={option.name}- >- {option.country} - {option.name}- </Listbox.Option>- )- )}- </Listbox>- <Input- value={taxId.value}- placeholder={selectedTaxId?.placeholder ?? ''}- onChange={(e: any) =>- onUpdateTaxId(taxId.id, 'value', e.target.value)- }- disabled={!canUpdateTaxIds}- />- {canUpdateTaxIds && (- <Button- type="text"- className="px-1"- icon={<IconX />}- onClick={() => onRemoveTaxId(taxId.id)}- />+ <FormField_Shadcn_+ name="name"+ control={form.control}+ render={({ field }) => (+ <FormItem_Shadcn_>+ <FormControl_Shadcn_>+ <Select_Shadcn_+ {...field}+ disabled={!canUpdateTaxId}+ value={field.value}+ onValueChange={(value) => onSelectTaxIdType(value)}+ >+ <SelectTrigger_Shadcn_>+ <SelectValue_Shadcn_ placeholder="None" />+ </SelectTrigger_Shadcn_>+ <SelectContent_Shadcn_>+ <SelectGroup_Shadcn_>+ {TAX_IDS.sort((a, b) => a.country.localeCompare(b.country)).map(+ (option) => (+ <SelectItem_Shadcn_ key={option.name} value={option.name}>+ {option.country} - {option.name}+ </SelectItem_Shadcn_>+ ))}- </div>- )- })}- </div>- ) : (- <div>- <p className="flex items-center space-x-2 text-sm text-foreground-lighter">- No tax IDs- </p>- </div>- )}- {canUpdateTaxIds && (- <div- className="flex cursor-pointer items-center space-x-2 opacity-50 transition hover:opacity-100"- onClick={() => onAddNewTaxId()}- >- <IconPlus size={14} />- <p className="text-sm">Add another ID</p>- </div>- )}- </FormSectionContent>- </FormSection>- </FormPanel>- )}- </Form>+ </SelectGroup_Shadcn_>+ </SelectContent_Shadcn_>+ </Select_Shadcn_>+ </FormControl_Shadcn_>+ </FormItem_Shadcn_>+ )}+ />++ {selectedTaxId && (+ <div className="flex items-center space-x-2">+ <FormField_Shadcn_+ name="value"+ control={form.control}+ render={({ field }) => (+ <FormItem_Shadcn_ className="w-full">+ <FormControl_Shadcn_>+ <Input_Shadcn_+ {...field}+ placeholder={selectedTaxId?.placeholder}+ disabled={!canUpdateTaxId}+ />+ </FormControl_Shadcn_>+ </FormItem_Shadcn_>+ )}+ />++ <Button+ type="text"+ className="px-1"+ icon={<IconX />}+ onClick={() => onRemoveTaxId()}+ />+ </div>+ )}+ </form>+ </Form_Shadcn_>+ </Panel>)}</>)}diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.utils.ts b/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.utils.tsindex a7a8b935ce7..ce69896aff4 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.utils.ts+++ b/apps/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.utils.ts@@ -1,29 +1,19 @@-import { TaxIdValue } from 'data/organizations/organization-tax-ids-update-mutation'import { TAX_IDS } from './TaxID.constants'-import { isEqual, sortBy } from 'lodash'-export const sanitizeTaxID = (taxId: TaxIdValue) => {- let newID = taxId-- const selectedTaxId = TAX_IDS.find((option) => option.name === taxId.name)+export const sanitizeTaxIdValue = (taxId: { type: string; value: string }) => {+ const selectedTaxId = TAX_IDS.find((option) => option.type === taxId.type)const vatIdPrefix = selectedTaxId?.vatPrefix// if the value doesn't start with the prefix, prepend themif (vatIdPrefix && !taxId.value.startsWith(vatIdPrefix)) {- newID.value = `${vatIdPrefix}${taxId.value}`+ return `${vatIdPrefix}${taxId.value}`}- return newID+ return taxId.value}/** Ignore id property amongst tax ids */-export const checkTaxIdsEqual = (a: any[], b: any[]) => {- const aExcludeId = a.map((x) => {- return { type: x.type, value: x.value, name: x.name }- })- const bExcludeId = b.map((x) => {- return { type: x.type, value: x.value, name: x.name }- })- return isEqual(sortBy(aExcludeId, 'name'), sortBy(bExcludeId, 'name'))+export const checkTaxIdEqual = (a: any, b: any) => {+ return a?.type === b?.type && a?.value === b?.value}diff --git a/apps/studio/data/organizations/keys.ts b/apps/studio/data/organizations/keys.tsindex ff03165c3b2..4cd9bd10ae9 100644--- a/apps/studio/data/organizations/keys.ts+++ b/apps/studio/data/organizations/keys.ts@@ -13,7 +13,7 @@ export const organizationKeys = {) => ['organizations', slug, 'audit-logs', { date_start, date_end }] as const,subscriptionPreview: (slug: string | undefined, tier: string | undefined) =>['organizations', slug, 'subscription', 'preview', tier] as const,- taxIds: (slug: string | undefined) => ['organizations', slug, 'tax-ids'] as const,+ taxId: (slug: string | undefined) => ['organizations', slug, 'tax-ids'] as const,tokenValidation: (slug: string | undefined, token: string | undefined) =>['organizations', slug, 'validate-token', token] as const,}diff --git a/apps/studio/data/organizations/organization-tax-id-query.ts b/apps/studio/data/organizations/organization-tax-id-query.tsnew file mode 100644index 00000000000..233dc15da4a--- /dev/null+++ b/apps/studio/data/organizations/organization-tax-id-query.ts@@ -0,0 +1,47 @@+import { useQuery, UseQueryOptions } from '@tanstack/react-query'+import { get, handleError } from 'data/fetchers'+import { organizationKeys } from './keys'+import type { ResponseError } from 'types'+import { components } from 'api-types'++export type OrganizationTaxIdVariables = {+ slug?: string+}++export async function getOrganizationTaxId(+ { slug }: OrganizationTaxIdVariables,+ signal?: AbortSignal+) {+ if (!slug) throw new Error('slug is required')++ const { data, error } = await get(`/platform/organizations/{slug}/tax-ids`, {+ params: { path: { slug } },+ signal,+ headers: {+ Version: '2',+ },+ })+ if (error) throw handleError(error)++ // @ts-ignore wrong typing due to mgmt api versioning+ return (data as components['schemas']['TaxIdV2Response']).tax_id+}++export type OrganizationTaxIdData = Awaited<ReturnType<typeof getOrganizationTaxId>>+export type OrganizationTaxIdError = ResponseError++export const useOrganizationTaxIdQuery = <TData = OrganizationTaxIdData>(+ { slug }: OrganizationTaxIdVariables,+ {+ enabled = true,+ ...options+ }: UseQueryOptions<OrganizationTaxIdData, OrganizationTaxIdError, TData> = {}+) =>+ useQuery<OrganizationTaxIdData, OrganizationTaxIdError, TData>(+ organizationKeys.taxId(slug),+ ({ signal }) => getOrganizationTaxId({ slug }, signal),+ {+ enabled: enabled && typeof slug !== 'undefined',+ ...options,+ }+ )diff --git a/apps/studio/data/organizations/organization-tax-id-update-mutation.ts b/apps/studio/data/organizations/organization-tax-id-update-mutation.tsnew file mode 100644index 00000000000..e0763e33220--- /dev/null+++ b/apps/studio/data/organizations/organization-tax-id-update-mutation.ts@@ -0,0 +1,82 @@+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'+import { toast } from 'react-hot-toast'++import type { ResponseError } from 'types'+import { organizationKeys } from './keys'+import { put, del, handleError } from 'data/fetchers'++export type OrganizationTaxIdUpdateVariables = {+ slug: string+ taxId: { type: string; value: string } | null+}++export async function updateOrganizationTaxId({ slug, taxId }: OrganizationTaxIdUpdateVariables) {+ if (!slug) {+ throw new Error('Slug is required')+ }++ if (taxId != null) {+ const { data, error } = await put(`/platform/organizations/{slug}/tax-ids`, {+ params: {+ path: {+ slug,+ },+ },+ body: { type: taxId.type, value: taxId.value },+ })++ if (error) handleError(error)++ return data+ } else {+ // @ts-ignore wrong type due to API versioning+ const { data, error } = await del(`/platform/organizations/{slug}/tax-ids`, {+ params: {+ path: {+ slug,+ },+ },+ headers: {+ Version: '2',+ },+ })++ if (error) handleError(error)++ return data+ }+}++type OrganizationTaxIdUpdateData = Awaited<ReturnType<typeof updateOrganizationTaxId>>++export const useOrganizationTaxIdUpdateMutation = ({+ onSuccess,+ onError,+ ...options+}: Omit<+ UseMutationOptions<OrganizationTaxIdUpdateData, ResponseError, OrganizationTaxIdUpdateVariables>,+ 'mutationFn'+> = {}) => {+ const queryClient = useQueryClient()++ return useMutation<OrganizationTaxIdUpdateData, ResponseError, OrganizationTaxIdUpdateVariables>(+ (vars) => updateOrganizationTaxId(vars),+ {+ async onSuccess(data, variables, context) {+ const { slug } = variables++ // We already have the data, no need to refetch+ queryClient.setQueryData(organizationKeys.taxId(slug), data.tax_id)+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to update tax id: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ }+ )+}diff --git a/apps/studio/data/organizations/organization-tax-ids-query.ts b/apps/studio/data/organizations/organization-tax-ids-query.tsdeleted file mode 100644index 8b650ef6089..00000000000--- a/apps/studio/data/organizations/organization-tax-ids-query.ts+++ /dev/null@@ -1,57 +0,0 @@-import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'lib/common/fetch'-import { API_URL } from 'lib/constants'-import { useCallback } from 'react'-import { organizationKeys } from './keys'-import type { ResponseError } from 'types'--export type OrganizationTaxIDsVariables = {- slug?: string-}--export type TaxId = {- country: string- created: number- customer: string- id: string- livemode: boolean- object: 'tax_id'- type: string- value: string- verification: {- status: string- verified_address: string | null- verified_name: string | null- }-}--export async function getOrganizationTaxIDs(- { slug }: OrganizationTaxIDsVariables,- signal?: AbortSignal-) {- if (!slug) throw new Error('slug is required')-- const data = await get(`${API_URL}/organizations/${slug}/tax-ids`, { signal })- if (data.error) throw data.error-- return data.data as TaxId[]-}--export type OrganizationTaxIDsData = Awaited<ReturnType<typeof getOrganizationTaxIDs>>-export type OrganizationTaxIDsError = ResponseError--export const useOrganizationTaxIDsQuery = <TData = OrganizationTaxIDsData>(- { slug }: OrganizationTaxIDsVariables,- {- enabled = true,- ...options- }: UseQueryOptions<OrganizationTaxIDsData, OrganizationTaxIDsError, TData> = {}-) =>- useQuery<OrganizationTaxIDsData, OrganizationTaxIDsError, TData>(- organizationKeys.taxIds(slug),- ({ signal }) => getOrganizationTaxIDs({ slug }, signal),- {- enabled: enabled && typeof slug !== 'undefined',- ...options,- }- )diff --git a/apps/studio/data/organizations/organization-tax-ids-update-mutation.ts b/apps/studio/data/organizations/organization-tax-ids-update-mutation.tsdeleted file mode 100644index 9a87e5b4c3a..00000000000--- a/apps/studio/data/organizations/organization-tax-ids-update-mutation.ts+++ /dev/null@@ -1,98 +0,0 @@-import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'-import { toast } from 'react-hot-toast'--import { delete_, post } from 'lib/common/fetch'-import { API_URL } from 'lib/constants'-import type { ResponseError } from 'types'-import { organizationKeys } from './keys'-import type { TaxId } from './organization-tax-ids-query'--export interface TaxIdValue {- id: string- type: string- value: string- name: string-}--export type OrganizationTaxIDsUpdateVariables = {- slug: string- existingIds: TaxId[]- newIds: TaxIdValue[]-}--export async function updateOrganizationTaxIDs({- slug,- existingIds,- newIds,-}: OrganizationTaxIDsUpdateVariables) {- if (!slug) {- console.error('Slug is required')- return {}- }-- // To make things simple we delete all existing ones and create new ones from this session- if (existingIds.length > 0) {- await Promise.all(- existingIds.map(async (taxId) => {- return await delete_(`${API_URL}/organizations/${slug}/tax-ids`, { id: taxId.id })- })- )- }-- const createdIds = await Promise.all(- newIds.map(async (taxId) => {- const result = await post(`${API_URL}/organizations/${slug}/tax-ids`, {- type: taxId.type,- value: taxId.value,- })- return { id: taxId.id, result }- })- )-- const taxIdsWithErrors = createdIds.filter((taxId) => {- if (taxId.result.error) return taxId- })-- const idsCreated = createdIds- .filter((taxId: any) => !taxId.result.error)- .map((taxId: any) => taxId.result)-- return { created: idsCreated, errors: taxIdsWithErrors }-}--type OrganizationTaxIDsUpdateData = Awaited<ReturnType<typeof updateOrganizationTaxIDs>>--export const useOrganizationTaxIDsUpdateMutation = ({- onSuccess,- onError,- ...options-}: Omit<- UseMutationOptions<- OrganizationTaxIDsUpdateData,- ResponseError,- OrganizationTaxIDsUpdateVariables- >,- 'mutationFn'-> = {}) => {- const queryClient = useQueryClient()-- return useMutation<- OrganizationTaxIDsUpdateData,- ResponseError,- OrganizationTaxIDsUpdateVariables- >((vars) => updateOrganizationTaxIDs(vars), {- async onSuccess(data, variables, context) {- const { slug } = variables- await queryClient.invalidateQueries(organizationKeys.taxIds(slug))- await onSuccess?.(data, variables, context)- },- async onError(data, variables, context) {- if (onError === undefined) {- toast.error(`Failed to update tax IDs: ${data.message}`)- } else {- onError(data, variables, context)- }- },- ...options,- })-}diff --git a/apps/studio/tests/components/Billing/TaxID.utils.test.ts b/apps/studio/tests/components/Billing/TaxID.utils.test.tsindex 7720b4a747b..f5cec98e7f8 100644--- a/apps/studio/tests/components/Billing/TaxID.utils.test.ts+++ b/apps/studio/tests/components/Billing/TaxID.utils.test.ts@@ -1,4 +1,4 @@-import { sanitizeTaxID } from 'components/interfaces/Organization/BillingSettings/TaxID/TaxID.utils'+import { sanitizeTaxIdValue } from 'components/interfaces/Organization/BillingSettings/TaxID/TaxID.utils'/*** We're sanitizing EU tax ids. Stripe expects a prefixed tax id (ATU12345678),@@ -19,8 +19,8 @@ describe('TaxID utils: sanitizeTaxID', () => {name: 'AT VAT',}- const sanitizedID = sanitizeTaxID(austriaTaxID)- expect(sanitizedID.value).toBe('ATU12345678')+ const sanitizedID = sanitizeTaxIdValue(austriaTaxID)+ expect(sanitizedID).toBe('ATU12345678')})test('should check that EU prefix is correct', () => {@@ -31,8 +31,8 @@ describe('TaxID utils: sanitizeTaxID', () => {name: 'AT VAT',}- const sanitizedID = sanitizeTaxID(austriaTaxID)- expect(sanitizedID.value).toBe('ATU12345678')+ const sanitizedID = sanitizeTaxIdValue(austriaTaxID)+ expect(sanitizedID).toBe('ATU12345678')})test('should not prefix an non-EU tax ID', () => {@@ -43,7 +43,7 @@ describe('TaxID utils: sanitizeTaxID', () => {name: 'US EIN',}- const sanitizedID = sanitizeTaxID(unitedStatesID)- expect(sanitizedID.value).toBe('12-3456789')+ const sanitizedID = sanitizeTaxIdValue(unitedStatesID)+ expect(sanitizedID).toBe('12-3456789')})})diff --git a/packages/api-types/types/api.d.ts b/packages/api-types/types/api.d.tsindex 510022ac7c3..1f00abc4776 100644--- a/packages/api-types/types/api.d.ts+++ b/packages/api-types/types/api.d.ts@@ -167,6 +167,8 @@ export interface paths {'/platform/organizations/{slug}/tax-ids': {/** Gets the given organization's tax IDs */get: operations['TaxIdsController_getTaxIds']+ /** Creates or updates a tax ID for the given organization */+ put: operations['TaxIdsController_updateTaxId']/** Creates a tax ID for the given organization */post: operations['TaxIdsController_createTaxId']/** Delete the tax ID with the given ID */@@ -993,6 +995,10 @@ export interface paths {/** Deletes all Edge Functions from a project */delete: operations['SystemFunctionsController_systemDeleteAllFunctions']}+ '/system/projects/{ref}/run-lints': {+ /** Run project lints */+ get: operations['SystemProjectRunLintsController_runProjectLints']+ }'/system/projects/{ref}/secrets': {/*** List all secrets@@ -2637,6 +2643,14 @@ export interface components {org_scoped_roles: components['schemas']['OrganizationRoleV2'][]project_scoped_roles: components['schemas']['OrganizationRoleV2'][]}+ TaxIdV2: {+ country: string+ type: string+ value: string+ }+ TaxIdV2Response: {+ tax_id: components['schemas']['TaxIdV2'] | null+ }TaxId: {id: stringcountry: string@@ -2647,7 +2661,7 @@ export interface components {data: components['schemas']['TaxId'][]}CreateTaxIdBody: {- type: Record<string, never>+ type: stringvalue: string}CreateTaxIdResponse: {@@ -2701,6 +2715,11 @@ export interface components {| 'COMPUTE_HOURS_8XL'| 'COMPUTE_HOURS_12XL'| 'COMPUTE_HOURS_16XL'+ | 'CUSTOM_DOMAIN'+ | 'PITR_7'+ | 'PITR_14'+ | 'PITR_28'+ | 'IPV4'/** @enum {string} */pricing_strategy: 'UNIT' | 'PACKAGE' | 'NONE'pricing_free_units?: number@@ -4106,11 +4125,6 @@ export interface components {name: stringlimit: number}- PreviewTransferInvoiceItem: {- description: string- quantity: number- amount: number- }PreviewProjectTransferResponse: {source_subscription_plan: components['schemas']['BillingPlanId']target_subscription_plan: components['schemas']['BillingPlanId']@@ -4123,11 +4137,6 @@ export interface components {source_project_eligible: booleantarget_organization_eligible: boolean | nulltarget_organization_has_free_project_slots: boolean | null- credits_on_source_organization: number- costs_on_target_organization: number- charge_on_target_organization: number- source_invoice_items: components['schemas']['PreviewTransferInvoiceItem'][]- target_invoice_items: components['schemas']['PreviewTransferInvoiceItem'][]}AnalyticsResponse: {error?: OneOf<@@ -5012,10 +5021,13 @@ export interface components {| 'INACTIVE'| 'INIT_FAILED'| 'REMOVED'- | 'RESTORING'+ | 'RESTARTING'| 'UNKNOWN'| 'UPGRADING'| 'PAUSING'+ | 'RESTORING'+ | 'RESTORE_FAILED'+ | 'PAUSE_FAILED'db_host: stringdb_user?: stringdb_pass?: string@@ -5088,10 +5100,13 @@ export interface components {| 'INACTIVE'| 'INIT_FAILED'| 'REMOVED'- | 'RESTORING'+ | 'RESTARTING'| 'UNKNOWN'| 'UPGRADING'| 'PAUSING'+ | 'RESTORING'+ | 'RESTORE_FAILED'+ | 'PAUSE_FAILED'}V1CreateProjectBody: {/** @description Database password */@@ -5890,17 +5905,20 @@ export interface components {* @enum {string}*/status:- | 'REMOVED'- | 'COMING_UP'- | 'INACTIVE'| 'ACTIVE_HEALTHY'| 'ACTIVE_UNHEALTHY'- | 'UNKNOWN'+ | 'COMING_UP'| 'GOING_DOWN'+ | 'INACTIVE'| 'INIT_FAILED'- | 'RESTORING'+ | 'REMOVED'+ | 'RESTARTING'+ | 'UNKNOWN'| 'UPGRADING'| 'PAUSING'+ | 'RESTORING'+ | 'RESTORE_FAILED'+ | 'PAUSE_FAILED'/*** @description Supabase organization id* @example fly_123456789@@ -6001,17 +6019,20 @@ export interface components {* @enum {string}*/status:- | 'REMOVED'- | 'COMING_UP'- | 'INACTIVE'| 'ACTIVE_HEALTHY'| 'ACTIVE_UNHEALTHY'- | 'UNKNOWN'+ | 'COMING_UP'| 'GOING_DOWN'+ | 'INACTIVE'| 'INIT_FAILED'- | 'RESTORING'+ | 'REMOVED'+ | 'RESTARTING'+ | 'UNKNOWN'| 'UPGRADING'| 'PAUSING'+ | 'RESTORING'+ | 'RESTORE_FAILED'+ | 'PAUSE_FAILED'/*** @description Supabase organization id* @example fly_123456789@@ -6961,6 +6982,34 @@ export interface operations {}}}+ /** Creates or updates a tax ID for the given organization */+ TaxIdsController_updateTaxId: {+ parameters: {+ path: {+ /** @description Organization slug */+ slug: string+ }+ }+ requestBody: {+ content: {+ 'application/json': components['schemas']['CreateTaxIdBody']+ }+ }+ responses: {+ 200: {+ content: {+ 'application/json': components['schemas']['TaxIdV2Response']+ }+ }+ 403: {+ content: never+ }+ /** @description Failed to create the tax ID */+ 500: {+ content: never+ }+ }+ }/** Creates a tax ID for the given organization */TaxIdsController_createTaxId: {parameters: {@@ -7058,6 +7107,11 @@ export interface operations {| 'COMPUTE_HOURS_8XL'| 'COMPUTE_HOURS_12XL'| 'COMPUTE_HOURS_16XL'+ | 'CUSTOM_DOMAIN'+ | 'PITR_7'+ | 'PITR_14'+ | 'PITR_28'+ | 'IPV4'interval: stringendDate: stringstartDate: string@@ -12590,6 +12644,25 @@ export interface operations {}}}+ /** Run project lints */+ SystemProjectRunLintsController_runProjectLints: {+ parameters: {+ path: {+ /** @description Project ref */+ ref: string+ }+ }+ responses: {+ 200: {+ content: {+ 'application/json': components['schemas']['ProjectLintResponse'][]+ }+ }+ 403: {+ content: never+ }+ }+ }/*** List all secrets* @description Returns all secrets you've previously added to the specified project.