Skip to content

Commit

Permalink
feat: wip send invoice receipt preview
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Oct 30, 2024
1 parent 5fddd08 commit 470bfd3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ContactMailNotification {
.withGraphFetched('metadata');

return {
CompanyName: organization.metadata.name,
['Company Name']: organization.metadata.name,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ export class SendSaleInvoiceMailCommon {
tenantId,
invoiceId
);
const commonArgs =
await this.contactMailNotification.getCommonFormatArgs(tenantId);

const commonArgs = await this.contactMailNotification.getCommonFormatArgs(
tenantId
);
return {
...commonArgs,
CustomerName: invoice.customer.displayName,
InvoiceNumber: invoice.invoiceNo,
InvoiceDueAmount: invoice.dueAmountFormatted,
InvoiceDueDate: invoice.dueDateFormatted,
InvoiceDate: invoice.invoiceDateFormatted,
InvoiceAmount: invoice.totalFormatted,
OverdueDays: invoice.overdueDays,
['Customer Name']: invoice.customer.displayName,
['Invoice Number']: invoice.invoiceNo,
['Invoice DueAmount']: invoice.dueAmountFormatted,
['Invoice DueDate']: invoice.dueDateFormatted,
['Invoice Date']: invoice.invoiceDateFormatted,
['Invoice Amount']: invoice.totalFormatted,
['Overdue Days']: invoice.overdueDays,
};
};
}
12 changes: 6 additions & 6 deletions packages/server/src/services/Sales/Invoices/constants.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import config from '@/config';

export const DEFAULT_INVOICE_MAIL_SUBJECT =
'Invoice {InvoiceNumber} from {CompanyName}';
'Invoice {Invoice Number} from {Company Name}';
export const DEFAULT_INVOICE_MAIL_CONTENT = `
<p>Dear {CustomerName}</p>
<p>Dear {Customer Name}</p>
<p>Thank you for your business, You can view or print your invoice from attachements.</p>
<p>
Invoice <strong>#{InvoiceNumber}</strong><br />
Due Date : <strong>{InvoiceDueDate}</strong><br />
Amount : <strong>{InvoiceAmount}</strong></br />
Invoice <strong>#{Invoice Number}</strong><br />
Due Date : <strong>{Invoice Due Date}</strong><br />
Amount : <strong>{Invoice Amount}</strong></br />
</p>
<p>
<i>Regards</i><br />
<i>{CompanyName}</i>
<i>{Company Name}</i>
</p>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@/components';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
import { useDrawerActions } from '@/hooks/state';
import { useInvoiceMailItems } from './_hooks';
import { useInvoiceMailItems, useSendInvoiceFormatArgsOptions } from './_hooks';

// Create new account renderer.
const createNewItemRenderer = (query, active, handleClick) => {
Expand Down Expand Up @@ -65,6 +65,7 @@ export function InvoiceSendMailFields() {

const { values, setFieldValue } = useFormikContext();
const items = useInvoiceMailItems();
const argsOptions = useSendInvoiceFormatArgsOptions();

const handleClickCcBtn = (event) => {
event.preventDefault();
Expand Down Expand Up @@ -124,7 +125,7 @@ export function InvoiceSendMailFields() {
if (!textarea) return;

const { selectionStart, selectionEnd, value: text } = textarea;
const insertText = item.value;
const insertText = `{${item.value}}`;
const message =
text.substring(0, selectionStart) +
insertText +
Expand Down Expand Up @@ -224,7 +225,7 @@ export function InvoiceSendMailFields() {
<FSelect
selectedItem={'customerName'}
name={'item'}
items={[{ value: 'CustomerName', text: 'Customer Name' }]}
items={argsOptions}
onItemChange={handleTextareaChange}
popoverProps={{
fill: false,
Expand All @@ -238,7 +239,7 @@ export function InvoiceSendMailFields() {
<Icon icon={'caret-down-16'} color={'#8F99A8'} />
}
>
{text}
Insert Variable
</Button>
)}
fill={false}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useFormikContext } from 'formik';
import { camelCase, chain, defaultTo, mapKeys, upperFirst } from 'lodash';
import { useMemo } from 'react';
import { SelectOptionProps } from '@blueprintjs-formik/select';
import { chain, defaultTo, mapKeys, snakeCase, startCase } from 'lodash';
import { InvoiceSendMailFormValues } from './_types';
import { useInvoiceSendMailBoot } from './InvoiceSendMailContentBoot';
import { useMemo } from 'react';

export const useInvoiceMailItems = () => {
const { values } = useFormikContext<InvoiceSendMailFormValues>();
Expand All @@ -19,24 +20,33 @@ export const useInvoiceMailItems = () => {
.value();
};

export const useSendInvoiceMailFormatArgs = () => {
export const useSendInvoiceMailFormatArgs = (): Record<string, string> => {
const { invoiceMailOptions } = useInvoiceSendMailBoot();

return useMemo(() => {
return mapKeys(invoiceMailOptions?.formatArgs, (_, key) =>
upperFirst(camelCase(key)),
startCase(snakeCase(key).replace('_', ' ')),
);
}, [invoiceMailOptions]);
};

export const useSendInvoiceMailSubject = () => {
export const useSendInvoiceMailSubject = (): string => {
const { values } = useFormikContext<InvoiceSendMailFormValues>();
const formatArgs = useSendInvoiceMailFormatArgs();

return formatSmsMessage(values?.subject, formatArgs);
};

export const useSendInvoiceMailMessage = () => {
export const useSendInvoiceFormatArgsOptions = (): Array<SelectOptionProps> => {
const formatArgs = useSendInvoiceMailFormatArgs();

return Object.keys(formatArgs).map((key) => ({
value: key,
text: key,
}));
};

export const useSendInvoiceMailMessage = (): string => {
const { values } = useFormikContext<InvoiceSendMailFormValues>();
const formatArgs = useSendInvoiceMailFormatArgs();

Expand Down

0 comments on commit 470bfd3

Please sign in to comment.