fix: Pdf branding templates request data

This commit is contained in:
Ahmed Bouhuolia
2024-10-07 16:03:56 +02:00
parent bbdfe00c7a
commit 9edfb83221
20 changed files with 142 additions and 72 deletions

View File

@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
import { EstimateCustomizeGeneralField } from './EstimateCustomizeFieldsGeneral';
import { EstimateCustomizeContentFields } from './EstimateCustomizeFieldsContent';
import { EstimatePaperTemplate } from './EstimatePaperTemplate';
import { EstimateCustomizeValues } from './types';
import { EstimatePaperTemplate, EstimatePaperTemplateProps } from './EstimatePaperTemplate';
import { EstimateBrandingState, EstimateCustomizeValues } from './types';
import { initialValues } from './constants';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
import { useDrawerActions } from '@/hooks/state';
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
export function EstimateCustomizeContent() {
const { payload, name } = useDrawerContext();
@@ -19,7 +20,7 @@ export function EstimateCustomizeContent() {
};
return (
<BrandingTemplateForm<EstimateCustomizeValues>
<BrandingTemplateForm<EstimateCustomizeValues, EstimateBrandingState>
templateId={templateId}
defaultValues={initialValues}
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() {
const { values } = useFormikContext<EstimateCustomizeValues>();
const { brandingState } = useElementCustomizeContext()
return <EstimatePaperTemplate {...values} />;
const mergedProps: EstimatePaperTemplateProps = { ...values, ...brandingState }
return <EstimatePaperTemplate {...mergedProps} />;
}

View File

@@ -20,15 +20,11 @@ export const initialValues = {
showExpirationDate: true,
expirationDateLabel: 'Expiration Date',
// Company name
companyName: 'Bigcapital Technology, Inc.',
// Customer address
showCustomerAddress: true,
// Company address
showCompanyAddress: true,
companyAddress: '',
billedToLabel: 'Billed To',
// Entries

View File

@@ -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 {
// Colors
@@ -20,9 +22,6 @@ export interface EstimateCustomizeValues extends BrandingTemplateValues {
estimateDateLabel?: string;
showEstimateDate?: boolean;
// Company name
companyName?: string;
// Addresses
showBilledFromAddress?: boolean;
showBillingToAddress?: boolean;