mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat: templates customize
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { omit } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import {
|
||||
CreatePdfTemplateValues,
|
||||
EditPdfTemplateValues,
|
||||
@@ -7,6 +8,7 @@ import { useBrandingTemplateBoot } from './BrandingTemplateBoot';
|
||||
import { transformToForm } from '@/utils';
|
||||
import { BrandingTemplateValues } from './types';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
|
||||
export const transformToEditRequest = <T extends BrandingTemplateValues>(
|
||||
values: T,
|
||||
@@ -19,7 +21,7 @@ export const transformToEditRequest = <T extends BrandingTemplateValues>(
|
||||
|
||||
export const transformToNewRequest = <T extends BrandingTemplateValues>(
|
||||
values: T,
|
||||
resource: string
|
||||
resource: string,
|
||||
): CreatePdfTemplateValues => {
|
||||
return {
|
||||
resource,
|
||||
@@ -28,12 +30,6 @@ export const transformToNewRequest = <T extends BrandingTemplateValues>(
|
||||
};
|
||||
};
|
||||
|
||||
export const useIsTemplateNamedFilled = () => {
|
||||
const { values } = useFormikContext<BrandingTemplateValues>();
|
||||
|
||||
return values.templateName && values.templateName?.length >= 4;
|
||||
};
|
||||
|
||||
export const useBrandingTemplateFormInitialValues = <
|
||||
T extends BrandingTemplateValues,
|
||||
>(
|
||||
@@ -50,3 +46,25 @@ export const useBrandingTemplateFormInitialValues = <
|
||||
...(transformToForm(defaultPdfTemplate, initialValues) as T),
|
||||
};
|
||||
};
|
||||
|
||||
export const getCustomizeDrawerNameFromResource = (resource: string) => {
|
||||
const pairs = {
|
||||
SaleInvoice: DRAWERS.INVOICE_CUSTOMIZE,
|
||||
SaleEstimate: DRAWERS.ESTIMATE_CUSTOMIZE,
|
||||
SaleReceipt: DRAWERS.RECEIPT_CUSTOMIZE,
|
||||
CreditNote: DRAWERS.CREDIT_NOTE_CUSTOMIZE,
|
||||
PaymentReceive: DRAWERS.PAYMENT_RECEIVED_CUSTOMIZE,
|
||||
};
|
||||
return R.prop(resource, pairs) || DRAWERS.INVOICE_CUSTOMIZE;
|
||||
};
|
||||
|
||||
export const getButtonLabelFromResource = (resource: string) => {
|
||||
const pairs = {
|
||||
SaleInvoice: 'Create Invoice Branding',
|
||||
SaleEstimate: 'Create Estimate Branding',
|
||||
SaleReceipt: 'Create Receipt Branding',
|
||||
CreditNote: 'Create Credit Note Branding',
|
||||
PaymentReceive: 'Create Payment Branding',
|
||||
};
|
||||
return R.prop(resource, pairs) || 'Create Branding Template';
|
||||
}
|
||||
Reference in New Issue
Block a user