mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
feat: Assign default PDF template automatically
This commit is contained in:
@@ -61,6 +61,7 @@ function InvoiceForm({
|
||||
createInvoiceMutate,
|
||||
editInvoiceMutate,
|
||||
submitPayload,
|
||||
saleInvoiceState
|
||||
} = useInvoiceFormContext();
|
||||
|
||||
// Invoice number.
|
||||
@@ -83,6 +84,7 @@ function InvoiceForm({
|
||||
currency_code: base_currency,
|
||||
invoice_message: defaultTo(invoiceCustomerNotes, ''),
|
||||
terms_conditions: defaultTo(invoiceTermsConditions, ''),
|
||||
pdf_template_id: saleInvoiceState?.defaultTemplateId,
|
||||
...newInvoice,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -16,13 +16,22 @@ import {
|
||||
useEditInvoice,
|
||||
useSettingsInvoices,
|
||||
useEstimate,
|
||||
useGetSaleInvoiceState,
|
||||
GetSaleInvoiceStateResponse,
|
||||
} from '@/hooks/query';
|
||||
import { useProjects } from '@/containers/Projects/hooks';
|
||||
import { useTaxRates } from '@/hooks/query/taxRates';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
import { useGetPaymentServices } from '@/hooks/query/payment-services';
|
||||
|
||||
const InvoiceFormContext = createContext();
|
||||
interface InvoiceFormContextValue {
|
||||
saleInvoiceState: GetSaleInvoiceStateResponse | null;
|
||||
isInvoiceStateLoading: boolean;
|
||||
}
|
||||
|
||||
const InvoiceFormContext = createContext<InvoiceFormContextValue>(
|
||||
{} as InvoiceFormContextValue,
|
||||
);
|
||||
|
||||
/**
|
||||
* Accounts chart data provider.
|
||||
@@ -100,6 +109,9 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||
|
||||
const { data: saleInvoiceState, isLoading: isInvoiceStateLoading } =
|
||||
useGetSaleInvoiceState();
|
||||
|
||||
// Handle fetching settings.
|
||||
const { isLoading: isSettingsLoading } = useSettingsInvoices();
|
||||
|
||||
@@ -154,6 +166,10 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
// Payment Services
|
||||
paymentServices,
|
||||
isPaymentServicesLoading,
|
||||
|
||||
// Invoice state
|
||||
saleInvoiceState,
|
||||
isInvoiceStateLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -172,6 +188,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
);
|
||||
}
|
||||
|
||||
const useInvoiceFormContext = () => React.useContext(InvoiceFormContext);
|
||||
const useInvoiceFormContext = () =>
|
||||
React.useContext<InvoiceFormContextValue>(InvoiceFormContext);
|
||||
|
||||
export { InvoiceFormProvider, useInvoiceFormContext };
|
||||
|
||||
Reference in New Issue
Block a user