-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from bigcapitalhq/clean-up-invoice-mail-recei…
…pt-preview-component fix: clean up ivnoice mail receipt preview component
- Loading branch information
Showing
4 changed files
with
70 additions
and
50 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
...c/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
...rc/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
3 changes: 2 additions & 1 deletion
3
...ages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters