The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Bring changes in from master and resolve conflicts
Joshen Lima33846be4836
diff --cc studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsxindex 4a873cf5cac,114ca9c2dd0..a75637f2b43--- a/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/BillingAddress/BillingAddress.tsx@@@ -4,30 -3,44 +4,47 @@@ import { isEqual } from 'lodashimport { useState } from 'react'import { Button, Form, Input, Listbox } from 'ui'+import AlertError from 'components/ui/AlertError'import NoPermission from 'components/ui/NoPermission'import Panel from 'components/ui/Panel'+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'+import { useOrganizationCustomerProfileQuery } from 'data/organizations/organization-customer-profile-query'+ import { useOrganizationCustomerProfileUpdateMutation } from 'data/organizations/organization-customer-profile-update-mutation'-import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'+import { useCheckPermissions, useStore } from 'hooks'- import { patch } from 'lib/common/fetch'- import { API_URL } from 'lib/constants'import { COUNTRIES } from './BillingAddress.constants'-export interface BillingAddressProps {- loading: boolean- address: { [key: string]: any }- onAddressUpdated: (address: any) => void-}--const BillingAddress = ({ loading, address, onAddressUpdated }: BillingAddressProps) => {+const BillingAddress = () => {const { ui } = useStore()- const [isDirty, setIsDirty] = useState(false)- const selectedOrganization = useSelectedOrganization()+ const { slug } = useParams()++ const {+ data: customer,+ error: customerError,- refetch: refetchCustomer,+ isError: isErrorCustomer,+ isLoading: isLoadingCustomer,+ isSuccess: isSuccessCustomer,+ } = useOrganizationCustomerProfileQuery({ slug })- const orgSlug = selectedOrganization?.slug ?? ''- const { city, country, line1, line2, postal_code, state } = address+ const { city, country, line1, line2, postal_code, state } = customer?.address ?? {}++ const [isDirty, setIsDirty] = useState(false)+ const initialValues = { city, country, line1, line2, postal_code, state }++ const { mutate: updateCustomer, isLoading: isUpdating } =+ useOrganizationCustomerProfileUpdateMutation({- onSuccess: (updatedCustomer) => {++ onSuccess: () => {+ ui.setNotification({+ category: 'success',+ message: 'Successfully updated billing address',+ })+ setIsDirty(false)- onAddressUpdated(updatedCustomer.address)+ },+ onError: (error) => {+ ui.setNotification({+ category: 'error',+ message: `Failed to update billing address: ${error.message}`,+ })+ },+ })const canReadBillingAddress = useCheckPermissions(PermissionAction.BILLING_READ,@@@ -58,27 -61,8 +65,9 @@@return errors}- const onSubmit = async (values: any, { setSubmitting }: any) => {- try {- setSubmitting(true)- const updatedCustomer = await patch(`${API_URL}/organizations/${slug}/customer`, {- address: values,- })- if (updatedCustomer.error) throw updatedCustomer.error- ui.setNotification({- category: 'success',- message: 'Successfully updated billing address',- })- refetchCustomer()- } catch (error: any) {- ui.setNotification({- category: 'error',- message: `Failed to update billing address: ${error.message}`,- })- } finally {- setSubmitting(false)- setIsDirty(false)- }+ const onSubmit = async (values: any) => {- updateCustomer({ slug: orgSlug, address: values })++ if (!slug) return console.error('Slug is required')++ updateCustomer({ slug, address: values })}return (@@@ -87,125 -71,122 +76,125 @@@<h4>Billing address</h4><p className="text-sm opacity-50">This will be reflected in every invoice</p></div>- <Panel loading={loading}>- {loading ? (- <div className="flex flex-col justify-between space-y-2 py-4 px-4">- <div className="shimmering-loader mx-1 w-2/3 rounded py-3" />- <div className="shimmering-loader mx-1 w-1/2 rounded py-3" />- <div className="shimmering-loader mx-1 w-1/3 rounded py-3" />- </div>- ) : !canReadBillingAddress ? (- <NoPermission resourceText="view this organization's billing address" />- ) : (- <Form- validateOnBlur- initialValues={initialValues}- validate={onValidate}- onSubmit={onSubmit}- >- {({ handleReset }: any) => {- return (- <>- <Panel.Content className="w-3/5 space-y-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">++ {isLoadingCustomer && <GenericSkeletonLoader />}++ {isErrorCustomer && (+ <AlertError error={customerError} subject="Failed to retrieve customer profile" />+ )}++ {isSuccessCustomer && (+ <Panel>+ {!canReadBillingAddress ? (+ <NoPermission resourceText="view this organization's billing address" />+ ) : (+ <Form+ validateOnBlur+ initialValues={initialValues}+ validate={onValidate}+ onSubmit={onSubmit}+ >- {({ isSubmitting, handleReset }: any) => {++ {({ handleReset }: any) => {+ return (+ <>+ <Panel.Content className="w-3/5 space-y-2"><Input- className="w-full"- id="city"- name="city"- placeholder="City"+ id="line1"+ name="line1"+ placeholder="Address line 1"disabled={!canUpdateBillingAddress}/><Input- className="w-full"- id="state"- name="state"- placeholder="State"+ id="line2"+ name="line2"+ placeholder="Address line 2"disabled={!canUpdateBillingAddress}/>- </div>- </Panel.Content>- <div className="border-t border-scale-400" />- <Panel.Content className="flex justify-between">- {!canUpdateBillingAddress ? (- <p className="text-sm text-scale-1000">- You need additional permissions to update this organization's billing- address- </p>- ) : (- <div />- )}- <div className="flex items-center space-x-2">- <Button- type="default"- htmlType="reset"- disabled={!isDirty || isUpdating || !canUpdateBillingAddress}- onClick={() => {- handleReset()- setIsDirty(false)- }}- >- Cancel- </Button>- <Button- type="primary"- htmlType="submit"- loading={isUpdating}- disabled={!isDirty || isUpdating || !canUpdateBillingAddress}- >- Save- </Button>- </div>- </Panel.Content>- </>- )- }}- </Form>- )}- </Panel>+ <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>+ </Panel.Content>+ <div className="border-t border-scale-400" />+ <Panel.Content className="flex justify-between">+ {!canUpdateBillingAddress ? (+ <p className="text-sm text-scale-1000">+ You need additional permissions to update this organization's billing+ address+ </p>+ ) : (+ <div />+ )}+ <div className="flex items-center space-x-2">+ <Button+ type="default"+ htmlType="reset"- disabled={!isDirty || isSubmitting || !canUpdateBillingAddress}++ disabled={!isDirty || isUpdating || !canUpdateBillingAddress}+ onClick={() => {+ handleReset()+ setIsDirty(false)+ }}+ >+ Cancel+ </Button>+ <Button+ type="primary"+ htmlType="submit"- loading={isSubmitting}- disabled={!isDirty || isSubmitting || !canUpdateBillingAddress}++ loading={isUpdating}++ disabled={!isDirty || isUpdating || !canUpdateBillingAddress}+ >+ Save+ </Button>+ </div>+ </Panel.Content>+ </>+ )+ }}+ </Form>+ )}+ </Panel>+ )}</div>)}diff --cc studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsxindex 8e14d072751,8e14d072751..840a21f8e60--- a/studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/BillingEmail.tsx@@@ -10,11 -10,11 +10,12 @@@ import { isResponseOk, patch } from 'liimport { API_URL } from 'lib/constants'import { Form, Input } from 'ui'import { Organization } from 'types'++import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'const BillingEmail = () => {-- const queryClient = useQueryClient()const { ui } = useStore()const { slug } = useParams()++ const queryClient = useQueryClient()const selectedOrganization = useSelectedOrganization()const { name, billing_email } = selectedOrganization ?? {}@@@ -66,52 -66,52 +67,56 @@@<p className="text-sm opacity-50">All billing correspondence will go to this email</p><div className="mt-3">-- <Form id={formId} initialValues={initialValues} onSubmit={onUpdateOrganization}>-- {({ isSubmitting, handleReset, values, initialValues, resetForm }: any) => {-- const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)++ {selectedOrganization === undefined ? (++ <GenericSkeletonLoader />++ ) : (++ <Form id={formId} initialValues={initialValues} onSubmit={onUpdateOrganization}>++ {({ 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 })-- // eslint-disable-next-line react-hooks/exhaustive-deps-- }, [slug])++ // [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 })++ // eslint-disable-next-line react-hooks/exhaustive-deps++ }, [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 className="-mx-2">-- <FormSectionContent loading={false}>-- <Input-- id="billing_email"-- size="small"-- label="Email address"-- type={canReadBillingEmail ? 'text' : 'password'}-- disabled={!canUpdateOrganization}-- />-- </FormSectionContent>-- </FormSection>-- </FormPanel>-- )-- }}-- </Form>++ 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 className="-mx-2">++ <FormSectionContent loading={false}>++ <Input++ id="billing_email"++ size="small"++ label="Email address"++ type={canReadBillingEmail ? 'text' : 'password'}++ disabled={!canUpdateOrganization}++ />++ </FormSectionContent>++ </FormSection>++ </FormPanel>++ )++ }}++ </Form>++ )}</div></div>)diff --cc studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsxindex 6b208ea9264,666ecb682b3..4df99f1b341--- a/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/PaymentMethods.tsx@@@ -16,40 -15,66 +16,65 @@@ import} from 'ui'import { AddNewPaymentMethodModal } from 'components/interfaces/BillingV2'++import AlertError from 'components/ui/AlertError'import NoPermission from 'components/ui/NoPermission'import Panel from 'components/ui/Panel'++import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'+import { useOrganizationCustomerProfileQuery } from 'data/organizations/organization-customer-profile-query'+ import { useOrganizationCustomerProfileUpdateMutation } from 'data/organizations/organization-customer-profile-update-mutation'+ import { useOrganizationPaymentMethodDeleteMutation } from 'data/organizations/organization-payment-method-delete-mutation'-import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'+import { useOrganizationPaymentMethodsQuery } from 'data/organizations/organization-payment-methods-query'+import { useCheckPermissions, useStore } from 'hooks'- import { delete_, patch } from 'lib/common/fetch'- import { API_URL, BASE_PATH } from 'lib/constants'+ import { BASE_PATH } from 'lib/constants'import { getURL } from 'lib/helpers'- import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'- import AlertError from 'components/ui/AlertError'-export interface PaymentMethodsProps {- loading: boolean- defaultPaymentMethod: string- paymentMethods: any[]- onDefaultMethodUpdated: (updatedCustomer: any) => void- onPaymentMethodsDeleted: () => void- onPaymentMethodAdded: () => void-}--const PaymentMethods = ({- loading,- defaultPaymentMethod,- paymentMethods,- onDefaultMethodUpdated,- onPaymentMethodsDeleted,- onPaymentMethodAdded,-}: PaymentMethodsProps) => {+const PaymentMethods = () => {const { ui } = useStore()- const selectedOrganization = useSelectedOrganization()- const orgSlug = selectedOrganization?.slug ?? ''+ const { slug } = useParams()const [selectedMethodForDefault, setSelectedMethodForDefault] = useState<any>()const [selectedMethodToDelete, setSelectedMethodToDelete] = useState<any>()const [showAddPaymentMethodModal, setShowAddPaymentMethodModal] = useState(false)- const [isUpdatingPaymentMethod, setIsUpdatingPaymentMethod] = useState(false)- const { data: customer, refetch: refetchCustomer } = useOrganizationCustomerProfileQuery({ slug })+ const { mutate: updateCustomerProfile, isLoading: isUpdating } =+ useOrganizationCustomerProfileUpdateMutation({+ onSuccess: (updatedCustomer) => {- onDefaultMethodUpdated(updatedCustomer)+ setSelectedMethodForDefault(undefined)+ ui.setNotification({+ category: 'success',+ message: 'Successfully updated default payment method',+ })+ },+ onError: (error) => {+ ui.setNotification({+ category: 'error',+ message: `Failed to make payment method default: ${error.message}`,+ })+ },+ })++ const { mutate: deletePaymentMethod, isLoading: isDeleting } =+ useOrganizationPaymentMethodDeleteMutation({+ onSuccess: () => {- onPaymentMethodsDeleted()+ setSelectedMethodToDelete(undefined)+ ui.setNotification({ category: 'success', message: 'Successfully deleted payment method' })+ },+ })+++ const { data: customer } = useOrganizationCustomerProfileQuery({ slug })++ const {+ data,+ error: paymentMethodsError,+ refetch: refetchPaymentMethods,+ isLoading: isLoadingPaymentMethods,+ isError: isErrorPaymentMethods,+ isSuccess: isSuccessPaymentMethods,+ } = useOrganizationPaymentMethodsQuery({ slug })+ const paymentMethods = data || []++ const defaultPaymentMethod = customer?.invoice_settings?.default_payment_method ?? ''+const canReadPaymentMethods = useCheckPermissions(PermissionAction.BILLING_READ,'stripe.payment_methods'@@@ -59,54 -84,22 +84,25 @@@'stripe.payment_methods')-- const onConfirmMakeDefaultPaymentMethod = async () => {- try {- setIsUpdatingPaymentMethod(true)- const updatedCustomer = await patch(`${API_URL}/organizations/${slug}/customer`, {- invoice_settings: {- default_payment_method: selectedMethodForDefault.id,- },- })- if (updatedCustomer.error) throw updatedCustomer.error- refetchCustomer(updatedCustomer)- setSelectedMethodForDefault(undefined)- ui.setNotification({- category: 'success',- message: 'Successfully updated default payment method',- })- } catch (error: any) {- ui.setNotification({- category: 'error',- message: `Failed to make payment method default: ${error.message}`,- })- } finally {- setIsUpdatingPaymentMethod(false)- }++ const onConfirmMakeDefaultPaymentMethod = () => {++ if (!slug) return console.error('Slug is required')+ updateCustomerProfile({- slug: orgSlug,++ slug,+ invoice_settings: {+ default_payment_method: selectedMethodForDefault.id,+ },+ })}-- const onConfirmDetachPaymentMethod = async () => {- try {- setIsUpdatingPaymentMethod(true)- const { error } = await delete_(`${API_URL}/organizations/${slug}/payments`, {- card_id: selectedMethodToDelete.id,- })- if (error) throw error- refetchPaymentMethods()- setSelectedMethodToDelete(undefined)- ui.setNotification({ category: 'success', message: 'Successfully deleted payment method' })- } catch (error: any) {- ui.setNotification({- category: 'error',- message: `Failed to delete payment method: ${error.message}`,- })- } finally {- setIsUpdatingPaymentMethod(false)- }- deletePaymentMethod({ slug: orgSlug, cardId: selectedMethodToDelete.id })++ const onConfirmDetachPaymentMethod = () => {++ if (!slug) return console.error('Slug is required')++ deletePaymentMethod({ slug, cardId: selectedMethodToDelete.id })}const onLocalPaymentMethodAdded = () => {setShowAddPaymentMethodModal(false)- return onPaymentMethodAdded()++ ui.setNotification({ category: 'success', message: 'Successfully added new payment method' })+ return refetchPaymentMethods()}return (diff --cc studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsxindex 51d778ec8fd,ea707e420a1..29ab3fd3c94--- a/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx+++ b/studio/components/interfaces/Organization/BillingSettings/TaxID/TaxID.tsx@@@ -8,11 -8,12 +8,12 @@@ import AlertError from 'components/ui/Aimport NoPermission from 'components/ui/NoPermission'import Panel from 'components/ui/Panel'import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'-import { TaxId, useOrganizationTaxIDsQuery } from 'data/organizations/organization-tax-ids-query'+import { useOrganizationTaxIDsQuery } from 'data/organizations/organization-tax-ids-query'- import { TaxIdValue } from 'data/organizations/organization-tax-ids-update-mutation'+ import {+ TaxIdValue,+ useOrganizationTaxIDsUpdateMutation,+ } from 'data/organizations/organization-tax-ids-update-mutation'import { useCheckPermissions, useStore } from 'hooks'- import { delete_, post } from 'lib/common/fetch'- import { API_URL } from 'lib/constants'import { uuidv4 } from 'lib/helpers'import { StripeTaxId, TAX_IDS } from './TaxID.constants'import { sanitizeTaxID } from './TaxID.utils'@@@ -25,38 -26,67 +26,66 @@@ const TaxID = () =>const { slug } = useParams()const {- data: taxIds,- error,- isLoading,- isSuccess,- isError,+ data,+ error: taxIdsError,- refetch: refetchTaxIds,+ isLoading: isLoadingTaxIds,+ isError: isErrorTaxIds,+ isSuccess: isSuccessTaxIds,} = useOrganizationTaxIDsQuery({ slug })+ const taxIds = data || []- const [isSaving, setIsSaving] = useState(false)+ 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) => {+ ui.setNotification({ category: 'error', message: taxId.result.error.message })+ })+ } else {+ ui.setNotification({ category: 'success', message: 'Successfully updated tax IDs' })+ }+ },+ })+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 formattedTaxIds: StripeTaxId[] = taxIds.map((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 ?? '',+ }+ })useEffect(() => {- if (taxIdValues.length === 0) {- setTaxIdValues(formattedTaxIds)- } else {- const erroredTaxIds = taxIdValues.filter((taxId: any) => errors.includes(taxId.id))- setTaxIdValues(formattedTaxIds.concat(erroredTaxIds))- if (isSuccess) {++ if (isSuccessTaxIds) {+ if (taxIdValues.length === 0) {+ setTaxIdValues(formattedTaxIds)+ } else {+ const erroredTaxIds = taxIdValues.filter((taxId: any) => errors.includes(taxId.id))+ setTaxIdValues(formattedTaxIds.concat(erroredTaxIds))+ }}- }, [taxIds])- }, [isSuccess])++ }, [isSuccessTaxIds])const hasChanges = !isEqual(taxIdValues, formattedTaxIds)const canReadTaxIds = useCheckPermissions(PermissionAction.BILLING_READ, 'stripe.tax_ids')