Skip to content

Commit

Permalink
Merge pull request #739 from bigcapitalhq/clean-up-invoice-mail-recei…
Browse files Browse the repository at this point in the history
…pt-preview-component

fix: clean up ivnoice mail receipt preview component
  • Loading branch information
abouolia authored Nov 4, 2024
2 parents 2d18a65 + 5121879 commit b3ebbb4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 50 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useMemo, ComponentType } from 'react';
import { css } from '@emotion/css';
import { Box } from '@/components';
import {
InvoiceMailReceiptPreview,
InvoiceMailReceiptPreviewProps,
} from '../InvoiceCustomize/InvoiceMailReceiptPreview';
import { useInvoiceSendMailBoot } from './InvoiceSendMailContentBoot';
import { InvoiceSendMailPreviewWithHeader } from './InvoiceSendMailHeaderPreview';
import { useSendInvoiceMailMessage } from './_hooks';

export function InvoiceMailReceiptPreviewConnected() {
return (
<InvoiceSendMailPreviewWithHeader>
<Box px={4} pt={8} pb={16}>
<InvoiceMailReceiptPreviewWithProps
className={css`
margin: 0 auto;
`}
/>
</Box>
</InvoiceSendMailPreviewWithHeader>
);
}

/**
* Injects props from invoice mail state into the InvoiceMailReceiptPreview component.
*/
const withInvoiceMailReceiptPreviewProps = <
P extends InvoiceMailReceiptPreviewProps,
>(
WrappedComponent: ComponentType<P & InvoiceMailReceiptPreviewProps>,
) => {
return function WithInvoiceMailReceiptPreviewProps(props: P) {
const message = useSendInvoiceMailMessage();
const { invoiceMailState } = useInvoiceSendMailBoot();

const items = useMemo(
() =>
invoiceMailState?.entries?.map((entry: any) => ({
quantity: entry.quantity,
total: entry.totalFormatted,
label: entry.name,
})),
[invoiceMailState?.entries],
);

const mailReceiptPreviewProps = {
companyName: invoiceMailState?.companyName,
companyLogoUri: invoiceMailState?.companyLogoUri,
primaryColor: invoiceMailState?.primaryColor,
total: invoiceMailState?.totalFormatted,
dueDate: invoiceMailState?.dueDateFormatted,
dueAmount: invoiceMailState?.dueAmountFormatted,
invoiceNumber: invoiceMailState?.invoiceNo,
items,
message,
};
return <WrappedComponent {...mailReceiptPreviewProps} {...props} />;
};
};

export const InvoiceMailReceiptPreviewWithProps =
withInvoiceMailReceiptPreviewProps(InvoiceMailReceiptPreview);
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-nocheck
import React from 'react';
import * as R from 'ramda';
import { Drawer, DrawerSuspense } from '@/components';
import withDrawers from '@/containers/Drawer/withDrawers';
import React from 'react';

const InvoiceSendMailContent = React.lazy(() =>
import('./InvoiceSendMailContent').then((module) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { css } from '@emotion/css';
import { Tab, Tabs } from '@blueprintjs/core';
import { Stack } from '@/components';

const InvoiceMailReceiptPreviewConneceted = lazy(() =>
import('./InvoiceMailReceiptPreviewConnected.').then((module) => ({
default: module.InvoiceMailReceiptPreviewConneceted,
const InvoiceMailReceiptPreviewConnected = lazy(() =>
import('./InvoiceMailReceiptPreviewConnected').then((module) => ({
default: module.InvoiceMailReceiptPreviewConnected,
})),
);
const InvoiceSendPdfPreviewConnected = lazy(() =>
Expand Down Expand Up @@ -51,7 +51,7 @@ export function InvoiceSendMailPreview() {
title={'Payment page'}
panel={
<Suspense>
<InvoiceMailReceiptPreviewConneceted />
<InvoiceMailReceiptPreviewConnected />
</Suspense>
}
/>
Expand Down

0 comments on commit b3ebbb4

Please sign in to comment.