mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: hook up the invice customize api
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
import { omit } from 'lodash';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { InvoiceCustomizeValues } from './types';
|
||||
import { CreatePdfTemplateValues, EditPdfTemplateValues } from '@/hooks/query/pdf-templates';
|
||||
import {
|
||||
CreatePdfTemplateValues,
|
||||
EditPdfTemplateValues,
|
||||
} from '@/hooks/query/pdf-templates';
|
||||
import { useBrandingTemplateBoot } from '../BrandingTemplates/BrandingTemplateBoot';
|
||||
import { transformToForm } from '@/utils';
|
||||
import { initialValues } from './constants';
|
||||
|
||||
export const transformToEditRequest = (
|
||||
values: InvoiceCustomizeValues,
|
||||
templateId: number,
|
||||
): EditPdfTemplateValues => {
|
||||
return {
|
||||
templateId,
|
||||
templateName: 'Template Name',
|
||||
templateName: values.templateName,
|
||||
attributes: omit(values, ['templateName']),
|
||||
};
|
||||
};
|
||||
@@ -18,7 +23,29 @@ export const transformToNewRequest = (
|
||||
): CreatePdfTemplateValues => {
|
||||
return {
|
||||
resource: 'SaleInvoice',
|
||||
templateName: 'Template Name',
|
||||
templateName: values.templateName,
|
||||
attributes: omit(values, ['templateName']),
|
||||
};
|
||||
};
|
||||
|
||||
export const useIsTemplateNamedFilled = () => {
|
||||
const { values } = useFormikContext<InvoiceCustomizeValues>();
|
||||
|
||||
return values.templateName && values.templateName?.length >= 4;
|
||||
};
|
||||
|
||||
export const useInvoiceCustomizeInitialValues = (): InvoiceCustomizeValues => {
|
||||
const { pdfTemplate } = useBrandingTemplateBoot();
|
||||
|
||||
const defaultPdfTemplate = {
|
||||
templateName: pdfTemplate?.templateName,
|
||||
...pdfTemplate?.attributes,
|
||||
};
|
||||
return {
|
||||
...initialValues,
|
||||
...(transformToForm(
|
||||
defaultPdfTemplate,
|
||||
initialValues,
|
||||
) as InvoiceCustomizeValues),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user