Home / Function/ ChangePaymentMethodModal() — supabase Function Reference

ChangePaymentMethodModal() — supabase Function Reference

Architecture documentation for the ChangePaymentMethodModal() function in ChangePaymentMethodModal.tsx from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/studio/components/interfaces/Billing/Payment/PaymentMethods/ChangePaymentMethodModal.tsx lines 13–73

const ChangePaymentMethodModal = ({
  selectedPaymentMethod,
  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 onConfirmUpdate = async () => {
    if (!slug) return console.error('Slug is required')
    if (!selectedPaymentMethod) return console.error('Card ID is required')

    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>
  )
}

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free