Skip to content

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

chore: migrate billing `Modal` to `Dialog` (#46385)

Gildas Garciae26303cf9c49
diff --git a/apps/studio/components/interfaces/Billing/Payment/AddNewPaymentMethodModal.tsx b/apps/studio/components/interfaces/Billing/Payment/AddNewPaymentMethodModal.tsx
index 2d9ae03ad44..e048e37012e 100644
--- a/apps/studio/components/interfaces/Billing/Payment/AddNewPaymentMethodModal.tsx
+++ b/apps/studio/components/interfaces/Billing/Payment/AddNewPaymentMethodModal.tsx
@@ -4,7 +4,7 @@ import { loadStripe } from '@stripe/stripe-js'
import { useTheme } from 'next-themes'
import { useCallback, useEffect, useState } from 'react'
import { toast } from 'sonner'
-import { Modal } from 'ui'
+import { Dialog, DialogContent, DialogHeader, DialogSectionSeparator, DialogTitle } from 'ui'
import AddPaymentMethodForm from './AddPaymentMethodForm'
import { getStripeElementsAppearanceOptions } from './Payment.utils'
@@ -123,22 +123,21 @@ const AddNewPaymentMethodModal = ({
}}
/>
- <Modal
- hideFooter
- size="medium"
- visible={visible && intent !== undefined}
- header="Add new payment method"
- onCancel={onLocalCancel}
- className="PAYMENT"
- >
- <Elements stripe={stripePromise} options={options}>
- <AddPaymentMethodForm
- returnUrl={returnUrl}
- onCancel={onLocalCancel}
- onConfirm={onLocalConfirm}
- />
- </Elements>
- </Modal>
+ <Dialog open={visible && intent !== undefined} onOpenChange={onLocalCancel}>
+ <DialogContent size="medium" className="PAYMENT">
+ <DialogHeader>
+ <DialogTitle>Add new payment method</DialogTitle>
+ </DialogHeader>
+ <DialogSectionSeparator />
+ <Elements stripe={stripePromise} options={options}>
+ <AddPaymentMethodForm
+ returnUrl={returnUrl}
+ onCancel={onLocalCancel}
+ onConfirm={onLocalConfirm}
+ />
+ </Elements>
+ </DialogContent>
+ </Dialog>
</>
)
}
diff --git a/apps/studio/components/interfaces/Billing/Payment/AddPaymentMethodForm.tsx b/apps/studio/components/interfaces/Billing/Payment/AddPaymentMethodForm.tsx
index ba00e3ed9f7..792fa3eae53 100644
--- a/apps/studio/components/interfaces/Billing/Payment/AddPaymentMethodForm.tsx
+++ b/apps/studio/components/interfaces/Billing/Payment/AddPaymentMethodForm.tsx
@@ -1,7 +1,7 @@
import { useQueryClient } from '@tanstack/react-query'
import { useRef, useState } from 'react'
import { toast } from 'sonner'
-import { Button, Checkbox, Label, Modal } from 'ui'
+import { Button, Checkbox, DialogFooter, DialogSection, Label } from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import {
@@ -177,7 +177,7 @@ const AddPaymentMethodForm = ({ onCancel, onConfirm }: AddPaymentMethodFormProps
if (customerProfileLoading || isCustomerTaxIdLoading) {
return (
- <Modal.Content>
+ <DialogSection>
<div className="space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" />
@@ -186,13 +186,13 @@ const AddPaymentMethodForm = ({ onCancel, onConfirm }: AddPaymentMethodFormProps
<ShimmeringLoader />
<ShimmeringLoader />
</div>
- </Modal.Content>
+ </DialogSection>
)
}
return (
- <div>
- <Modal.Content
+ <>
+ <DialogSection
className={`transition ${isSaving ? 'pointer-events-none opacity-75' : 'opacity-100'}`}
>
<NewPaymentMethodElement
@@ -233,9 +233,8 @@ const AddPaymentMethodForm = ({ onCancel, onConfirm }: AddPaymentMethodFormProps
Use the billing address as my organization's primary address
</Label>
</div>
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content className="flex items-center space-x-2">
+ </DialogSection>
+ <DialogFooter>
<Button
htmlType="button"
size="small"
@@ -257,8 +256,8 @@ const AddPaymentMethodForm = ({ onCancel, onConfirm }: AddPaymentMethodFormProps
>
Add payment method
</Button>
- </Modal.Content>
- </div>
+ </DialogFooter>
+ </>
)
}
diff --git a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/ChangePaymentMethodModal.tsx b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/ChangePaymentMethodModal.tsx
index 837ae1209d4..5fd383fed14 100644
--- a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/ChangePaymentMethodModal.tsx
+++ b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/ChangePaymentMethodModal.tsx
@@ -1,6 +1,15 @@
import { useParams } from 'common'
import { toast } from 'sonner'
-import { Button, Modal } from 'ui'
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from 'ui'
import { useOrganizationPaymentMethodMarkAsDefaultMutation } from '@/data/organizations/organization-payment-method-default-mutation'
import type { OrganizationPaymentMethod } from '@/data/organizations/organization-payment-methods-query'
@@ -15,60 +24,46 @@ const ChangePaymentMethodModal = ({
onClose,
}: ChangePaymentMethodModalProps) => {
const { slug } = useParams()
- const { mutate: markAsDefault, isPending: isUpdating } =
- useOrganizationPaymentMethodMarkAsDefaultMutation({
- onSuccess: () => {
- toast.success(
- `Successfully changed payment method to the card ending with ${
- selectedPaymentMethod!.card!.last4
- }`
- )
- onClose()
- },
- onError: (error) => {
- toast.error(`Failed to change payment method: ${error.message}`)
- },
- })
+ const { mutateAsync: markAsDefault } = useOrganizationPaymentMethodMarkAsDefaultMutation({
+ onSuccess: () => {
+ toast.success(
+ `Successfully changed payment method to the card ending with ${
+ selectedPaymentMethod!.card!.last4
+ }`
+ )
+ onClose()
+ },
+ onError: (error) => {
+ toast.error(`Failed to change payment method: ${error.message}`)
+ },
+ })
const onConfirmUpdate = async () => {
if (!slug) return console.error('Slug is required')
if (!selectedPaymentMethod) return console.error('Card ID is required')
- markAsDefault({
+ await markAsDefault({
slug,
paymentMethodId: selectedPaymentMethod.id,
})
}
return (
- <Modal
- visible={selectedPaymentMethod !== undefined}
- size="medium"
- header={`Confirm to use payment method ending with ${selectedPaymentMethod?.card?.last4}`}
- onCancel={() => onClose()}
- customFooter={
- <div className="flex items-center gap-2">
- <Button type="default" disabled={isUpdating} onClick={() => onClose()}>
- Cancel
- </Button>
- <Button
- type="primary"
- disabled={isUpdating}
- loading={isUpdating}
- onClick={onConfirmUpdate}
- >
- Confirm
- </Button>
- </div>
- }
- >
- <Modal.Content>
- <p className="text-sm">
- Upon clicking confirm, all future charges will be deducted from the card ending with{' '}
- {selectedPaymentMethod?.card?.last4}. There are no immediate charges.
- </p>
- </Modal.Content>
- </Modal>
+ <AlertDialog open={selectedPaymentMethod !== undefined} onOpenChange={() => onClose()}>
+ <AlertDialogContent size="medium">
+ <AlertDialogHeader>
+ <AlertDialogTitle>{`Confirm to use payment method ending with ${selectedPaymentMethod?.card?.last4}`}</AlertDialogTitle>
+ <AlertDialogDescription>
+ Upon clicking confirm, all future charges will be deducted from the card ending with{' '}
+ {selectedPaymentMethod?.card?.last4}. There are no immediate charges.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction onClick={onConfirmUpdate}>Confirm</AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
)
}
diff --git a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/DeletePaymentMethodModal.tsx b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/DeletePaymentMethodModal.tsx
index 6874645dfe0..144dfe661f6 100644
--- a/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/DeletePaymentMethodModal.tsx
+++ b/apps/studio/components/interfaces/Billing/Payment/PaymentMethods/DeletePaymentMethodModal.tsx
@@ -1,6 +1,15 @@
import { useParams } from 'common'
import { toast } from 'sonner'
-import { Button, Modal } from 'ui'
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from 'ui'
import { Admonition } from 'ui-patterns'
import { useOrganizationPaymentMethodDeleteMutation } from '@/data/organizations/organization-payment-method-delete-mutation'
@@ -17,52 +26,40 @@ const DeletePaymentMethodModal = ({
}: DeletePaymentMethodModalProps) => {
const { slug } = useParams()
- const { mutate: deletePayment, isPending: isDeleting } =
- useOrganizationPaymentMethodDeleteMutation({
- onSuccess: () => {
- toast.success(
- `Successfully removed payment method ending with ${selectedPaymentMethod?.card?.last4}`
- )
- onClose()
- },
- })
+ const { mutateAsync: deletePayment } = useOrganizationPaymentMethodDeleteMutation({
+ onSuccess: () => {
+ toast.success(
+ `Successfully removed payment method ending with ${selectedPaymentMethod?.card?.last4}`
+ )
+ onClose()
+ },
+ })
const onConfirmDelete = async () => {
if (!slug) return console.error('Slug is required')
if (!selectedPaymentMethod) return console.error('Card ID is required')
- deletePayment({ slug, cardId: selectedPaymentMethod.id })
+ await deletePayment({ slug, cardId: selectedPaymentMethod.id })
}
return (
- <Modal
- visible={selectedPaymentMethod !== undefined}
- size="medium"
- header={`Confirm to delete payment method ending with ${selectedPaymentMethod?.card?.last4}`}
- onCancel={() => onClose()}
- customFooter={
- <div className="flex items-center gap-2">
- <Button type="default" disabled={isDeleting} onClick={() => onClose()}>
- Cancel
- </Button>
- <Button
- type="primary"
- disabled={isDeleting}
- loading={isDeleting}
- onClick={onConfirmDelete}
- >
- Confirm
- </Button>
- </div>
- }
- >
- <Modal.Content>
- <Admonition
- type="default"
- title="This will permanently delete your payment method."
- description="You can re-add the payment method any time."
- />
- </Modal.Content>
- </Modal>
+ <AlertDialog open={selectedPaymentMethod !== undefined} onOpenChange={() => onClose()}>
+ <AlertDialogContent size="medium">
+ <AlertDialogHeader>
+ <AlertDialogTitle>{`Confirm to delete payment method ending with ${selectedPaymentMethod?.card?.last4}`}</AlertDialogTitle>
+ <AlertDialogDescription>
+ <Admonition
+ type="default"
+ title="This will permanently delete your payment method."
+ description="You can re-add the payment method any time."
+ />
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction onClick={onConfirmDelete}>Confirm</AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
)
}
diff --git a/apps/studio/components/interfaces/Billing/SpendCapModal.tsx b/apps/studio/components/interfaces/Billing/SpendCapModal.tsx
index 4dcf0489dfa..66b45ee4566 100644
--- a/apps/studio/components/interfaces/Billing/SpendCapModal.tsx
+++ b/apps/studio/components/interfaces/Billing/SpendCapModal.tsx
@@ -1,4 +1,18 @@
-import { Button, Modal, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from 'ui'
import { DocsButton } from '@/components/ui/DocsButton'
import { DOCS_URL } from '@/lib/constants'
@@ -10,115 +24,108 @@ interface SpendCapModalProps {
const SpendCapModal = ({ visible, onHide }: SpendCapModalProps) => {
return (
- <Modal
- hideFooter
- visible={visible}
- size="xlarge"
- header={
- <div className="flex justify-between items-center">
- <span>Spend Cap</span>
- <DocsButton href={`${DOCS_URL}/guides/platform/cost-control#spend-cap`} />
- </div>
- }
- showCloseButton={false}
- onCancel={() => onHide()}
- >
- <Modal.Content>
- <div className="space-y-4">
- <p className="text-sm">
- Enabling the Spend Cap limits your usage to your plan's quota, which controls costs but
- can restrict your service. Disabling the spend cap removes these limits, but any extra
- usage beyond the plan's limit will be charged per usage.
- </p>
- <p className="text-sm">
- Launching additional projects or enabling project add-ons will incur additional monthly
- fees independent of your Spend Cap.
- </p>
+ <AlertDialog open={visible} onOpenChange={() => onHide()}>
+ <AlertDialogContent size="xlarge">
+ <AlertDialogHeader>
+ <AlertDialogTitle>
+ <div className="flex justify-between items-center">
+ <span>Spend Cap</span>
+ <DocsButton href={`${DOCS_URL}/guides/platform/cost-control#spend-cap`} />
+ </div>
+ </AlertDialogTitle>
+ <AlertDialogDescription asChild>
+ <div className="space-y-4">
+ <p className="text-sm">
+ Enabling the Spend Cap limits your usage to your plan's quota, which controls costs
+ but can restrict your service. Disabling the spend cap removes these limits, but any
+ extra usage beyond the plan's limit will be charged per usage.
+ </p>
+ <p className="text-sm">
+ Launching additional projects or enabling project add-ons will incur additional
+ monthly fees independent of your Spend Cap.
+ </p>
- {/* Maybe instead of a table, show something more interactive like a spend cap playground */}
- {/* Maybe ideate this in Figma first but this is good enough for now */}
+ {/* Maybe instead of a table, show something more interactive like a spend cap playground */}
+ {/* Maybe ideate this in Figma first but this is good enough for now */}
- <Table>
- <TableHeader className="[&_th]:h-7">
- <TableRow>
- <TableHead className="w-[50%]">Item</TableHead>
- <TableHead className="w-[25%]">Limit</TableHead>
- <TableHead className="w-[25%]">Rate</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody className="[&_td]:py-2">
- <TableRow>
- <TableCell>Disk Size</TableCell>
- <TableCell>8 GB per project</TableCell>
- <TableCell translate="no">$0.125 per GB</TableCell>
- </TableRow>
+ <Table>
+ <TableHeader className="[&_th]:h-7">
+ <TableRow>
+ <TableHead className="w-[50%]">Item</TableHead>
+ <TableHead className="w-[25%]">Limit</TableHead>
+ <TableHead className="w-[25%]">Rate</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody className="[&_td]:py-2">
+ <TableRow>
+ <TableCell>Disk Size</TableCell>
+ <TableCell>8 GB per project</TableCell>
+ <TableCell translate="no">$0.125 per GB</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Egress</TableCell>
- <TableCell>250 GB</TableCell>
- <TableCell translate="no">$0.09 per GB</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Egress</TableCell>
+ <TableCell>250 GB</TableCell>
+ <TableCell translate="no">$0.09 per GB</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Auth MAUs</TableCell>
- <TableCell>100,000</TableCell>
- <TableCell translate="no">$0.00325 per user</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Auth MAUs</TableCell>
+ <TableCell>100,000</TableCell>
+ <TableCell translate="no">$0.00325 per user</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Auth Third-Party MAUs</TableCell>
- <TableCell>100,000</TableCell>
- <TableCell translate="no">$0.00325 per user</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Auth Third-Party MAUs</TableCell>
+ <TableCell>100,000</TableCell>
+ <TableCell translate="no">$0.00325 per user</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Auth Single Sign-On MAUs</TableCell>
- <TableCell>50</TableCell>
- <TableCell translate="no">$0.015 per user</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Auth Single Sign-On MAUs</TableCell>
+ <TableCell>50</TableCell>
+ <TableCell translate="no">$0.015 per user</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Storage Size</TableCell>
- <TableCell>100 GB</TableCell>
- <TableCell translate="no">$0.021 per GB</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Storage Size</TableCell>
+ <TableCell>100 GB</TableCell>
+ <TableCell translate="no">$0.021 per GB</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Storage Image Transformations</TableCell>
- <TableCell>100 origin images</TableCell>
- <TableCell translate="no">$5 per 1000 images</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Storage Image Transformations</TableCell>
+ <TableCell>100 origin images</TableCell>
+ <TableCell translate="no">$5 per 1000 images</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Realtime Concurrent Peak Connections</TableCell>
- <TableCell>500</TableCell>
- <TableCell translate="no">$10 per 1000</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Realtime Concurrent Peak Connections</TableCell>
+ <TableCell>500</TableCell>
+ <TableCell translate="no">$10 per 1000</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Realtime Messages</TableCell>
- <TableCell>5 Million</TableCell>
- <TableCell translate="no">$2.50 per Million</TableCell>
- </TableRow>
+ <TableRow>
+ <TableCell>Realtime Messages</TableCell>
+ <TableCell>5 Million</TableCell>
+ <TableCell translate="no">$2.50 per Million</TableCell>
+ </TableRow>
- <TableRow>
- <TableCell>Function Invocations</TableCell>
- <TableCell>2 Million</TableCell>
- <TableCell translate="no">$2 per Million</TableCell>
- </TableRow>
- </TableBody>
- </Table>
- </div>
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content>
- <div className="flex items-center gap-2">
- <Button block type="primary" onClick={() => onHide()}>
- Understood
- </Button>
- </div>
- </Modal.Content>
- </Modal>
+ <TableRow>
+ <TableCell>Function Invocations</TableCell>
+ <TableCell>2 Million</TableCell>
+ <TableCell translate="no">$2 per Million</TableCell>
+ </TableRow>
+ </TableBody>
+ </Table>
+ </div>
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogAction onClick={() => onHide()}>Understood</AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
)
}