InvoicePayButton.tsx31 lines · main
| 1 | import { toast } from 'sonner' |
| 2 | import { Button } from 'ui' |
| 3 | |
| 4 | import { useInvoicePaymentLinkGetMutation } from '@/data/invoices/invoice-payment-link-mutation' |
| 5 | |
| 6 | interface InvoicePayButtonProps { |
| 7 | slug?: string |
| 8 | invoiceId: string |
| 9 | } |
| 10 | |
| 11 | const InvoicePayButton = ({ slug, invoiceId }: InvoicePayButtonProps) => { |
| 12 | const { mutate, isPending } = useInvoicePaymentLinkGetMutation({ |
| 13 | onSuccess(data) { |
| 14 | toast.success('Redirecting to payment gateway...') |
| 15 | |
| 16 | window.location.href = data.redirectUrl |
| 17 | }, |
| 18 | }) |
| 19 | |
| 20 | function onPayNow() { |
| 21 | mutate({ slug, invoiceId }) |
| 22 | } |
| 23 | |
| 24 | return ( |
| 25 | <Button onClick={onPayNow} loading={isPending} disabled={isPending}> |
| 26 | Pay now |
| 27 | </Button> |
| 28 | ) |
| 29 | } |
| 30 | |
| 31 | export default InvoicePayButton |