mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix: Pdf branding templates request data
This commit is contained in:
@@ -1,19 +1,21 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
|
import { Spinner } from '@blueprintjs/core';
|
||||||
import {
|
import {
|
||||||
GetPdfTemplateBrandingStateResponse,
|
GetPdfTemplateBrandingStateResponse,
|
||||||
GetPdfTemplateResponse,
|
GetPdfTemplateResponse,
|
||||||
useGetPdfTemplate,
|
useGetPdfTemplate,
|
||||||
useGetPdfTemplateBrandingState,
|
useGetPdfTemplateBrandingState,
|
||||||
} from '@/hooks/query/pdf-templates';
|
} from '@/hooks/query/pdf-templates';
|
||||||
import { Spinner } from '@blueprintjs/core';
|
|
||||||
|
|
||||||
interface PdfTemplateContextValue {
|
interface PdfTemplateContextValue {
|
||||||
templateId: number | string;
|
templateId: number | string;
|
||||||
pdfTemplate: GetPdfTemplateResponse | undefined;
|
|
||||||
|
// Pdf template.
|
||||||
|
pdfTemplate: GetPdfTemplateResponse;
|
||||||
isPdfTemplateLoading: boolean;
|
isPdfTemplateLoading: boolean;
|
||||||
|
|
||||||
// Branding state.
|
// Branding state.
|
||||||
brandingTemplateState: GetPdfTemplateBrandingStateResponse | undefined;
|
brandingTemplateState: GetPdfTemplateBrandingStateResponse;
|
||||||
isBrandingTemplateLoading: boolean;
|
isBrandingTemplateLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,10 +36,18 @@ export const BrandingTemplateBoot = ({
|
|||||||
useGetPdfTemplate(templateId, {
|
useGetPdfTemplate(templateId, {
|
||||||
enabled: !!templateId,
|
enabled: !!templateId,
|
||||||
});
|
});
|
||||||
// Retreives the branding template state.
|
// Retrieves the branding template state.
|
||||||
const { data: brandingTemplateState, isLoading: isBrandingTemplateLoading } =
|
const { data: brandingTemplateState, isLoading: isBrandingTemplateLoading } =
|
||||||
useGetPdfTemplateBrandingState();
|
useGetPdfTemplateBrandingState();
|
||||||
|
|
||||||
|
const isLoading = isPdfTemplateLoading ||
|
||||||
|
isBrandingTemplateLoading ||
|
||||||
|
!brandingTemplateState ||
|
||||||
|
!pdfTemplate;
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <Spinner size={20} />;
|
||||||
|
}
|
||||||
const value = {
|
const value = {
|
||||||
templateId,
|
templateId,
|
||||||
pdfTemplate,
|
pdfTemplate,
|
||||||
@@ -47,11 +57,6 @@ export const BrandingTemplateBoot = ({
|
|||||||
isBrandingTemplateLoading,
|
isBrandingTemplateLoading,
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLoading = isPdfTemplateLoading || isBrandingTemplateLoading;
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return <Spinner size={20} />;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<PdfTemplateContext.Provider value={value}>
|
<PdfTemplateContext.Provider value={value}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
transformToEditRequest,
|
transformToEditRequest,
|
||||||
transformToNewRequest,
|
transformToNewRequest,
|
||||||
|
useBrandingState,
|
||||||
useBrandingTemplateFormInitialValues,
|
useBrandingTemplateFormInitialValues,
|
||||||
} from './_utils';
|
} from './_utils';
|
||||||
import { AppToaster } from '@/components';
|
import { AppToaster } from '@/components';
|
||||||
@@ -17,31 +18,42 @@ import {
|
|||||||
useEditPdfTemplate,
|
useEditPdfTemplate,
|
||||||
} from '@/hooks/query/pdf-templates';
|
} from '@/hooks/query/pdf-templates';
|
||||||
import { FormikHelpers } from 'formik';
|
import { FormikHelpers } from 'formik';
|
||||||
import { BrandingTemplateValues } from './types';
|
import { BrandingTemplateValues, BrandingState } from './types';
|
||||||
import { useUploadAttachments } from '@/hooks/query/attachments';
|
import { useUploadAttachments } from '@/hooks/query/attachments';
|
||||||
import { excludePrivateProps } from '@/utils';
|
import { excludePrivateProps } from '@/utils';
|
||||||
|
|
||||||
interface BrandingTemplateFormProps<T> extends ElementCustomizeProps<T> {
|
interface BrandingTemplateFormProps<
|
||||||
|
T extends BrandingTemplateValues,
|
||||||
|
Y extends BrandingState
|
||||||
|
> extends ElementCustomizeProps<T, Y> {
|
||||||
resource: string;
|
resource: string;
|
||||||
templateId?: number;
|
templateId?: number;
|
||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
onError?: () => void;
|
onError?: () => void;
|
||||||
|
|
||||||
|
/* The default values hold the initial values of the form and the values being sent to the server. */
|
||||||
defaultValues?: T;
|
defaultValues?: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BrandingTemplateForm<T extends BrandingTemplateValues>({
|
export function BrandingTemplateForm<
|
||||||
|
T extends BrandingTemplateValues,
|
||||||
|
Y extends BrandingState,
|
||||||
|
>({
|
||||||
templateId,
|
templateId,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onError,
|
onError,
|
||||||
defaultValues,
|
defaultValues,
|
||||||
resource,
|
resource,
|
||||||
...props
|
...props
|
||||||
}: BrandingTemplateFormProps<T>) {
|
}: BrandingTemplateFormProps<T, Y>) {
|
||||||
|
// Create/edit pdf template mutators.
|
||||||
const { mutateAsync: createPdfTemplate } = useCreatePdfTemplate();
|
const { mutateAsync: createPdfTemplate } = useCreatePdfTemplate();
|
||||||
const { mutateAsync: editPdfTemplate } = useEditPdfTemplate();
|
const { mutateAsync: editPdfTemplate } = useEditPdfTemplate();
|
||||||
|
|
||||||
const initialValues = useBrandingTemplateFormInitialValues<T>(defaultValues);
|
const initialValues = useBrandingTemplateFormInitialValues<T>(defaultValues);
|
||||||
const [isUploading, setIsLoading] = useState<boolean>(false);
|
const brandingState = useBrandingState();
|
||||||
|
|
||||||
|
const [, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
// Uploads the attachments.
|
// Uploads the attachments.
|
||||||
const { mutateAsync: uploadAttachments } = useUploadAttachments({
|
const { mutateAsync: uploadAttachments } = useUploadAttachments({
|
||||||
@@ -122,10 +134,11 @@ export function BrandingTemplateForm<T extends BrandingTemplateValues>({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ElementCustomize<T>
|
<ElementCustomize<T, Y>
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
onSubmit={handleFormSubmit}
|
onSubmit={handleFormSubmit}
|
||||||
|
brandingState={brandingState || {}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '@/hooks/query/pdf-templates';
|
} from '@/hooks/query/pdf-templates';
|
||||||
import { useBrandingTemplateBoot } from './BrandingTemplateBoot';
|
import { useBrandingTemplateBoot } from './BrandingTemplateBoot';
|
||||||
import { transformToForm } from '@/utils';
|
import { transformToForm } from '@/utils';
|
||||||
import { BrandingTemplateValues } from './types';
|
import { BrandingState, BrandingTemplateValues } from './types';
|
||||||
import { DRAWERS } from '@/constants/drawers';
|
import { DRAWERS } from '@/constants/drawers';
|
||||||
|
|
||||||
const commonExcludedAttrs = ['templateName', 'companyLogoUri'];
|
const commonExcludedAttrs = ['templateName', 'companyLogoUri'];
|
||||||
@@ -48,7 +48,7 @@ export const useBrandingTemplateFormInitialValues = <
|
|||||||
|
|
||||||
const brandingAttributes = {
|
const brandingAttributes = {
|
||||||
templateName: pdfTemplate?.templateName,
|
templateName: pdfTemplate?.templateName,
|
||||||
...brandingTemplateState,
|
// ...brandingTemplateState,
|
||||||
...pdfTemplate?.attributes,
|
...pdfTemplate?.attributes,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
@@ -57,6 +57,15 @@ export const useBrandingTemplateFormInitialValues = <
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useBrandingState = (state?: Partial<BrandingState>): BrandingState => {
|
||||||
|
const { brandingTemplateState } = useBrandingTemplateBoot();
|
||||||
|
|
||||||
|
return {
|
||||||
|
...brandingTemplateState,
|
||||||
|
...state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const getCustomizeDrawerNameFromResource = (resource: string) => {
|
export const getCustomizeDrawerNameFromResource = (resource: string) => {
|
||||||
const pairs = {
|
const pairs = {
|
||||||
SaleInvoice: DRAWERS.INVOICE_CUSTOMIZE,
|
SaleInvoice: DRAWERS.INVOICE_CUSTOMIZE,
|
||||||
|
|||||||
@@ -6,4 +6,18 @@ export interface BrandingTemplateValues {
|
|||||||
// Company logo
|
// Company logo
|
||||||
companyLogoKey?: string;
|
companyLogoKey?: string;
|
||||||
companyLogoUri?: string;
|
companyLogoUri?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BrandingState extends ElementPreviewState {
|
||||||
|
companyName: string;
|
||||||
|
companyAddress: string;
|
||||||
|
|
||||||
|
companyLogoKey: string;
|
||||||
|
companyLogoUri: string;
|
||||||
|
|
||||||
|
primaryColor: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ElementPreviewState {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,17 +9,21 @@ import { ElementCustomizeTabsControllerProvider } from './ElementCustomizeTabsCo
|
|||||||
import { ElementCustomizeFields } from './ElementCustomizeFields';
|
import { ElementCustomizeFields } from './ElementCustomizeFields';
|
||||||
import { ElementCustomizePreview } from './ElementCustomizePreview';
|
import { ElementCustomizePreview } from './ElementCustomizePreview';
|
||||||
import { extractChildren } from '@/utils/extract-children';
|
import { extractChildren } from '@/utils/extract-children';
|
||||||
|
import { ElementPreviewState } from '../BrandingTemplates/types';
|
||||||
|
|
||||||
export interface ElementCustomizeProps<T> extends ElementCustomizeFormProps<T> {
|
export interface ElementCustomizeProps<T, Y>
|
||||||
|
extends ElementCustomizeFormProps<T, Y> {
|
||||||
|
brandingState?: Y;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ElementCustomize<T>({
|
export function ElementCustomize<T, Y extends ElementPreviewState>({
|
||||||
initialValues,
|
initialValues,
|
||||||
validationSchema,
|
validationSchema,
|
||||||
|
brandingState,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
children,
|
children,
|
||||||
}: ElementCustomizeProps<T>) {
|
}: ElementCustomizeProps<T, Y>) {
|
||||||
const PaperTemplate = React.useMemo(
|
const PaperTemplate = React.useMemo(
|
||||||
() => extractChildren(children, ElementCustomize.PaperTemplate),
|
() => extractChildren(children, ElementCustomize.PaperTemplate),
|
||||||
[children],
|
[children],
|
||||||
@@ -29,7 +33,7 @@ export function ElementCustomize<T>({
|
|||||||
[children],
|
[children],
|
||||||
);
|
);
|
||||||
|
|
||||||
const value = { PaperTemplate, CustomizeTabs };
|
const value = { PaperTemplate, CustomizeTabs, brandingState };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ElementCustomizeForm
|
<ElementCustomizeForm
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
|
import { ElementPreviewState } from '../BrandingTemplates/types';
|
||||||
|
|
||||||
interface ElementCustomizeValue {
|
interface ElementCustomizeValue {
|
||||||
PaperTemplate?: React.ReactNode;
|
PaperTemplate?: React.ReactNode;
|
||||||
CustomizeTabs: React.ReactNode;
|
CustomizeTabs: React.ReactNode;
|
||||||
|
brandingState?: ElementPreviewState;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ElementCustomizeContext = createContext<ElementCustomizeValue>(
|
const ElementCustomizeContext = createContext<ElementCustomizeValue>(
|
||||||
{} as ElementCustomizeValue,
|
{} as ElementCustomizeValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ElementCustomizeProvider: React.FC<{
|
interface ElementCustomizeProviderProps {
|
||||||
value: ElementCustomizeValue;
|
value: ElementCustomizeValue;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}> = ({ value, children }) => {
|
}
|
||||||
|
|
||||||
|
export const ElementCustomizeProvider = ({ value, children }: ElementCustomizeProviderProps) => {
|
||||||
return (
|
return (
|
||||||
<ElementCustomizeContext.Provider value={{ ...value }}>
|
<ElementCustomizeContext.Provider value={{ ...value }}>
|
||||||
{children}
|
{children}
|
||||||
@@ -29,4 +33,4 @@ export const useElementCustomizeContext = (): ElementCustomizeValue => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Formik, Form, FormikHelpers } from 'formik';
|
import { Formik, Form, FormikHelpers } from 'formik';
|
||||||
|
|
||||||
export interface ElementCustomizeFormProps<T> {
|
export interface ElementCustomizeFormProps<T, Y> {
|
||||||
initialValues?: T;
|
initialValues?: T;
|
||||||
validationSchema?: any;
|
validationSchema?: any;
|
||||||
onSubmit?: (values: T, formikHelpers: FormikHelpers<T>) => void;
|
onSubmit?: (values: T, formikHelpers: FormikHelpers<T>) => void;
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
|
|||||||
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
||||||
import { CreditNoteCustomizeGeneralField } from './CreditNoteCustomizeGeneralFields';
|
import { CreditNoteCustomizeGeneralField } from './CreditNoteCustomizeGeneralFields';
|
||||||
import { CreditNoteCustomizeContentFields } from './CreditNoteCutomizeContentFields';
|
import { CreditNoteCustomizeContentFields } from './CreditNoteCutomizeContentFields';
|
||||||
import { CreditNotePaperTemplate } from './CreditNotePaperTemplate';
|
import { CreditNotePaperTemplate, CreditNotePaperTemplateProps } from './CreditNotePaperTemplate';
|
||||||
import { CreditNoteCustomizeValues } from './types';
|
import { CreditNoteBrandingState, CreditNoteCustomizeValues } from './types';
|
||||||
import { initialValues } from './constants';
|
import { initialValues } from './constants';
|
||||||
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
||||||
import { useDrawerActions } from '@/hooks/state';
|
import { useDrawerActions } from '@/hooks/state';
|
||||||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
||||||
|
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
|
||||||
|
|
||||||
export function CreditNoteCustomizeContent() {
|
export function CreditNoteCustomizeContent() {
|
||||||
const { payload, name } = useDrawerContext();
|
const { payload, name } = useDrawerContext();
|
||||||
@@ -20,7 +21,7 @@ export function CreditNoteCustomizeContent() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrandingTemplateForm<CreditNoteCustomizeValues>
|
<BrandingTemplateForm<CreditNoteCustomizeValues, CreditNoteBrandingState>
|
||||||
resource={'CreditNote'}
|
resource={'CreditNote'}
|
||||||
templateId={templateId}
|
templateId={templateId}
|
||||||
defaultValues={initialValues}
|
defaultValues={initialValues}
|
||||||
@@ -43,6 +44,9 @@ export function CreditNoteCustomizeContent() {
|
|||||||
|
|
||||||
function CreditNotePaperTemplateFormConnected() {
|
function CreditNotePaperTemplateFormConnected() {
|
||||||
const { values } = useFormikContext<CreditNoteCustomizeValues>();
|
const { values } = useFormikContext<CreditNoteCustomizeValues>();
|
||||||
|
const { brandingState } = useElementCustomizeContext();
|
||||||
|
|
||||||
return <CreditNotePaperTemplate {...values} />;
|
const mergedProps: CreditNotePaperTemplateProps = { ...brandingState, ...values };
|
||||||
|
|
||||||
|
return <CreditNotePaperTemplate {...mergedProps} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export const initialValues = {
|
|||||||
// Address
|
// Address
|
||||||
showCustomerAddress: true,
|
showCustomerAddress: true,
|
||||||
showCompanyAddress: true,
|
showCompanyAddress: true,
|
||||||
companyAddress: '',
|
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
// Entries
|
// Entries
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
|
import { BrandingState, BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
|
||||||
|
|
||||||
|
export interface CreditNoteBrandingState extends BrandingState {}
|
||||||
|
|
||||||
export interface CreditNoteCustomizeValues extends BrandingTemplateValues {
|
export interface CreditNoteCustomizeValues extends BrandingTemplateValues {
|
||||||
// Colors
|
// Colors
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
|
|||||||
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
||||||
import { EstimateCustomizeGeneralField } from './EstimateCustomizeFieldsGeneral';
|
import { EstimateCustomizeGeneralField } from './EstimateCustomizeFieldsGeneral';
|
||||||
import { EstimateCustomizeContentFields } from './EstimateCustomizeFieldsContent';
|
import { EstimateCustomizeContentFields } from './EstimateCustomizeFieldsContent';
|
||||||
import { EstimatePaperTemplate } from './EstimatePaperTemplate';
|
import { EstimatePaperTemplate, EstimatePaperTemplateProps } from './EstimatePaperTemplate';
|
||||||
import { EstimateCustomizeValues } from './types';
|
import { EstimateBrandingState, EstimateCustomizeValues } from './types';
|
||||||
import { initialValues } from './constants';
|
import { initialValues } from './constants';
|
||||||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
||||||
import { useDrawerActions } from '@/hooks/state';
|
import { useDrawerActions } from '@/hooks/state';
|
||||||
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
||||||
|
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
|
||||||
|
|
||||||
export function EstimateCustomizeContent() {
|
export function EstimateCustomizeContent() {
|
||||||
const { payload, name } = useDrawerContext();
|
const { payload, name } = useDrawerContext();
|
||||||
@@ -19,7 +20,7 @@ export function EstimateCustomizeContent() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrandingTemplateForm<EstimateCustomizeValues>
|
<BrandingTemplateForm<EstimateCustomizeValues, EstimateBrandingState>
|
||||||
templateId={templateId}
|
templateId={templateId}
|
||||||
defaultValues={initialValues}
|
defaultValues={initialValues}
|
||||||
onSuccess={handleSuccess}
|
onSuccess={handleSuccess}
|
||||||
@@ -40,8 +41,15 @@ export function EstimateCustomizeContent() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the `EstimatePaperTemplate` component props from the form and branding states.
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
function EstimatePaperTemplateFormConnected() {
|
function EstimatePaperTemplateFormConnected() {
|
||||||
const { values } = useFormikContext<EstimateCustomizeValues>();
|
const { values } = useFormikContext<EstimateCustomizeValues>();
|
||||||
|
const { brandingState } = useElementCustomizeContext()
|
||||||
|
|
||||||
return <EstimatePaperTemplate {...values} />;
|
const mergedProps: EstimatePaperTemplateProps = { ...values, ...brandingState }
|
||||||
|
|
||||||
|
return <EstimatePaperTemplate {...mergedProps} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,11 @@ export const initialValues = {
|
|||||||
showExpirationDate: true,
|
showExpirationDate: true,
|
||||||
expirationDateLabel: 'Expiration Date',
|
expirationDateLabel: 'Expiration Date',
|
||||||
|
|
||||||
// Company name
|
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
|
||||||
|
|
||||||
// Customer address
|
// Customer address
|
||||||
showCustomerAddress: true,
|
showCustomerAddress: true,
|
||||||
|
|
||||||
// Company address
|
// Company address
|
||||||
showCompanyAddress: true,
|
showCompanyAddress: true,
|
||||||
companyAddress: '',
|
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
// Entries
|
// Entries
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
|
import { BrandingState, BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
|
||||||
|
|
||||||
|
export interface EstimateBrandingState extends BrandingState {}
|
||||||
|
|
||||||
export interface EstimateCustomizeValues extends BrandingTemplateValues {
|
export interface EstimateCustomizeValues extends BrandingTemplateValues {
|
||||||
// Colors
|
// Colors
|
||||||
@@ -20,9 +22,6 @@ export interface EstimateCustomizeValues extends BrandingTemplateValues {
|
|||||||
estimateDateLabel?: string;
|
estimateDateLabel?: string;
|
||||||
showEstimateDate?: boolean;
|
showEstimateDate?: boolean;
|
||||||
|
|
||||||
// Company name
|
|
||||||
companyName?: string;
|
|
||||||
|
|
||||||
// Addresses
|
// Addresses
|
||||||
showBilledFromAddress?: boolean;
|
showBilledFromAddress?: boolean;
|
||||||
showBillingToAddress?: boolean;
|
showBillingToAddress?: boolean;
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ import {
|
|||||||
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
||||||
import { InvoiceCustomizeGeneralField } from './InvoiceCustomizeGeneralFields';
|
import { InvoiceCustomizeGeneralField } from './InvoiceCustomizeGeneralFields';
|
||||||
import { InvoiceCustomizeContentFields } from './InvoiceCutomizeContentFields';
|
import { InvoiceCustomizeContentFields } from './InvoiceCutomizeContentFields';
|
||||||
import { InvoiceCustomizeValues } from './types';
|
import { InvoiceCustomizeFormValues, InvoiceCustomizeState } from './types';
|
||||||
import { InvoiceCustomizeSchema } from './InvoiceCustomizeForm.schema';
|
import { InvoiceCustomizeSchema } from './InvoiceCustomizeForm.schema';
|
||||||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
||||||
import { useDrawerActions } from '@/hooks/state';
|
import { useDrawerActions } from '@/hooks/state';
|
||||||
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
||||||
import { initialValues } from './constants';
|
import { initialValues } from './constants';
|
||||||
|
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice branding template customize.
|
||||||
|
*/
|
||||||
export function InvoiceCustomizeContent() {
|
export function InvoiceCustomizeContent() {
|
||||||
const { payload, name } = useDrawerContext();
|
const { payload, name } = useDrawerContext();
|
||||||
const { closeDrawer } = useDrawerActions();
|
const { closeDrawer } = useDrawerActions();
|
||||||
@@ -25,7 +29,7 @@ export function InvoiceCustomizeContent() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrandingTemplateForm<InvoiceCustomizeValues>
|
<BrandingTemplateForm<InvoiceCustomizeFormValues, InvoiceCustomizeState>
|
||||||
templateId={templateId}
|
templateId={templateId}
|
||||||
defaultValues={initialValues}
|
defaultValues={initialValues}
|
||||||
validationSchema={InvoiceCustomizeSchema}
|
validationSchema={InvoiceCustomizeSchema}
|
||||||
@@ -47,15 +51,23 @@ export function InvoiceCustomizeContent() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const withFormikProps = <P extends object>(
|
/**
|
||||||
|
* Injects the `InvoicePaperTemplate` component props from the form and branding states.
|
||||||
|
* @param Component
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
const withInvoicePreviewTemplateProps = <P extends object>(
|
||||||
Component: React.ComponentType<P>,
|
Component: React.ComponentType<P>,
|
||||||
) => {
|
) => {
|
||||||
return (props: Omit<P, keyof InvoicePaperTemplateProps>) => {
|
return (props: Omit<P, keyof InvoicePaperTemplateProps>) => {
|
||||||
const { values } = useFormikContext<InvoicePaperTemplateProps>();
|
const { values } = useFormikContext<InvoiceCustomizeFormValues>();
|
||||||
|
const { brandingState, } = useElementCustomizeContext();
|
||||||
|
|
||||||
return <Component {...(props as P)} {...values} />;
|
const mergedProps: InvoicePaperTemplateProps = { ...brandingState, ...values }
|
||||||
|
|
||||||
|
return <Component {...(props as P)} {...mergedProps} />;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const InvoicePaperTemplateFormConnected =
|
export const InvoicePaperTemplateFormConnected =
|
||||||
R.compose(withFormikProps)(InvoicePaperTemplate);
|
R.compose(withInvoicePreviewTemplateProps)(InvoicePaperTemplate);
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
|
|||||||
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
|
||||||
import { PaymentReceivedCustomizeGeneralField } from './PaymentReceivedCustomizeFieldsGeneral';
|
import { PaymentReceivedCustomizeGeneralField } from './PaymentReceivedCustomizeFieldsGeneral';
|
||||||
import { PaymentReceivedCustomizeContentFields } from './PaymentReceivedCustomizeFieldsContent';
|
import { PaymentReceivedCustomizeContentFields } from './PaymentReceivedCustomizeFieldsContent';
|
||||||
import { PaymentReceivedCustomizeValues } from './types';
|
import { PaymentReceivedCustomizeValues, PaymentReceivedPreviewState } from './types';
|
||||||
import { PaymentReceivedPaperTemplate } from './PaymentReceivedPaperTemplate';
|
import { PaymentReceivedPaperTemplate, PaymentReceivedPaperTemplateProps } from './PaymentReceivedPaperTemplate';
|
||||||
import { initialValues } from './constants';
|
import { initialValues } from './constants';
|
||||||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
||||||
import { useDrawerActions } from '@/hooks/state';
|
import { useDrawerActions } from '@/hooks/state';
|
||||||
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
||||||
|
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
|
||||||
|
|
||||||
export function PaymentReceivedCustomizeContent() {
|
export function PaymentReceivedCustomizeContent() {
|
||||||
const { payload, name } = useDrawerContext();
|
const { payload, name } = useDrawerContext();
|
||||||
@@ -20,7 +21,7 @@ export function PaymentReceivedCustomizeContent() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrandingTemplateForm<PaymentReceivedCustomizeValues>
|
<BrandingTemplateForm<PaymentReceivedCustomizeValues, PaymentReceivedPreviewState>
|
||||||
templateId={templateId}
|
templateId={templateId}
|
||||||
defaultValues={initialValues}
|
defaultValues={initialValues}
|
||||||
onSuccess={handleSuccess}
|
onSuccess={handleSuccess}
|
||||||
@@ -43,6 +44,9 @@ export function PaymentReceivedCustomizeContent() {
|
|||||||
|
|
||||||
function PaymentReceivedPaperTemplateFormConnected() {
|
function PaymentReceivedPaperTemplateFormConnected() {
|
||||||
const { values } = useFormikContext<PaymentReceivedCustomizeValues>();
|
const { values } = useFormikContext<PaymentReceivedCustomizeValues>();
|
||||||
|
const { brandingState } = useElementCustomizeContext();
|
||||||
|
|
||||||
return <PaymentReceivedPaperTemplate {...values} />;
|
const paperTemplateProps: PaymentReceivedPaperTemplateProps = { ...brandingState, ...values };
|
||||||
|
|
||||||
|
return <PaymentReceivedPaperTemplate {...paperTemplateProps} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ export const initialValues = {
|
|||||||
showPaymentReceivedDate: true,
|
showPaymentReceivedDate: true,
|
||||||
paymentReceivedDateLabel: 'Date of Issue',
|
paymentReceivedDateLabel: 'Date of Issue',
|
||||||
|
|
||||||
// Company name
|
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
|
||||||
|
|
||||||
// Customer address
|
// Customer address
|
||||||
showCompanyAddress: true,
|
showCompanyAddress: true,
|
||||||
companyAddress: '',
|
companyAddress: '',
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
|
import { BrandingState, BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
|
||||||
|
|
||||||
|
export interface PaymentReceivedPreviewState extends BrandingState {}
|
||||||
|
|
||||||
export interface PaymentReceivedCustomizeValues extends BrandingTemplateValues {
|
export interface PaymentReceivedCustomizeValues extends BrandingTemplateValues {
|
||||||
// Colors
|
// Colors
|
||||||
@@ -20,15 +22,11 @@ export interface PaymentReceivedCustomizeValues extends BrandingTemplateValues {
|
|||||||
showDueDate?: boolean;
|
showDueDate?: boolean;
|
||||||
dueDateLabel?: string;
|
dueDateLabel?: string;
|
||||||
|
|
||||||
// # Company name
|
|
||||||
companyName?: string;
|
|
||||||
|
|
||||||
// # Customer address
|
// # Customer address
|
||||||
showCustomerAddress?: boolean;
|
showCustomerAddress?: boolean;
|
||||||
|
|
||||||
// # Company address
|
// # Company address
|
||||||
showCompanyAddress?: boolean;
|
showCompanyAddress?: boolean;
|
||||||
companyAddress?: string;
|
|
||||||
billedToLabel?: string;
|
billedToLabel?: string;
|
||||||
|
|
||||||
// Entries
|
// Entries
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
|
|||||||
import { ElementCustomize } from '@/containers/ElementCustomize/ElementCustomize';
|
import { ElementCustomize } from '@/containers/ElementCustomize/ElementCustomize';
|
||||||
import { ReceiptCustomizeGeneralField } from './ReceiptCustomizeFieldsGeneral';
|
import { ReceiptCustomizeGeneralField } from './ReceiptCustomizeFieldsGeneral';
|
||||||
import { ReceiptCustomizeFieldsContent } from './ReceiptCustomizeFieldsContent';
|
import { ReceiptCustomizeFieldsContent } from './ReceiptCustomizeFieldsContent';
|
||||||
import { ReceiptPaperTemplate } from './ReceiptPaperTemplate';
|
import { ReceiptPaperTemplate, ReceiptPaperTemplateProps } from './ReceiptPaperTemplate';
|
||||||
import { ReceiptCustomizeValues } from './types';
|
import { EstimateBrandingState, ReceiptCustomizeValues } from './types';
|
||||||
import { initialValues } from './constants';
|
import { initialValues } from './constants';
|
||||||
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
|
||||||
import { useDrawerActions } from '@/hooks/state';
|
import { useDrawerActions } from '@/hooks/state';
|
||||||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
||||||
|
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
|
||||||
|
|
||||||
export function ReceiptCustomizeContent() {
|
export function ReceiptCustomizeContent() {
|
||||||
const { payload, name } = useDrawerContext();
|
const { payload, name } = useDrawerContext();
|
||||||
@@ -19,7 +20,7 @@ export function ReceiptCustomizeContent() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrandingTemplateForm<ReceiptCustomizeValues>
|
<BrandingTemplateForm<ReceiptCustomizeValues, EstimateBrandingState>
|
||||||
resource={'SaleReceipt'}
|
resource={'SaleReceipt'}
|
||||||
templateId={templateId}
|
templateId={templateId}
|
||||||
defaultValues={initialValues}
|
defaultValues={initialValues}
|
||||||
@@ -42,6 +43,9 @@ export function ReceiptCustomizeContent() {
|
|||||||
|
|
||||||
function ReceiptPaperTemplateFormConnected() {
|
function ReceiptPaperTemplateFormConnected() {
|
||||||
const { values } = useFormikContext<ReceiptCustomizeValues>();
|
const { values } = useFormikContext<ReceiptCustomizeValues>();
|
||||||
|
const { brandingState } = useElementCustomizeContext();
|
||||||
|
|
||||||
return <ReceiptPaperTemplate {...values} />;
|
const mergedProps: ReceiptPaperTemplateProps = { ...brandingState, ...values, };
|
||||||
|
|
||||||
|
return <ReceiptPaperTemplate {...mergedProps} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ export const initialValues = {
|
|||||||
showReceiptDate: true,
|
showReceiptDate: true,
|
||||||
receiptDateLabel: 'Date of Issue',
|
receiptDateLabel: 'Date of Issue',
|
||||||
|
|
||||||
// Company name
|
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
|
||||||
|
|
||||||
// Customer address
|
// Customer address
|
||||||
showCustomerAddress: true,
|
showCustomerAddress: true,
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { BrandingTemplateValues } from "@/containers/BrandingTemplates/types";
|
import { BrandingState, BrandingTemplateValues } from "@/containers/BrandingTemplates/types";
|
||||||
|
|
||||||
|
export interface EstimateBrandingState extends BrandingState {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export interface ReceiptCustomizeValues extends BrandingTemplateValues {
|
export interface ReceiptCustomizeValues extends BrandingTemplateValues {
|
||||||
// Colors
|
// Colors
|
||||||
@@ -16,9 +20,6 @@ export interface ReceiptCustomizeValues extends BrandingTemplateValues {
|
|||||||
showReceiptDate?: boolean;
|
showReceiptDate?: boolean;
|
||||||
receiptDateLabel?: string;
|
receiptDateLabel?: string;
|
||||||
|
|
||||||
// Company name
|
|
||||||
companyName?: string;
|
|
||||||
|
|
||||||
// Addresses
|
// Addresses
|
||||||
showBilledFromAddress?: boolean;
|
showBilledFromAddress?: boolean;
|
||||||
showBilledToAddress?: boolean;
|
showBilledToAddress?: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user