-
-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathDownloadButton.tsx
More file actions
37 lines (31 loc) · 1.09 KB
/
DownloadButton.tsx
File metadata and controls
37 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { FC } from 'react';
import { useOrganization } from 'tg.views/organizations/useOrganization';
import { components } from 'tg.service/billingApiSchema.generated';
import { useBillingApiMutation } from 'tg.service/http/useQueryApi';
import { useInvoicePdfDownload } from './useInvoicePdfDownload';
import { PdfDownloadButton } from './PdfDownloadButton';
type DownloadButtonProps = {
invoice: components['schemas']['InvoiceModel'];
};
export const DownloadButton: FC<DownloadButtonProps> = ({ invoice }) => {
const organization = useOrganization();
const { onSuccess } = useInvoicePdfDownload(invoice);
const pdfMutation = useBillingApiMutation({
url: '/v2/organizations/{organizationId}/billing/invoices/{invoiceId}/pdf',
method: 'get',
fetchOptions: { rawResponse: true },
});
const onDownload = () => {
pdfMutation.mutate(
{ path: { organizationId: organization!.id, invoiceId: invoice.id } },
{ onSuccess }
);
};
return (
<PdfDownloadButton
invoice={invoice}
onDownload={onDownload}
isLoading={pdfMutation.isLoading}
/>
);
};