The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add and refactor the other components to org billing for billing v2
Joshen Lim0ed5e40c4c9a
diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsxindex 42ecf17386e..98438a7f4df 100644--- a/studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsx@@ -75,6 +75,7 @@ const BillingEmail = () => {useEffect(() => {const values = { billing_email: billing_email ?? '' }resetForm({ values, initialValues: values })+ // eslint-disable-next-line react-hooks/exhaustive-deps}, [slug])return (diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingSettingsV2.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingSettingsV2.tsxdeleted file mode 100644index 8a3a736386f..00000000000--- a/studio/components/interfaces/Organization/BillingSettings/BillingSettingsV2.tsx+++ /dev/null@@ -1,19 +0,0 @@-import CostControl from './CostControl/CostControl'-import Subscription from './Subscription/Subscription'--const BillingSettingsV2 = () => {- return (- <>- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">- <Subscription />- </div>- <div className="border-b" />- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">- <CostControl />- </div>- <div className="border-b" />- </>- )-}--export default BillingSettingsV2diff --git a/studio/components/interfaces/Organization/BillingSettings/CostControl/CostControl.tsx b/studio/components/interfaces/Organization/BillingSettings/CostControl/CostControl.tsxdeleted file mode 100644index cc6641c7014..00000000000--- a/studio/components/interfaces/Organization/BillingSettings/CostControl/CostControl.tsx+++ /dev/null@@ -1,151 +0,0 @@-import Link from 'next/link'--import { useParams, useTheme } from 'common'-import ShimmeringLoader from 'components/ui/ShimmeringLoader'-import { BASE_PATH } from 'lib/constants'-import { useSubscriptionPageStateSnapshot } from 'state/subscription-page'-import { Alert, Button, IconExternalLink } from 'ui'-// import SpendCapSidePanel from './SpendCapSidePanel'-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'-import { useFlag } from 'hooks'-import ProjectUpdateDisabledTooltip from '../ProjectUpdateDisabledTooltip'--export interface CostControlProps {}--const CostControl = ({}: CostControlProps) => {- const { slug } = useParams()- const snap = useSubscriptionPageStateSnapshot()- const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')- const { isDarkMode } = useTheme()-- const { data: subscription, isLoading } = useOrgSubscriptionQuery({ orgSlug: slug })-- const currentPlan = subscription?.plan- const isUsageBillingEnabled = subscription?.usage_billing_enabled ?? false-- const canChangeTier =- !projectUpdateDisabled && !['team', 'enterprise'].includes(currentPlan?.id || '')-- return (- <>- <div className="grid grid-cols-12 gap-6" id="cost-control">- <div className="col-span-12 lg:col-span-5">- <div className="sticky top-16">- <div className="space-y-6">- <div>- <p className="text-base">Cost Control</p>- <p className="text-sm text-scale-1000">- Control whether to use beyond your plans included quota- </p>- </div>- <div className="space-y-2">- <p className="text-sm text-scale-1100">More information</p>- <div>- <Link href="https://supabase.com/docs/guides/platform/spend-cap">- <a target="_blank" rel="noreferrer">- <div className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition">- <p className="text-sm">Spend cap</p>- <IconExternalLink size={16} strokeWidth={1.5} />- </div>- </a>- </Link>- </div>- </div>- </div>- </div>- </div>- {isLoading ? (- <div className="col-span-12 lg:col-span-7 space-y-2">- <ShimmeringLoader />- <ShimmeringLoader className="w-3/4" />- <ShimmeringLoader className="w-1/2" />- </div>- ) : (- <div className="col-span-12 lg:col-span-7 space-y-6">- {['team', 'enterprise'].includes(currentPlan?.id || '') ? (- <Alert- withIcon- variant="info"- title={`You will be charged for any additional usage on the ${- currentPlan?.name || ''- } plan`}- >- {currentPlan?.name || ''} plan requires you to have spend cap off at all times. Your- projects will never become unresponsive. Only when your{' '}- <Link href="#breakdown">- <a className="text-sm text-green-900 transition hover:text-green-1000">- included usage- </a>- </Link>{' '}- is exceeded will you be charged for any additional usage.- </Alert>- ) : (- <p className="text-sm text-scale-1000">- You can control whether your organization is charged for additional usage beyond the{' '}- <Link href="#breakdown">- <a className="text-sm text-green-900 transition hover:text-green-1000">- included quota- </a>- </Link>{' '}- of your subscription plan. If you need to go beyond the included quota, simply- switch off your spend cap to pay for additional usage.- </p>- )}-- <div className="flex space-x-6">- <div>- <div className="rounded-md bg-scale-100 dark:bg-scale-400 w-[160px] h-[96px] shadow">- <img- alt="Spend Cap"- width={160}- height={96}- src={- isUsageBillingEnabled- ? `${BASE_PATH}/img/spend-cap-off${isDarkMode ? '' : '--light'}.png?v=3`- : `${BASE_PATH}/img/spend-cap-on${isDarkMode ? '' : '--light'}.png?v=3`- }- />- </div>- </div>- <div>- <p className="mb-1">- Spend cap is {isUsageBillingEnabled ? 'disabled' : 'enabled'}- </p>- <p className="text-sm text-scale-1000">- {isUsageBillingEnabled ? (- <span>You will be charged for any usage above the included quota.</span>- ) : (- <span>- You won't be charged any extra for usage. However, your projects could become- unresponsive or enter read only mode if you exceed the included quota.- </span>- )}- </p>- {isUsageBillingEnabled && (- <p className="text-sm text-scale-1000 mt-1">- Your projects will never become unresponsive. Only when your usage reaches the- quota limit will you be charged for any excess usage.- </p>- )}- <ProjectUpdateDisabledTooltip projectUpdateDisabled={projectUpdateDisabled}>- <Button- type="default"- className="mt-4"- disabled={!canChangeTier}- onClick={() => snap.setPanelKey('costControl')}- >- Change spend cap- </Button>- </ProjectUpdateDisabledTooltip>- </div>- </div>- </div>- )}- </div>-- {/* <SpendCapSidePanel /> */}- </>- )-}--export default CostControldiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.constants.ts b/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.constants.tsnew file mode 100644index 00000000000..728b4ecef37--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.constants.ts@@ -0,0 +1,248 @@+export const COUNTRIES = [+ { code: 'AF', name: 'Afghanistan' },+ { code: 'AL', name: 'Albania' },+ { code: 'DZ', name: 'Algeria' },+ { code: 'AS', name: 'American Samoa' },+ { code: 'AD', name: 'Andorra' },+ { code: 'AO', name: 'Angola' },+ { code: 'AI', name: 'Anguilla' },+ { code: 'AQ', name: 'Antarctica' },+ { code: 'AG', name: 'Antigua and Barbuda' },+ { code: 'AR', name: 'Argentina' },+ { code: 'AM', name: 'Armenia' },+ { code: 'AW', name: 'Aruba' },+ { code: 'AU', name: 'Australia' },+ { code: 'AT', name: 'Austria' },+ { code: 'AZ', name: 'Azerbaijan' },+ { code: 'BS', name: 'Bahamas' },+ { code: 'BH', name: 'Bahrain' },+ { code: 'BD', name: 'Bangladesh' },+ { code: 'BB', name: 'Barbados' },+ { code: 'BY', name: 'Belarus' },+ { code: 'BE', name: 'Belgium' },+ { code: 'BZ', name: 'Belize' },+ { code: 'BJ', name: 'Benin' },+ { code: 'BM', name: 'Bermuda' },+ { code: 'BT', name: 'Bhutan' },+ { code: 'BO', name: 'Bolivia' },+ { code: 'BA', name: 'Bosnia and Herzegovina' },+ { code: 'BW', name: 'Botswana' },+ { code: 'BV', name: 'Bouvet Island' },+ { code: 'BR', name: 'Brazil' },+ { code: 'IO', name: 'British Indian Ocean Territory' },+ { code: 'VG', name: 'British Virgin Islands' },+ { code: 'BN', name: 'Brunei Darussalam' },+ { code: 'BG', name: 'Bulgaria' },+ { code: 'BF', name: 'Burkina Faso' },+ { code: 'BI', name: 'Burundi' },+ { code: 'KH', name: 'Cambodia' },+ { code: 'CM', name: 'Cameroon' },+ { code: 'CA', name: 'Canada' },+ { code: 'CV', name: 'Cape Verde' },+ { code: 'KY', name: 'Cayman Islands' },+ { code: 'CF', name: 'Central African Republic' },+ { code: 'TD', name: 'Chad' },+ { code: 'CL', name: 'Chile' },+ { code: 'CN', name: 'China' },+ { code: 'CX', name: 'Christmas Island' },+ { code: 'CC', name: 'Cocos (Keeling) Islands' },+ { code: 'CO', name: 'Colombia' },+ { code: 'KM', name: 'Comoros' },+ { code: 'CG', name: 'Congo' },+ { code: 'CK', name: 'Cook Islands' },+ { code: 'CR', name: 'Costa Rica' },+ { code: 'HR', name: 'Croatia' },+ { code: 'CU', name: 'Cuba' },+ { code: 'CW', name: 'Curaçao' },+ { code: 'CY', name: 'Cyprus' },+ { code: 'CZ', name: 'Czech Republic' },+ { code: 'CI', name: "Côte d'Ivoire" },+ { code: 'DK', name: 'Denmark' },+ { code: 'DJ', name: 'Djibouti' },+ { code: 'DM', name: 'Dominica' },+ { code: 'DO', name: 'Dominican Republic' },+ { code: 'EC', name: 'Ecuador' },+ { code: 'EG', name: 'Egypt' },+ { code: 'SV', name: 'El Salvador' },+ { code: 'GQ', name: 'Equatorial Guinea' },+ { code: 'ER', name: 'Eritrea' },+ { code: 'EE', name: 'Estonia' },+ { code: 'SZ', name: 'Eswatini' },+ { code: 'ET', name: 'Ethiopia' },+ { code: 'FK', name: 'Falkland Islands' },+ { code: 'FO', name: 'Faroe Islands' },+ { code: 'FJ', name: 'Fiji' },+ { code: 'FI', name: 'Finland' },+ { code: 'FR', name: 'France' },+ { code: 'GF', name: 'French Guiana' },+ { code: 'PF', name: 'French Polynesia' },+ { code: 'TF', name: 'French Southern Territories' },+ { code: 'GA', name: 'Gabon' },+ { code: 'GM', name: 'Gambia' },+ { code: 'GE', name: 'Georgia' },+ { code: 'DE', name: 'Germany' },+ { code: 'GH', name: 'Ghana' },+ { code: 'GI', name: 'Gibraltar' },+ { code: 'GR', name: 'Greece' },+ { code: 'GL', name: 'Greenland' },+ { code: 'GD', name: 'Grenada' },+ { code: 'GP', name: 'Guadeloupe' },+ { code: 'GU', name: 'Guam' },+ { code: 'GT', name: 'Guatemala' },+ { code: 'GG', name: 'Guernsey' },+ { code: 'GN', name: 'Guinea' },+ { code: 'GW', name: 'Guinea-Bissau' },+ { code: 'GY', name: 'Guyana' },+ { code: 'HT', name: 'Haiti' },+ { code: 'HM', name: 'Heard & McDonald Islands' },+ { code: 'HN', name: 'Honduras' },+ { code: 'HK', name: 'Hong Kong' },+ { code: 'HU', name: 'Hungary' },+ { code: 'IS', name: 'Iceland' },+ { code: 'IN', name: 'India' },+ { code: 'ID', name: 'Indonesia' },+ { code: 'IR', name: 'Iran' },+ { code: 'IQ', name: 'Iraq' },+ { code: 'IE', name: 'Ireland' },+ { code: 'IM', name: 'Isle of Man' },+ { code: 'IL', name: 'Israel' },+ { code: 'IT', name: 'Italy' },+ { code: 'JM', name: 'Jamaica' },+ { code: 'JP', name: 'Japan' },+ { code: 'JE', name: 'Jersey' },+ { code: 'JO', name: 'Jordan' },+ { code: 'KZ', name: 'Kazakhstan' },+ { code: 'KE', name: 'Kenya' },+ { code: 'KI', name: 'Kiribati' },+ { code: 'KW', name: 'Kuwait' },+ { code: 'KG', name: 'Kyrgyzstan' },+ { code: 'LA', name: 'Laos' },+ { code: 'LV', name: 'Latvia' },+ { code: 'LB', name: 'Lebanon' },+ { code: 'LS', name: 'Lesotho' },+ { code: 'LR', name: 'Liberia' },+ { code: 'LY', name: 'Libya' },+ { code: 'LI', name: 'Liechtenstein' },+ { code: 'LT', name: 'Lithuania' },+ { code: 'LU', name: 'Luxembourg' },+ { code: 'MO', name: 'Macao' },+ { code: 'MG', name: 'Madagascar' },+ { code: 'MW', name: 'Malawi' },+ { code: 'MY', name: 'Malaysia' },+ { code: 'MV', name: 'Maldives' },+ { code: 'ML', name: 'Mali' },+ { code: 'MT', name: 'Malta' },+ { code: 'MH', name: 'Marshall Islands' },+ { code: 'MQ', name: 'Martinique' },+ { code: 'MR', name: 'Mauritania' },+ { code: 'MU', name: 'Mauritius' },+ { code: 'YT', name: 'Mayotte' },+ { code: 'MX', name: 'Mexico' },+ { code: 'FM', name: 'Micronesia' },+ { code: 'MD', name: 'Moldova' },+ { code: 'MC', name: 'Monaco' },+ { code: 'MN', name: 'Mongolia' },+ { code: 'ME', name: 'Montenegro' },+ { code: 'MS', name: 'Montserrat' },+ { code: 'MA', name: 'Morocco' },+ { code: 'MZ', name: 'Mozambique' },+ { code: 'MM', name: 'Myanmar' },+ { code: 'NA', name: 'Namibia' },+ { code: 'NR', name: 'Nauru' },+ { code: 'NP', name: 'Nepal' },+ { code: 'NL', name: 'Netherlands' },+ { code: 'NC', name: 'New Caledonia' },+ { code: 'NZ', name: 'New Zealand' },+ { code: 'NI', name: 'Nicaragua' },+ { code: 'NE', name: 'Niger' },+ { code: 'NG', name: 'Nigeria' },+ { code: 'NU', name: 'Niue' },+ { code: 'NF', name: 'Norfolk Island' },+ { code: 'KP', name: 'North Korea' },+ { code: 'MK', name: 'North Macedonia' },+ { code: 'MP', name: 'Northern Mariana Islands' },+ { code: 'NO', name: 'Norway' },+ { code: 'OM', name: 'Oman' },+ { code: 'PK', name: 'Pakistan' },+ { code: 'PW', name: 'Palau' },+ { code: 'PS', name: 'Palestinian Territories' },+ { code: 'PA', name: 'Panama' },+ { code: 'PG', name: 'Papua New Guinea' },+ { code: 'PY', name: 'Paraguay' },+ { code: 'PE', name: 'Peru' },+ { code: 'PH', name: 'Philippines' },+ { code: 'PN', name: 'Pitcairn Islands' },+ { code: 'PL', name: 'Poland' },+ { code: 'PT', name: 'Portugal' },+ { code: 'PR', name: 'Puerto Rico' },+ { code: 'QA', name: 'Qatar' },+ { code: 'RO', name: 'Romania' },+ { code: 'RU', name: 'Russia' },+ { code: 'RW', name: 'Rwanda' },+ { code: 'RE', name: 'Réunion' },+ { code: 'BL', name: 'Saint Barthélemy' },+ { code: 'WS', name: 'Samoa' },+ { code: 'SM', name: 'San Marino' },+ { code: 'ST', name: 'Sao Tome and Principe' },+ { code: 'SA', name: 'Saudi Arabia' },+ { code: 'SN', name: 'Senegal' },+ { code: 'RS', name: 'Serbia' },+ { code: 'SC', name: 'Seychelles' },+ { code: 'SL', name: 'Sierra Leone' },+ { code: 'SG', name: 'Singapore' },+ { code: 'SX', name: 'Sint Maarten' },+ { code: 'SK', name: 'Slovakia' },+ { code: 'SI', name: 'Slovenia' },+ { code: 'SB', name: 'Solomon Islands' },+ { code: 'SO', name: 'Somalia' },+ { code: 'ZA', name: 'South Africa' },+ { code: 'GS', name: 'South Georgia and the South Sandwich Islands' },+ { code: 'KR', name: 'South Korea' },+ { code: 'SS', name: 'South Sudan' },+ { code: 'ES', name: 'Spain' },+ { code: 'LK', name: 'Sri Lanka' },+ { code: 'SH', name: 'St Helena' },+ { code: 'KN', name: 'St Kitts and Nevis' },+ { code: 'LC', name: 'St Lucia' },+ { code: 'MF', name: 'St Martin' },+ { code: 'PM', name: 'St Pierre and Miquelon' },+ { code: 'VC', name: 'St Vincent and the Grenadines' },+ { code: 'SD', name: 'Sudan' },+ { code: 'SR', name: 'Suriname' },+ { code: 'SJ', name: 'Svalbard & Jan Mayen' },+ { code: 'SE', name: 'Sweden' },+ { code: 'CH', name: 'Switzerland' },+ { code: 'SY', name: 'Syria' },+ { code: 'TW', name: 'Taiwan' },+ { code: 'TJ', name: 'Tajikistan' },+ { code: 'TZ', name: 'Tanzania' },+ { code: 'TH', name: 'Thailand' },+ { code: 'TL', name: 'Timor-Leste' },+ { code: 'TG', name: 'Togo' },+ { code: 'TK', name: 'Tokelau' },+ { code: 'TO', name: 'Tonga' },+ { code: 'TT', name: 'Trinidad & Tobago' },+ { code: 'TN', name: 'Tunisia' },+ { code: 'TR', name: 'Turkey' },+ { code: 'TM', name: 'Turkmenistan' },+ { code: 'TC', name: 'Turks & Caicos Islands' },+ { code: 'TV', name: 'Tuvalu' },+ { code: 'VI', name: 'US Virgin Islands' },+ { code: 'UG', name: 'Uganda' },+ { code: 'UA', name: 'Ukraine' },+ { code: 'AE', name: 'United Arab Emirates' },+ { code: 'GB', name: 'United Kingdom' },+ { code: 'US', name: 'United States of America' },+ { code: 'UY', name: 'Uruguay' },+ { code: 'UZ', name: 'Uzbekistan' },+ { code: 'VU', name: 'Vanuatu' },+ { code: 'VA', name: 'Vatican City' },+ { code: 'VE', name: 'Venezuela' },+ { code: 'VN', name: 'Vietnam' },+ { code: 'WF', name: 'Wallis & Futuna' },+ { code: 'EH', name: 'Western Sahara' },+ { code: 'YE', name: 'Yemen' },+ { code: 'ZM', name: 'Zambia' },+ { code: 'ZW', name: 'Zimbabwe' },+ { code: 'AX', name: 'Åland Islands' },+]diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsxnew file mode 100644index 00000000000..421c4bb7f3b--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsx@@ -0,0 +1,180 @@+import { PermissionAction } from '@supabase/shared-types/out/constants'+import { useEffect } from 'react'++import { useParams } from 'common'+import {+ FormActions,+ FormPanel,+ FormSection,+ FormSectionContent,+ FormSectionLabel,+} from 'components/ui/Forms'+import NoPermission from 'components/ui/NoPermission'+import { useOrganizationCustomerProfileQuery } from 'data/organizations/organization-customer-profile-query'+import { useOrganizationCustomerProfileUpdateMutation } from 'data/organizations/organization-customer-profile-update-mutation'+import { useCheckPermissions, useStore } from 'hooks'+import { Form, Input, Listbox } from 'ui'+import { COUNTRIES } from './BillingAddress.constants'++const BillingAddress = () => {+ const { ui } = useStore()+ const { slug } = useParams()+ const { data, isLoading, isSuccess } = useOrganizationCustomerProfileQuery({ slug })+ const { mutateAsync: updateCustomerProfile } = useOrganizationCustomerProfileUpdateMutation()++ const formId = 'billing-address-form'+ const { city, country, line1, line2, postal_code, state } = data?.address ?? {}++ const canReadBillingAddress = useCheckPermissions(+ PermissionAction.BILLING_READ,+ 'stripe.customer'+ )+ const canUpdateBillingAddress = useCheckPermissions(+ PermissionAction.BILLING_WRITE,+ 'stripe.customer'+ )++ const initialValues = { city, country, line1, line2, postal_code, state }++ const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {+ if (!slug) return console.error('Slug is required')++ try {+ setSubmitting(true)+ await updateCustomerProfile({ slug, address: values })+ ui.setNotification({+ category: 'success',+ message: 'Successfully updated billing address',+ })+ resetForm({ values, initialValues: values })+ } catch (error: any) {+ ui.setNotification({+ category: 'error',+ message: `Failed to update billing address: ${error.message}`,+ })+ } finally {+ setSubmitting(false)+ }+ }++ return (+ <FormSection+ id="address"+ header={+ <FormSectionLabel>+ <div className="sticky top-16">+ <p className="text-base">Billing Address</p>+ <p className="text-sm text-scale-1000">This will be reflected in every invoice</p>+ </div>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={false}>+ {!canReadBillingAddress ? (+ <NoPermission resourceText="view this organization's billing address" />+ ) : (+ <Form validateOnBlur id={formId} initialValues={initialValues} onSubmit={onSubmit}>+ {({ isSubmitting, values, initialValues, handleReset, resetForm }: any) => {+ const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)++ // eslint-disable-next-line react-hooks/rules-of-hooks+ useEffect(() => {+ if (isSuccess && data !== undefined) {+ const { city, country, line1, line2, postal_code, state } = data?.address ?? {}+ const values = { city, country, line1, line2, postal_code, state }+ resetForm({ values, initialValues: values })+ }++ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [isSuccess])++ return (+ <FormPanel+ footer={+ <div className="flex py-4 px-8">+ <FormActions+ form={formId}+ isSubmitting={isSubmitting}+ hasChanges={hasChanges}+ handleReset={handleReset}+ helper={+ !canUpdateBillingAddress+ ? "You need additional permissions to manage this organization's billing address"+ : undefined+ }+ />+ </div>+ }+ >+ <FormSection>+ <FormSectionContent fullWidth loading={isLoading} className="!gap-2">+ <Input+ id="line1"+ name="line1"+ placeholder="Address line 1"+ disabled={!canUpdateBillingAddress}+ />+ <Input+ id="line2"+ name="line2"+ placeholder="Address line 2"+ disabled={!canUpdateBillingAddress}+ />+ <div className="flex items-center space-x-2">+ <Listbox+ className="w-full"+ id="country"+ name="country"+ placeholder="Country"+ disabled={!canUpdateBillingAddress}+ >+ <Listbox.Option label="---" key="empty" value="">+ ---+ </Listbox.Option>+ {COUNTRIES.map((country) => (+ <Listbox.Option+ label={country.name}+ key={country.code}+ value={country.code}+ >+ {country.name}+ </Listbox.Option>+ ))}+ </Listbox>+ <Input+ className="w-full"+ id="postal_code"+ name="postal_code"+ placeholder="Postal code"+ disabled={!canUpdateBillingAddress}+ />+ </div>+ <div className="flex items-center space-x-2">+ <Input+ className="w-full"+ id="city"+ name="city"+ placeholder="City"+ disabled={!canUpdateBillingAddress}+ />+ <Input+ className="w-full"+ id="state"+ name="state"+ placeholder="State"+ disabled={!canUpdateBillingAddress}+ />+ </div>+ </FormSectionContent>+ </FormSection>+ </FormPanel>+ )+ }}+ </Form>+ )}+ </FormSectionContent>+ </FormSection>+ )+}++export default BillingAddressdiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingEmail.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingEmail.tsxnew file mode 100644index 00000000000..64e90b8a3c5--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingEmail.tsx@@ -0,0 +1,130 @@+import { PermissionAction } from '@supabase/shared-types/out/constants'+import { useQueryClient } from '@tanstack/react-query'+import { useEffect } from 'react'++import { useParams } from 'common'+import {+ FormActions,+ FormPanel,+ FormSection,+ FormSectionContent,+ FormSectionLabel,+} from 'components/ui/Forms'+import { invalidateOrganizationsQuery } from 'data/organizations/organizations-query'+import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'+import { patch } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { Form, Input } from 'ui'++const BillingEmail = () => {+ const queryClient = useQueryClient()+ const { ui } = useStore()+ const { slug } = useParams()+ const selectedOrganization = useSelectedOrganization()+ const { name, billing_email } = selectedOrganization ?? {}++ const formId = 'org-billing-email'+ const initialValues = { billing_email: billing_email ?? '' }++ const canUpdateOrganization = useCheckPermissions(PermissionAction.UPDATE, 'organizations')+ const canReadBillingEmail = useCheckPermissions(PermissionAction.READ, 'organizations')++ const onUpdateOrganizationEmail = async (values: any, { setSubmitting, resetForm }: any) => {+ if (!canUpdateOrganization) {+ return ui.setNotification({+ category: 'error',+ message: 'You do not have the required permissions to update this organization',+ })+ }++ setSubmitting(true)+ const response = await patch(`${API_URL}/organizations/${slug}`, { ...values, name })+ if (response.error) {+ ui.setNotification({+ category: 'error',+ message: `Failed to update organization: ${response.error.message}`,+ })+ } else {+ const { billing_email } = response+ resetForm({+ values: { billing_email },+ initialValues: { billing_email },+ })++ invalidateOrganizationsQuery(queryClient)+ ui.setNotification({+ category: 'success',+ message: 'Successfully saved settings',+ })+ }+ setSubmitting(false)+ }++ return (+ <FormSection+ id="email-correspondence"+ header={+ <FormSectionLabel>+ <div className="sticky space-y-6 top-16">+ <div>+ <p className="text-base">Email Recipient</p>+ <p className="text-sm text-scale-1000">+ All billing correspondence will go to this email+ </p>+ </div>+ </div>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={false}>+ <Form id={formId} initialValues={initialValues} onSubmit={onUpdateOrganizationEmail}>+ {({ isSubmitting, handleReset, values, initialValues, resetForm }: any) => {+ const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)++ // [Alaister] although this "technically" is breaking the rules of React hooks+ // it won't error because the hooks are always rendered in the same order+ // eslint-disable-next-line react-hooks/rules-of-hooks+ useEffect(() => {+ const values = { billing_email: billing_email ?? '' }+ resetForm({ values, initialValues: values })+ }, [slug])++ return (+ <FormPanel+ footer={+ <div className="flex py-4 px-8">+ <FormActions+ form={formId}+ isSubmitting={isSubmitting}+ hasChanges={hasChanges}+ handleReset={handleReset}+ helper={+ !canUpdateOrganization+ ? "You need additional permissions to manage this organization's settings"+ : undefined+ }+ />+ </div>+ }+ >+ <FormSection>+ <FormSectionContent fullWidth loading={false}>+ <Input+ id="billing_email"+ size="small"+ label="Email address"+ type={canReadBillingEmail ? 'text' : 'password'}+ disabled={!canUpdateOrganization}+ />+ </FormSectionContent>+ </FormSection>+ </FormPanel>+ )+ }}+ </Form>+ </FormSectionContent>+ </FormSection>+ )+}++export default BillingEmaildiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsxnew file mode 100644index 00000000000..bac99d83061--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsx@@ -0,0 +1,37 @@+import BillingEmail from './BillingEmail'+import CostControl from './CostControl/CostControl'+import Subscription from './Subscription/Subscription'+import CreditBalance from './CreditBalance'+import { LayoutWrapper } from './Scaffold'+import BillingAddress from './BillingAddress/BillingAddress'+import TaxID from './TaxID/TaxID'++// [Joshen TODO] Last one: payment method details management+// Either as part of the subscription plan component like project, or its own section like the old design++const BillingSettings = () => {+ return (+ <>+ <LayoutWrapper>+ <Subscription />+ </LayoutWrapper>+ <LayoutWrapper>+ <CostControl />+ </LayoutWrapper>+ <LayoutWrapper>+ <CreditBalance />+ </LayoutWrapper>+ <LayoutWrapper>+ <BillingEmail />+ </LayoutWrapper>+ <LayoutWrapper>+ <BillingAddress />+ </LayoutWrapper>+ <LayoutWrapper>+ <TaxID />+ </LayoutWrapper>+ </>+ )+}++export default BillingSettingsdiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/CostControl/CostControl.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/CostControl/CostControl.tsxnew file mode 100644index 00000000000..90ea7c45e5f--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/CostControl/CostControl.tsx@@ -0,0 +1,140 @@+import Link from 'next/link'++import { useParams, useTheme } from 'common'+import { BASE_PATH } from 'lib/constants'+import { useSubscriptionPageStateSnapshot } from 'state/subscription-page'+import { Alert, Button, IconExternalLink } from 'ui'+// import SpendCapSidePanel from './SpendCapSidePanel'+import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'+import { useFlag } from 'hooks'+import ProjectUpdateDisabledTooltip from '../../BillingSettings/ProjectUpdateDisabledTooltip'++export interface CostControlProps {}++const CostControl = ({}: CostControlProps) => {+ const { slug } = useParams()+ const snap = useSubscriptionPageStateSnapshot()+ const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')+ const { isDarkMode } = useTheme()++ const { data: subscription, isLoading } = useOrgSubscriptionQuery({ orgSlug: slug })++ const currentPlan = subscription?.plan+ const isUsageBillingEnabled = subscription?.usage_billing_enabled ?? false++ const canChangeTier =+ !projectUpdateDisabled && !['team', 'enterprise'].includes(currentPlan?.id || '')++ return (+ <FormSection+ header={+ <FormSectionLabel>+ <div className="sticky space-y-6 top-16">+ <div>+ <p className="text-base">Cost Control</p>+ <p className="text-sm text-scale-1000">+ Control whether to use beyond your plans included quota+ </p>+ </div>+ <div className="space-y-2">+ <p className="text-sm text-scale-1100">More information</p>+ <div>+ <Link href="https://supabase.com/docs/guides/platform/spend-cap">+ <a target="_blank" rel="noreferrer">+ <div className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition">+ <p className="text-sm">Spend cap</p>+ <IconExternalLink size={16} strokeWidth={1.5} />+ </div>+ </a>+ </Link>+ </div>+ </div>+ </div>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={isLoading}>+ <div className="space-y-6">+ {['team', 'enterprise'].includes(currentPlan?.id || '') ? (+ <Alert+ withIcon+ variant="info"+ title={`You will be charged for any additional usage on the ${+ currentPlan?.name || ''+ } plan`}+ >+ {currentPlan?.name || ''} plan requires you to have spend cap off at all times. Your+ projects will never become unresponsive. Only when your{' '}+ <Link href="#breakdown">+ <a className="text-sm text-green-900 transition hover:text-green-1000">+ included usage+ </a>+ </Link>{' '}+ is exceeded will you be charged for any additional usage.+ </Alert>+ ) : (+ <p className="text-sm text-scale-1000">+ You can control whether your organization is charged for additional usage beyond the{' '}+ <Link href="#breakdown">+ <a className="text-sm text-green-900 transition hover:text-green-1000">+ included quota+ </a>+ </Link>{' '}+ of your subscription plan. If you need to go beyond the included quota, simply switch+ off your spend cap to pay for additional usage.+ </p>+ )}++ <div className="flex space-x-6">+ <div>+ <div className="rounded-md bg-scale-100 dark:bg-scale-400 w-[160px] h-[96px] shadow">+ <img+ alt="Spend Cap"+ width={160}+ height={96}+ src={+ isUsageBillingEnabled+ ? `${BASE_PATH}/img/spend-cap-off${isDarkMode ? '' : '--light'}.png?v=3`+ : `${BASE_PATH}/img/spend-cap-on${isDarkMode ? '' : '--light'}.png?v=3`+ }+ />+ </div>+ </div>+ <div>+ <p className="mb-1">Spend cap is {isUsageBillingEnabled ? 'disabled' : 'enabled'}</p>+ <p className="text-sm text-scale-1000">+ {isUsageBillingEnabled ? (+ <span>You will be charged for any usage above the included quota.</span>+ ) : (+ <span>+ You won't be charged any extra for usage. However, your projects could become+ unresponsive or enter read only mode if you exceed the included quota.+ </span>+ )}+ </p>+ {isUsageBillingEnabled && (+ <p className="text-sm text-scale-1000 mt-1">+ Your projects will never become unresponsive. Only when your usage reaches the+ quota limit will you be charged for any excess usage.+ </p>+ )}+ <ProjectUpdateDisabledTooltip projectUpdateDisabled={projectUpdateDisabled}>+ <Button+ type="default"+ className="mt-4"+ disabled={!canChangeTier}+ onClick={() => snap.setPanelKey('costControl')}+ >+ Change spend cap+ </Button>+ </ProjectUpdateDisabledTooltip>+ </div>+ </div>+ </div>+ </FormSectionContent>+ </FormSection>+ )+}++export default CostControldiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsxnew file mode 100644index 00000000000..cdcd469e729--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsx@@ -0,0 +1,48 @@+import { useParams } from 'common'+import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'+import { useOrganizationCustomerProfileQuery } from 'data/organizations/organization-customer-profile-query'+import { Badge } from 'ui'++const CreditBalance = () => {+ const { slug } = useParams()+ const { data } = useOrganizationCustomerProfileQuery({ slug })++ const customerBalance = (data?.balance ?? 0) / 100+ const isCredit = customerBalance < 0+ const isDebt = customerBalance > 0+ const balance =+ isCredit && customerBalance !== 0+ ? customerBalance.toFixed(2).toString().replace('-', '')+ : customerBalance.toFixed(2)++ return (+ <FormSection+ id="credit-balance"+ header={+ <FormSectionLabel>+ <div className="sticky top-16">+ <div className="flex items-center space-x-2">+ <p className="text-base">Credit balance</p>+ {isCredit && <Badge>You have credits available</Badge>}+ {isDebt && <Badge color="red">Outstanding payments</Badge>}+ </div>+ <p className="text-sm text-scale-1000">+ Charges will be deducted from your balance first+ </p>+ </div>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={false}>+ <div className="flex items-end space-x-1">+ {isDebt && <h4 className="opacity-50">-</h4>}+ <h4 className="opacity-50">$</h4>+ <h2 className="text-4xl relative top-[2px]">{balance}</h2>+ {isCredit && <h4 className="opacity-50">/credits</h4>}+ </div>+ </FormSectionContent>+ </FormSection>+ )+}++export default CreditBalancediff --git a/studio/components/interfaces/Organization/BillingSettingsV2/Scaffold.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/Scaffold.tsxnew file mode 100644index 00000000000..38ef45cf8f9--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/Scaffold.tsx@@ -0,0 +1,5 @@+import { PropsWithChildren } from 'react'++export const LayoutWrapper = ({ children }: PropsWithChildren<{}>) => (+ <div className="border-b last:border-0">{children}</div>+)diff --git a/studio/components/interfaces/Organization/BillingSettings/Subscription/README.md b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/README.mdsimilarity index 100%rename from studio/components/interfaces/Organization/BillingSettings/Subscription/README.mdrename to studio/components/interfaces/Organization/BillingSettingsV2/Subscription/README.mddiff --git a/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsxsimilarity index 81%rename from studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsxrename to studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsxindex c44cb8fd99f..cc39cf513b2 100644--- a/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsx@@ -3,12 +3,12 @@ import Link from 'next/link'import { useParams } from 'common'import AlertError from 'components/ui/AlertError'-import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'+import SparkBar from 'components/ui/SparkBar'import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'import { useFlag } from 'hooks'import { Alert, Button, IconExternalLink } from 'ui'-import ProjectUpdateDisabledTooltip from '../ProjectUpdateDisabledTooltip'-import SparkBar from 'components/ui/SparkBar'+import ProjectUpdateDisabledTooltip from '../../BillingSettings/ProjectUpdateDisabledTooltip'const Subscription = () => {const { slug } = useParams()@@ -32,37 +32,31 @@ const Subscription = () => {const canChangeTier =!projectUpdateDisabled && !['team', 'enterprise'].includes(currentPlan?.id ?? '')- console.log({ subscription })-return (- <div id="plan" className="grid grid-cols-12 gap-6">- <div className="col-span-12 lg:col-span-5 space-y-6">- <div className="sticky space-y-6 top-16">- <p className="text-base">Subscription plan</p>- <div className="space-y-2">- <p className="text-sm text-scale-1100">More information</p>- <div>- <Link href="https://supabase.com/pricing">- <a target="_blank" rel="noreferrer">- <div className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition">- <p className="text-sm">Pricing</p>- <IconExternalLink size={16} strokeWidth={1.5} />- </div>- </a>- </Link>+ <FormSection+ id="plan"+ header={+ <FormSectionLabel>+ <div className="sticky space-y-6 top-16">+ <p className="text-base">Subscription Plan</p>+ <div className="space-y-2">+ <p className="text-sm text-scale-1100">More information</p>+ <div>+ <Link href="https://supabase.com/pricing">+ <a target="_blank" rel="noreferrer">+ <div className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition">+ <p className="text-sm">Pricing</p>+ <IconExternalLink size={16} strokeWidth={1.5} />+ </div>+ </a>+ </Link>+ </div></div></div>- </div>- </div>- <div className="col-span-12 lg:col-span-7">- {isLoading && (- <div className="space-y-2">- <ShimmeringLoader />- <ShimmeringLoader className="w-3/4" />- <ShimmeringLoader className="w-1/2" />- </div>- )}-+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={isLoading}>{isError && <AlertError subject="Failed to retrieve subscription" error={error} />}{isSuccess && (@@ -166,8 +160,8 @@ const Subscription = () => {/></div>)}- </div>- </div>+ </FormSectionContent>+ </FormSection>)}diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.constants.ts b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.constants.tsnew file mode 100644index 00000000000..9595d935efb--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.constants.ts@@ -0,0 +1,459 @@+// List of available Tax IDs as reflected in Stripe's web portal+// This was manually ported over so there may be a chance of mistakes+// Last updated as of 29th March 2022.+// The code may not necessarily match with the name (ref SE_VAT)+// https://stripe.com/docs/api/customer_tax_ids/create+export interface TaxId {+ name: string+ code: string+ country: string+ placeholder: string+ vatPrefix?: string+}++export const TAX_IDS: TaxId[] = [+ {+ name: 'AE TRN',+ code: 'ae_trn',+ country: 'United Arab Emirates',+ placeholder: '123456789012345',+ },+ {+ name: 'AT VAT',+ code: 'eu_vat',+ country: 'Austria',+ placeholder: 'ATU12345678',+ vatPrefix: 'ATU',+ },+ {+ name: 'AU ABN',+ code: 'au_abn',+ country: 'Australia',+ placeholder: '12345678912',+ },+ {+ name: 'AU ARN',+ code: 'au_arn',+ country: 'Australia',+ placeholder: '123456789123',+ },+ {+ name: 'BE VAT',+ code: 'eu_vat',+ country: 'Belgium',+ placeholder: 'BE0123456789',+ vatPrefix: 'BE',+ },+ {+ name: 'BG VAT',+ code: 'eu_vat',+ country: 'Bulgaria',+ placeholder: 'BG0123456789',+ vatPrefix: 'BG',+ },+ {+ name: 'BR CNPJ',+ code: 'br_cnpj',+ country: 'Brazil',+ placeholder: '01.234.456/5432-10',+ },+ {+ name: 'BR CPF',+ code: 'br_cpf',+ country: 'Brazil',+ placeholder: '123.456.789-87',+ },+ {+ name: 'CA BN',+ code: 'ca_bn',+ country: 'Canada',+ placeholder: '123456789',+ },+ {+ name: 'CA GST/HST',+ code: 'ca_gst_hst',+ country: 'Canada',+ placeholder: '123456789RT0002',+ },+ {+ name: 'CA PST-BC',+ code: 'ca_pst_bc',+ country: 'Canada',+ placeholder: 'PST-1234-5678',+ },+ {+ name: 'CA PST-MB',+ code: 'ca_pst_mb',+ country: 'Canada',+ placeholder: '123456-7',+ },+ {+ name: 'CA PST-SK',+ code: 'ca_pst_mb',+ country: 'Canada',+ placeholder: '1234567',+ },+ {+ name: 'CA QST',+ code: 'ca_qst',+ country: 'Canada',+ placeholder: '1234567890TQ1234',+ },+ {+ name: 'CH VAT',+ code: 'ch_vat',+ country: 'Switzerland',+ placeholder: 'CHE-123.456.789 MWST',+ vatPrefix: 'CHE',+ },+ {+ name: 'CL TIN',+ code: 'cl_tin',+ country: 'Chile',+ placeholder: '12.345.678-K',+ },+ {+ name: 'CY VAT',+ code: 'eu_vat',+ country: 'Cyprus',+ placeholder: 'CY12345678Z',+ vatPrefix: 'CY',+ },+ {+ name: 'CZ VAT',+ code: 'eu_vat',+ country: 'Czech Republic',+ placeholder: 'CZ1234567890',+ vatPrefix: 'CZ',+ },+ {+ name: 'DE VAT',+ code: 'eu_vat',+ country: 'Germany',+ placeholder: 'DE123456789',+ vatPrefix: 'DE',+ },+ {+ name: 'DK VAT',+ code: 'eu_vat',+ country: 'Denmark',+ placeholder: 'DK12345678',+ vatPrefix: 'DK',+ },+ {+ name: 'EE VAT',+ code: 'eu_vat',+ country: 'Estonia',+ placeholder: 'EE123456789',+ vatPrefix: 'EE',+ },+ {+ name: 'ES CIF',+ code: 'es_cif',+ country: 'Spain',+ placeholder: 'A12345678',+ },+ {+ name: 'ES VAT',+ code: 'eu_vat',+ country: 'Spain',+ placeholder: 'ESX1234567Z',+ vatPrefix: 'ES',+ },+ {+ name: 'FI VAT',+ code: 'eu_vat',+ country: 'Finland',+ placeholder: 'FI12345678',+ vatPrefix: 'FI',+ },+ {+ name: 'FR VAT',+ code: 'eu_vat',+ country: 'France',+ placeholder: 'FRAB123456789',+ vatPrefix: 'FR',+ },+ {+ name: 'GB VAT',+ code: 'eu_vat',+ country: 'United Kingdom',+ placeholder: 'GB123456789',+ vatPrefix: 'GB',+ },+ {+ name: 'GE VAT',+ code: 'ge_vat',+ country: 'Georgia',+ placeholder: '123456789',+ },+ {+ name: 'EL VAT',+ code: 'eu_vat',+ country: 'Greece',+ placeholder: 'EL123456789',+ vatPrefix: 'EL',+ },+ {+ name: 'HK BR',+ code: 'hk_br',+ country: 'Hong Kong SAR China',+ placeholder: '12345678',+ },+ {+ name: 'HR VAT',+ code: 'eu_vat',+ country: 'Croatia',+ placeholder: 'HR12345678912',+ vatPrefix: 'HR',+ },+ {+ name: 'HU VAT',+ code: 'eu_vat',+ country: 'Hungary',+ placeholder: 'HU12345678912',+ vatPrefix: 'HU',+ },+ {+ name: 'ID NPWP',+ code: 'id_npwp',+ country: 'Indonesia',+ placeholder: '12.345.678.9-012.345',+ },+ {+ name: 'IE VAT',+ code: 'eu_vat',+ country: 'Ireland',+ placeholder: 'IE1234567AB',+ vatPrefix: 'IE',+ },+ {+ name: 'IL VAT',+ code: 'il_vat',+ country: 'Israel',+ placeholder: '000012345',+ },+ {+ name: 'IN GST',+ code: 'in_gst',+ country: 'India',+ placeholder: '12ABCDE3456FGZH',+ },+ {+ name: 'IS VAT',+ code: 'is_vat',+ country: 'Iceland',+ placeholder: '123456',+ },+ {+ name: 'IT VAT',+ code: 'eu_vat',+ country: 'Italy',+ placeholder: 'IT12345678912',+ vatPrefix: 'IT',+ },+ {+ name: 'JP CN',+ code: 'jp_cn',+ country: 'Japan',+ placeholder: '1234567891234',+ },+ {+ name: 'JP RN',+ code: 'jp_rn',+ country: 'Japan',+ placeholder: '12345',+ },+ {+ name: 'KR BRN',+ code: 'kr_brn',+ country: 'Korea',+ placeholder: '123-45-67890',+ },+ {+ name: 'LI UID',+ code: 'li_uid',+ country: 'Liechtenstein',+ placeholder: 'CHE123456789',+ },+ {+ name: 'LT VAT',+ code: 'eu_vat',+ country: 'Lithuania',+ placeholder: 'LT123456789123',+ vatPrefix: 'LT',+ },+ {+ name: 'LU VAT',+ code: 'eu_vat',+ country: 'Luxembourg',+ placeholder: 'LU12345678',+ vatPrefix: 'LU',+ },+ {+ name: 'LV VAT',+ code: 'eu_vat',+ country: 'Latvia',+ placeholder: 'LV12345678912',+ vatPrefix: 'LV',+ },+ {+ name: 'MT VAT',+ code: 'eu_vat',+ country: 'Malta',+ placeholder: 'MT12345678',+ vatPrefix: 'MT',+ },+ {+ name: 'MX RFC',+ code: 'mx_rfc',+ country: 'Mexico',+ placeholder: 'ABC010203AB9',+ },+ {+ name: 'MY FRP',+ code: 'my_frp',+ country: 'Malaysia',+ placeholder: '12345678',+ },+ {+ name: 'MY ITN',+ code: 'my_itn',+ country: 'Malaysia',+ placeholder: 'C 1234567890',+ },+ {+ name: 'MY SST',+ code: 'my_sst',+ country: 'Malaysia',+ placeholder: 'A12-3456-78912345',+ },+ {+ name: 'NL VAT',+ code: 'eu_vat',+ country: 'Netherlands',+ placeholder: 'NL123456789B12',+ vatPrefix: 'NL',+ },+ {+ name: 'NO VAT',+ code: 'no_vat',+ country: 'Norway',+ placeholder: '123456789MVA',+ },+ {+ name: 'NZ GST',+ code: 'nz_gst',+ country: 'New Zealand',+ placeholder: '123456789',+ },+ {+ name: 'PL VAT',+ code: 'eu_vat',+ country: 'Poland',+ placeholder: 'PL1234567890',+ vatPrefix: 'PL',+ },+ {+ name: 'PT VAT',+ code: 'eu_vat',+ country: 'Portugal',+ placeholder: 'PT123456789',+ vatPrefix: 'PT',+ },+ {+ name: 'RO VAT',+ code: 'eu_vat',+ country: 'Romania',+ placeholder: 'RO1234567891',+ vatPrefix: 'RO',+ },+ {+ name: 'RU INN',+ code: 'ru_inn',+ country: 'Russia',+ placeholder: '1234567891',+ },+ {+ name: 'RU KPP',+ code: 'ru_kpp',+ country: 'Russia',+ placeholder: '123456789',+ },+ {+ name: 'SA VAT',+ code: 'sa_vat',+ country: 'Saudi Arabia',+ placeholder: '123456789012345',+ },+ {+ name: 'SE VAT',+ code: 'eu_vat',+ country: 'Sweden',+ placeholder: 'SE123456789123',+ vatPrefix: 'SE',+ },+ {+ name: 'SG GST',+ code: 'sg_gst',+ country: 'Singapore',+ placeholder: 'M12345678X',+ },+ {+ name: 'SG UEN',+ code: 'sg_uen',+ country: 'Singapore',+ placeholder: '123456789F',+ },+ {+ name: 'SI VAT',+ code: 'eu_vat',+ country: 'Slovenia',+ placeholder: 'SI12345678',+ vatPrefix: 'SI',+ },+ {+ name: 'SK VAT',+ code: 'eu_vat',+ country: 'Slovakia',+ placeholder: 'SK1234567891',+ vatPrefix: 'SK',+ },+ {+ name: 'TH VAT',+ code: 'th_vat',+ country: 'Thailand',+ placeholder: '1234567891234',+ },+ {+ name: 'TW VAT',+ code: 'tw_vat',+ country: 'Taiwan',+ placeholder: '12345678',+ },+ {+ name: 'UA VAT',+ code: 'ua_vat',+ country: 'Ukraine',+ placeholder: '123456789',+ },+ {+ name: 'US EIN',+ code: 'us_ein',+ country: 'United States',+ placeholder: '12-3456789',+ },+ {+ name: 'XI VAT',+ code: 'eu_vat',+ country: 'United Kingdom (Northern Ireland)',+ placeholder: 'XI123456789',+ vatPrefix: 'XI',+ },+ {+ name: 'ZA VAT',+ code: 'za_vat',+ country: 'South Africa',+ placeholder: '4123456789',+ },+]diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsxnew file mode 100644index 00000000000..28b3957a9fc--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsx@@ -0,0 +1,233 @@+import { useEffect, useState } from 'react'+import { PermissionAction } from '@supabase/shared-types/out/constants'++import {+ FormActions,+ FormPanel,+ FormSection,+ FormSectionContent,+ FormSectionLabel,+} from 'components/ui/Forms'+import NoPermission from 'components/ui/NoPermission'+import { useCheckPermissions, useStore } from 'hooks'+import { Button, Form, IconPlus, IconX, Input, Listbox } from 'ui'+import { TAX_IDS } from './TaxID.constants'+import { TaxId, useOrganizationTaxIDsQuery } from 'data/organizations/organization-tax-ids-query'+import { useParams } from 'common'+import { uuidv4 } from 'lib/helpers'+import { isEqual } from 'lodash'+import {+ TaxIdValue,+ useOrganizationTaxIDsUpdateMutation,+} from 'data/organizations/organization-tax-ids-update-mutation'+import { sanitizeTaxID } from './TaxID.utilts'++const TaxID = () => {+ const { ui } = useStore()+ const { slug } = useParams()+ const { data: taxIds, isLoading, isSuccess, isError } = useOrganizationTaxIDsQuery({ slug })+ const { mutateAsync: updateTaxIDs } = useOrganizationTaxIDsUpdateMutation()++ const [errors, setErrors] = useState<string[]>([])+ const [taxIdValues, setTaxIdValues] = useState<TaxIdValue[]>([])++ const formattedTaxIds =+ taxIds?.map((taxId: TaxId) => {+ return {+ id: taxId.id,+ type: taxId.type,+ value: taxId.value,+ name:+ taxId.type === 'eu_vat'+ ? `${taxId.country} VAT`+ : TAX_IDS.find((option) => option.code === taxId.type)?.name ?? '',+ }+ }) ?? []++ const formId = 'tax-id-form'+ const hasChanges = !isEqual(taxIdValues, formattedTaxIds)+ const canReadTaxIds = useCheckPermissions(PermissionAction.BILLING_READ, 'stripe.tax_ids')+ const canUpdateTaxIds = 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))+ }+ }+ // 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+ })+ 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 onRemoveTaxId = (id: string) => {+ const updatedTaxIds = taxIdValues.filter((taxId) => taxId.id !== id)+ setTaxIdValues(updatedTaxIds)+ }++ const onResetTaxIds = () => {+ setTaxIdValues(formattedTaxIds)+ }++ const onSaveTaxIds = async (values: any, { setSubmitting }: any) => {+ if (!slug) return console.error('Slug is required')+ if (taxIds === undefined) return console.error('Tax IDs are required')++ try {+ setSubmitting(true)+ const newIds = taxIdValues.map((x) => sanitizeTaxID(x))+ const { errors } = await updateTaxIDs({ slug, existingIds: taxIds, newIds })+ setErrors(errors?.map((taxId) => taxId.id) ?? [])++ if (errors !== undefined && errors.length > 0) {+ errors.forEach((taxId: any) => {+ ui.setNotification({ category: 'error', message: taxId.result.error.message })+ })+ } else {+ ui.setNotification({ category: 'success', message: 'Successfully updated tax IDs' })+ }+ } catch (error: any) {+ ui.setNotification({ category: 'error', message: `Failed to save tax IDs: ${error.message}` })+ } finally {+ setSubmitting(false)+ }+ }++ return (+ <FormSection+ id="tax-id"+ header={+ <FormSectionLabel>+ <div className="sticky space-y-6 top-16">+ <div>+ <p className="text-base">Tax ID</p>+ <p className="text-sm text-scale-1000">+ If you would like to include specific tax ID(s) to your invoices.+ </p>+ <p className="text-sm text-scale-1000">+ Make sure the tax ID looks exactly like the placeholder text.+ </p>+ </div>+ </div>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={false}>+ {!canReadTaxIds ? (+ <NoPermission resourceText="view this organization's tax IDs" />+ ) : (+ <Form validateOnBlur id={formId} initialValues={{}} onSubmit={onSaveTaxIds}>+ {({ isSubmitting }: { isSubmitting: boolean }) => (+ <FormPanel+ footer={+ <div className="flex py-4 px-8">+ <FormActions+ form={formId}+ isSubmitting={isSubmitting}+ hasChanges={hasChanges}+ handleReset={() => onResetTaxIds()}+ helper={+ !canUpdateTaxIds+ ? "You need additional permissions to manage this organization's tax IDs"+ : undefined+ }+ />+ </div>+ }+ >+ <FormSection>+ <FormSectionContent fullWidth loading={isLoading}>+ {taxIdValues.length >= 1 ? (+ <div className="w-full space-y-2">+ {taxIdValues.map((taxId, idx: number) => {+ const selectedTaxId = TAX_IDS.find((option) => option.code === taxId.type)+ 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)}+ />+ )}+ </div>+ )+ })}+ </div>+ ) : (+ <div>+ <p className="flex items-center space-x-2 text-sm text-scale-900">+ 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>+ )}+ </FormSectionContent>+ </FormSection>+ )+}++export default TaxIDdiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.utilts.ts b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.utilts.tsnew file mode 100644index 00000000000..e44856a58be--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.utilts.ts@@ -0,0 +1,24 @@+import { TaxId } from 'data/organizations/organization-tax-ids-query'+import { TAX_IDS } from './TaxID.constants'+import { TaxIdValue } from 'data/organizations/organization-tax-ids-update-mutation'++/**+ * Sanitize EU VAT ids so they get prepended with the country code+ *+ * Ex: Belgium's VAT ID should be BE0123456789 not 0123456789+ * Only EU VAT ids are affected+ */+export const sanitizeTaxID = (taxId: TaxIdValue) => {+ let newID = taxId++ const selectedTaxId = TAX_IDS.find((option) => option.code === taxId.type)++ const vatIdPrefix = selectedTaxId?.vatPrefix++ // if the value doesn't start with the prefix, prepend them+ if (vatIdPrefix && !taxId.value.startsWith(vatIdPrefix)) {+ newID.value = `${vatIdPrefix}${taxId.value}`+ }++ return newID+}diff --git a/studio/components/interfaces/Organization/index.ts b/studio/components/interfaces/Organization/index.tsindex c041402fdf2..2f0f370861b 100644--- a/studio/components/interfaces/Organization/index.ts+++ b/studio/components/interfaces/Organization/index.ts@@ -1,12 +1,13 @@import GeneralSettings from './GeneralSettings/GeneralSettings'import TeamSettings from './TeamSettings/TeamSettings'import BillingSettings from './BillingSettings/BillingSettings'-import BillingSettingsV2 from './BillingSettings/BillingSettingsV2'import InvoicesSettings from './InvoicesSettings/InvoicesSettings'import NewOrgForm from './NewOrg/NewOrgForm'import Usage from './Usage/Usage'import OAuthApps from './OAuthApps/OAuthApps'+import BillingSettingsV2 from './BillingSettingsV2/BillingSettings'+export {GeneralSettings,TeamSettings,diff --git a/studio/components/ui/Forms/FormSection.tsx b/studio/components/ui/Forms/FormSection.tsxindex a94b81d44d4..5baa7ca7f56 100644--- a/studio/components/ui/Forms/FormSection.tsx+++ b/studio/components/ui/Forms/FormSection.tsx@@ -2,12 +2,14 @@ import { Children } from 'react'const FormSection = ({children,+ id,header,disabled,visible = true,className,}: {children: React.ReactNode+ id?: stringheader?: React.ReactNodedisabled?: booleanvisible?: boolean@@ -21,7 +23,7 @@ const FormSection = ({]return (- <div className={classes.join(' ')}>+ <div id={id} className={classes.join(' ')}>{header}{children}</div>diff --git a/studio/data/organizations/keys.ts b/studio/data/organizations/keys.tsindex a7b2d230164..ecac86e4ae7 100644--- a/studio/data/organizations/keys.ts+++ b/studio/data/organizations/keys.ts@@ -10,4 +10,5 @@ export const organizationKeys = {migrateBilling: (slug: string | undefined) => ['organizations', slug, 'migrate-billing'] as const,migrateBillingPreview: (slug: string | undefined) =>['organizations', slug, 'migrate-billing', 'preview'] as const,+ taxIds: (slug: string | undefined) => ['organizations', slug, 'tax-ids'] as const,}diff --git a/studio/data/organizations/organization-customer-profile-query.ts b/studio/data/organizations/organization-customer-profile-query.tsindex 31c6e4d55b3..de495773339 100644--- a/studio/data/organizations/organization-customer-profile-query.ts+++ b/studio/data/organizations/organization-customer-profile-query.ts@@ -9,7 +9,14 @@ export type OrganizationCustomerProfileVariables = {}export type OrganizationCustomerProfileResponse = {- address: string | null+ address: {+ city: string | null+ country: string | null+ line1: string | null+ line2: string | null+ postal_code: string | null+ state: string | null+ } | nullbalance: numberemail: stringid: stringdiff --git a/studio/data/organizations/organization-customer-profile-update-mutation.ts b/studio/data/organizations/organization-customer-profile-update-mutation.tsnew file mode 100644index 00000000000..f038e76ab45--- /dev/null+++ b/studio/data/organizations/organization-customer-profile-update-mutation.ts@@ -0,0 +1,58 @@+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'+import { patch } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { organizationKeys } from './keys'++export type OrganizationCustomerProfileUpdateVariables = {+ slug: string+ address?: {+ city: string | null+ country: string | null+ line1: string | null+ line2: string | null+ postal_code: string | null+ state: string | null+ } | null+}++export async function updateOrganizationCustomerProfile({+ slug,+ address,+}: OrganizationCustomerProfileUpdateVariables) {+ if (!slug) return console.error('Slug is required')++ const response = await patch(`${API_URL}/organizations/${slug}/customer`, { address })+ if (response.error) throw response.error+ return response+}++type OrganizationCustomerProfileUpdateData = Awaited<+ ReturnType<typeof updateOrganizationCustomerProfile>+>++export const useOrganizationCustomerProfileUpdateMutation = ({+ onSuccess,+ ...options+}: Omit<+ UseMutationOptions<+ OrganizationCustomerProfileUpdateData,+ unknown,+ OrganizationCustomerProfileUpdateVariables+ >,+ 'mutationFn'+> = {}) => {+ const queryClient = useQueryClient()++ return useMutation<+ OrganizationCustomerProfileUpdateData,+ unknown,+ OrganizationCustomerProfileUpdateVariables+ >((vars) => updateOrganizationCustomerProfile(vars), {+ async onSuccess(data, variables, context) {+ const { slug } = variables+ await queryClient.invalidateQueries(organizationKeys.customerProfile(slug))+ await onSuccess?.(data, variables, context)+ },+ ...options,+ })+}diff --git a/studio/data/organizations/organization-tax-ids-query.ts b/studio/data/organizations/organization-tax-ids-query.tsnew file mode 100644index 00000000000..059840795fd--- /dev/null+++ b/studio/data/organizations/organization-tax-ids-query.ts@@ -0,0 +1,68 @@+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'++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 = unknown++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,+ }+ )++export const useOrganizationTaxIDsPrefetch = ({ slug }: OrganizationTaxIDsVariables) => {+ const client = useQueryClient()++ return useCallback(() => {+ if (slug) {+ client.prefetchQuery(organizationKeys.taxIds(slug), ({ signal }) =>+ getOrganizationTaxIDs({ slug }, signal)+ )+ }+ }, [slug])+}diff --git a/studio/data/organizations/organization-tax-ids-update-mutation.ts b/studio/data/organizations/organization-tax-ids-update-mutation.tsnew file mode 100644index 00000000000..36ea34fd23d--- /dev/null+++ b/studio/data/organizations/organization-tax-ids-update-mutation.ts@@ -0,0 +1,82 @@+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'+import { delete_, post } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { organizationKeys } from './keys'+import { 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,+ ...options+}: Omit<+ UseMutationOptions<OrganizationTaxIDsUpdateData, unknown, OrganizationTaxIDsUpdateVariables>,+ 'mutationFn'+> = {}) => {+ const queryClient = useQueryClient()++ return useMutation<OrganizationTaxIDsUpdateData, unknown, OrganizationTaxIDsUpdateVariables>(+ (vars) => updateOrganizationTaxIDs(vars),+ {+ async onSuccess(data, variables, context) {+ const { slug } = variables+ await queryClient.invalidateQueries(organizationKeys.customerProfile(slug))+ await onSuccess?.(data, variables, context)+ },+ ...options,+ }+ )+}