mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: rendering pdf templates on the server-side
This commit is contained in:
@@ -12,10 +12,15 @@ import {
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from '@blueprintjs/core';
|
||||
import { If, Icon, FormattedMessage as T, Group } from '@/components';
|
||||
import { If, Icon, FormattedMessage as T, Group, FSelect } from '@/components';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import classNames from 'classnames';
|
||||
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
|
||||
import {
|
||||
BrandingThemeFormGroup,
|
||||
BrandingThemeSelectButton,
|
||||
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
|
||||
import { useCreditNoteFormBrandingTemplatesOptions } from './utils';
|
||||
|
||||
/**
|
||||
* Credit note floating actions.
|
||||
@@ -74,6 +79,8 @@ export default function CreditNoteFloatingActions() {
|
||||
resetForm();
|
||||
};
|
||||
|
||||
const brandingTemplatesOptions = useCreditNoteFormBrandingTemplatesOptions();
|
||||
|
||||
return (
|
||||
<Group
|
||||
spacing={10}
|
||||
@@ -190,6 +197,25 @@ export default function CreditNoteFloatingActions() {
|
||||
onClick={handleCancelBtnClick}
|
||||
text={<T id={'cancel'} />}
|
||||
/>
|
||||
|
||||
{/* ----------- Branding Template Select ----------- */}
|
||||
<BrandingThemeFormGroup
|
||||
name={'pdf_template_id'}
|
||||
label={'Branding'}
|
||||
inline
|
||||
fastField
|
||||
style={{ marginLeft: 20 }}
|
||||
>
|
||||
<FSelect
|
||||
name={'pdf_template_id'}
|
||||
items={brandingTemplatesOptions}
|
||||
input={({ activeItem, text, label, value }) => (
|
||||
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
|
||||
)}
|
||||
filterable={false}
|
||||
popoverProps={{ minimal: true }}
|
||||
/>
|
||||
</BrandingThemeFormGroup>
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
useSettingsCreditNotes,
|
||||
useInvoice,
|
||||
} from '@/hooks/query';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
|
||||
const CreditNoteFormContext = React.createContext();
|
||||
|
||||
@@ -73,6 +74,10 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Fetches branding templates of invoice.
|
||||
const { data: brandingTemplates, isLoading: isBrandingTemplatesLoading } =
|
||||
useGetPdfTemplates({ resource: 'PaymentReceive' });
|
||||
|
||||
// Handle fetching settings.
|
||||
useSettingsCreditNotes();
|
||||
|
||||
@@ -115,13 +120,18 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
createCreditNoteMutate,
|
||||
editCreditNoteMutate,
|
||||
setSubmitPayload,
|
||||
|
||||
// Branding templates.
|
||||
brandingTemplates,
|
||||
isBrandingTemplatesLoading,
|
||||
};
|
||||
|
||||
const isLoading =
|
||||
isItemsLoading ||
|
||||
isCustomersLoading ||
|
||||
isCreditNoteLoading ||
|
||||
isInvoiceLoading;
|
||||
isInvoiceLoading ||
|
||||
isBrandingTemplatesLoading;
|
||||
|
||||
return (
|
||||
<DashboardInsider loading={isLoading} name={'credit-note-form'}>
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
transformAttachmentsToForm,
|
||||
transformAttachmentsToRequest,
|
||||
} from '@/containers/Attachments/utils';
|
||||
import { convertBrandingTemplatesToOptions } from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
|
||||
|
||||
export const MIN_LINES_NUMBER = 1;
|
||||
|
||||
@@ -54,7 +55,8 @@ export const defaultCreditNote = {
|
||||
exchange_rate: 1,
|
||||
currency_code: '',
|
||||
entries: [...repeatValue(defaultCreditNoteEntry, MIN_LINES_NUMBER)],
|
||||
attachments: []
|
||||
attachments: [],
|
||||
pdf_template_id: '',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -214,3 +216,13 @@ export const useCreditNoteIsForeignCustomer = () => {
|
||||
);
|
||||
return isForeignCustomer;
|
||||
};
|
||||
|
||||
|
||||
export const useCreditNoteFormBrandingTemplatesOptions = () => {
|
||||
const { brandingTemplates } = useCreditNoteFormContext();
|
||||
|
||||
return React.useMemo(
|
||||
() => convertBrandingTemplatesToOptions(brandingTemplates),
|
||||
[brandingTemplates],
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user