import { useParams } from 'common' import { toast } from 'sonner' import { Button, Modal } from 'ui' import { useOrganizationPaymentMethodMarkAsDefaultMutation } from '@/data/organizations/organization-payment-method-default-mutation' import type { OrganizationPaymentMethod } from '@/data/organizations/organization-payment-methods-query' export interface ChangePaymentMethodModalProps { selectedPaymentMethod?: OrganizationPaymentMethod onClose: () => void } 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 ( onClose()} customFooter={
} >

Upon clicking confirm, all future charges will be deducted from the card ending with{' '} {selectedPaymentMethod?.card?.last4}. There are no immediate charges.

) } export default ChangePaymentMethodModal