templateId={templateId}
defaultValues={initialValues}
validationSchema={InvoiceCustomizeSchema}
@@ -47,15 +51,23 @@ export function InvoiceCustomizeContent() {
);
}
-const withFormikProps = (
+/**
+ * Injects the `InvoicePaperTemplate` component props from the form and branding states.
+ * @param Component
+ * @returns {JSX.Element}
+ */
+const withInvoicePreviewTemplateProps =
(
Component: React.ComponentType
,
) => {
return (props: Omit
) => {
- const { values } = useFormikContext();
+ const { values } = useFormikContext();
+ const { brandingState, } = useElementCustomizeContext();
- return ;
+ const mergedProps: InvoicePaperTemplateProps = { ...brandingState, ...values }
+
+ return ;
};
};
export const InvoicePaperTemplateFormConnected =
- R.compose(withFormikProps)(InvoicePaperTemplate);
+ R.compose(withInvoicePreviewTemplateProps)(InvoicePaperTemplate);
diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/constants.ts b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/constants.ts
index 1d9a4dcb8..015bb7255 100644
--- a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/constants.ts
+++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/constants.ts
@@ -16,19 +16,17 @@ export const initialValues = {
showInvoiceNumber: true,
invoiceNumberLabel: 'Invoice number',
+ // Issue date
showDateIssue: true,
dateIssueLabel: 'Date of Issue',
+ // Due date.
showDueDate: true,
dueDateLabel: 'Due Date',
- // Company name
- companyName: 'Bigcapital Technology, Inc.',
-
// Addresses
showCustomerAddress: true,
showCompanyAddress: true,
- companyAddress: '',
billedToLabel: 'Billed To',
// Entries
@@ -41,6 +39,7 @@ export const initialValues = {
showSubtotal: true,
subtotalLabel: 'Subtotal',
+ // Discount
showDiscount: true,
discountLabel: 'Discount',
@@ -52,6 +51,7 @@ export const initialValues = {
paymentMadeLabel: 'Payment Made',
showPaymentMade: true,
+ // Due amount
dueAmountLabel: 'Due Amount',
showDueAmount: true,
@@ -59,6 +59,7 @@ export const initialValues = {
termsConditionsLabel: 'Terms & Conditions',
showTermsConditions: true,
+ // Statement
statementLabel: 'Statement',
showStatement: true,
};
diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/types.ts b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/types.ts
index 6a2d6839e..e67d755ff 100644
--- a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/types.ts
+++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/types.ts
@@ -1,6 +1,8 @@
-import { BrandingTemplateValues } from "@/containers/BrandingTemplates/types";
+import { BrandingState, BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
-export interface InvoiceCustomizeValues extends BrandingTemplateValues {
+export interface InvoiceCustomizeState extends BrandingState {}
+
+export interface InvoiceCustomizeFormValues extends BrandingTemplateValues {
// Colors
primaryColor?: string;
secondaryColor?: string;
@@ -14,15 +16,14 @@ export interface InvoiceCustomizeValues extends BrandingTemplateValues {
showInvoiceNumber?: boolean;
invoiceNumberLabel?: string;
+ // Date issue
showDateIssue?: boolean;
dateIssueLabel?: string;
+ // Due date
showDueDate?: boolean;
dueDateLabel?: string;
- // Company name
- companyName?: string;
-
// Addresses
showBilledFromAddress?: boolean;
showBillingToAddress?: boolean;
@@ -38,6 +39,7 @@ export interface InvoiceCustomizeValues extends BrandingTemplateValues {
showSubtotal?: boolean;
subtotalLabel?: string;
+ // Discount
showDiscount?: boolean;
discountLabel?: string;
diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/utils.ts b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/utils.ts
index d9a1979da..081eae5cc 100644
--- a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/utils.ts
+++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/utils.ts
@@ -1,6 +1,5 @@
import { omit } from 'lodash';
-import { useFormikContext } from 'formik';
-import { InvoiceCustomizeValues } from './types';
+import { InvoiceCustomizeFormValues } from './types';
import {
CreatePdfTemplateValues,
EditPdfTemplateValues,
@@ -10,7 +9,7 @@ import { initialValues } from './constants';
import { useBrandingTemplateBoot } from '@/containers/BrandingTemplates/BrandingTemplateBoot';
export const transformToEditRequest = (
- values: InvoiceCustomizeValues,
+ values: InvoiceCustomizeFormValues,
): EditPdfTemplateValues => {
return {
templateName: values.templateName,
@@ -19,7 +18,7 @@ export const transformToEditRequest = (
};
export const transformToNewRequest = (
- values: InvoiceCustomizeValues,
+ values: InvoiceCustomizeFormValues,
): CreatePdfTemplateValues => {
return {
resource: 'SaleInvoice',
@@ -28,7 +27,7 @@ export const transformToNewRequest = (
};
};
-export const useInvoiceCustomizeInitialValues = (): InvoiceCustomizeValues => {
+export const useInvoiceCustomizeInitialValues = (): InvoiceCustomizeFormValues => {
const { pdfTemplate } = useBrandingTemplateBoot();
const defaultPdfTemplate = {
@@ -40,6 +39,6 @@ export const useInvoiceCustomizeInitialValues = (): InvoiceCustomizeValues => {
...(transformToForm(
defaultPdfTemplate,
initialValues,
- ) as InvoiceCustomizeValues),
+ ) as InvoiceCustomizeFormValues),
};
};
diff --git a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedCustomizeContent.tsx b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedCustomizeContent.tsx
index b08b5979e..6c42ff3a1 100644
--- a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedCustomizeContent.tsx
+++ b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedCustomizeContent.tsx
@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
import { PaymentReceivedCustomizeGeneralField } from './PaymentReceivedCustomizeFieldsGeneral';
import { PaymentReceivedCustomizeContentFields } from './PaymentReceivedCustomizeFieldsContent';
-import { PaymentReceivedCustomizeValues } from './types';
-import { PaymentReceivedPaperTemplate } from './PaymentReceivedPaperTemplate';
+import { PaymentReceivedCustomizeValues, PaymentReceivedPreviewState } from './types';
+import { PaymentReceivedPaperTemplate, PaymentReceivedPaperTemplateProps } from './PaymentReceivedPaperTemplate';
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 PaymentReceivedCustomizeContent() {
const { payload, name } = useDrawerContext();
@@ -20,7 +21,7 @@ export function PaymentReceivedCustomizeContent() {
};
return (
-
+
templateId={templateId}
defaultValues={initialValues}
onSuccess={handleSuccess}
@@ -43,6 +44,9 @@ export function PaymentReceivedCustomizeContent() {
function PaymentReceivedPaperTemplateFormConnected() {
const { values } = useFormikContext();
+ const { brandingState } = useElementCustomizeContext();
- return ;
+ const paperTemplateProps: PaymentReceivedPaperTemplateProps = { ...brandingState, ...values };
+
+ return ;
}
diff --git a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts
index f4d2c1ea3..8ed1551fe 100644
--- a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts
+++ b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts
@@ -18,12 +18,8 @@ export const initialValues = {
showPaymentReceivedDate: true,
paymentReceivedDateLabel: 'Date of Issue',
- // Company name
- companyName: 'Bigcapital Technology, Inc.',
-
// Customer address
showCompanyAddress: true,
- companyAddress: '',
// Company address
showCustomerAddress: true,
diff --git a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/types.ts b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/types.ts
index f26371cc6..20ff06cb2 100644
--- a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/types.ts
+++ b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/types.ts
@@ -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 {
// Colors
@@ -20,15 +22,11 @@ export interface PaymentReceivedCustomizeValues extends BrandingTemplateValues {
showDueDate?: boolean;
dueDateLabel?: string;
- // # Company name
- companyName?: string;
-
// # Customer address
showCustomerAddress?: boolean;
// # Company address
showCompanyAddress?: boolean;
- companyAddress?: string;
billedToLabel?: string;
// Entries
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptCustomizeContent.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptCustomizeContent.tsx
index 298e8f879..dd6ffc09c 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptCustomizeContent.tsx
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptCustomizeContent.tsx
@@ -2,12 +2,13 @@ import { useFormikContext } from 'formik';
import { ElementCustomize } from '@/containers/ElementCustomize/ElementCustomize';
import { ReceiptCustomizeGeneralField } from './ReceiptCustomizeFieldsGeneral';
import { ReceiptCustomizeFieldsContent } from './ReceiptCustomizeFieldsContent';
-import { ReceiptPaperTemplate } from './ReceiptPaperTemplate';
-import { ReceiptCustomizeValues } from './types';
+import { ReceiptPaperTemplate, ReceiptPaperTemplateProps } from './ReceiptPaperTemplate';
+import { EstimateBrandingState, ReceiptCustomizeValues } from './types';
import { initialValues } from './constants';
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
import { useDrawerActions } from '@/hooks/state';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
+import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
export function ReceiptCustomizeContent() {
const { payload, name } = useDrawerContext();
@@ -19,7 +20,7 @@ export function ReceiptCustomizeContent() {
};
return (
-
+
resource={'SaleReceipt'}
templateId={templateId}
defaultValues={initialValues}
@@ -42,6 +43,9 @@ export function ReceiptCustomizeContent() {
function ReceiptPaperTemplateFormConnected() {
const { values } = useFormikContext();
+ const { brandingState } = useElementCustomizeContext();
- return ;
+ const mergedProps: ReceiptPaperTemplateProps = { ...brandingState, ...values, };
+
+ return ;
}
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts
index cee1327f1..bf340bbd2 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts
@@ -18,14 +18,10 @@ export const initialValues = {
showReceiptDate: true,
receiptDateLabel: 'Date of Issue',
- // Company name
- companyName: 'Bigcapital Technology, Inc.',
-
// Customer address
showCustomerAddress: true,
// Company address
- companyAddress: '',
showCompanyAddress: true,
billedToLabel: 'Billed To',
diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/types.ts b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/types.ts
index 1fe5f2bf0..31b72081d 100644
--- a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/types.ts
+++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/types.ts
@@ -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 {
// Colors
@@ -16,9 +20,6 @@ export interface ReceiptCustomizeValues extends BrandingTemplateValues {
showReceiptDate?: boolean;
receiptDateLabel?: string;
- // Company name
- companyName?: string;
-
// Addresses
showBilledFromAddress?: boolean;
showBilledToAddress?: boolean;