feat: getting invoice preview on send mail view

This commit is contained in:
Ahmed Bouhuolia
2024-11-05 22:30:54 +02:00
parent b6baa80134
commit 802775c118
5 changed files with 102 additions and 17 deletions

View File

@@ -201,6 +201,34 @@ export function usePdfInvoice(invoiceId) {
});
}
interface GetInvoiceHtmlResponse {
htmlContent: string;
}
/**
* Retrieves the invoice html content.
* @param {number} invoiceId
* @param {UseQueryOptions<GetInvoiceHtmlResponse>} options
* @returns {UseQueryResult<GetInvoiceHtmlResponse>}
*/
export const useInvoiceHtml = (
invoiceId: number,
options?: UseQueryOptions<GetInvoiceHtmlResponse>,
): UseQueryResult<GetInvoiceHtmlResponse> => {
const apiRequest = useApiRequest();
return useQuery<GetInvoiceHtmlResponse>(
['SALE_INVOICE_HTML', invoiceId],
() =>
apiRequest
.get(`sales/invoices/${invoiceId}`, {
headers: {
Accept: 'application/json+html',
},
})
.then((res) => transformToCamelCase(res.data)),
);
};
/**
* Retrieve due invoices of the given customer id.
* @param {number} customerId - Customer id.