mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: wip send invoice receipt preview
This commit is contained in:
@@ -79,7 +79,7 @@ export class ContactMailNotification {
|
|||||||
.withGraphFetched('metadata');
|
.withGraphFetched('metadata');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
CompanyName: organization.metadata.name,
|
['Company Name']: organization.metadata.name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,18 +106,18 @@ export class SendSaleInvoiceMailCommon {
|
|||||||
tenantId,
|
tenantId,
|
||||||
invoiceId
|
invoiceId
|
||||||
);
|
);
|
||||||
const commonArgs =
|
const commonArgs = await this.contactMailNotification.getCommonFormatArgs(
|
||||||
await this.contactMailNotification.getCommonFormatArgs(tenantId);
|
tenantId
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...commonArgs,
|
...commonArgs,
|
||||||
CustomerName: invoice.customer.displayName,
|
['Customer Name']: invoice.customer.displayName,
|
||||||
InvoiceNumber: invoice.invoiceNo,
|
['Invoice Number']: invoice.invoiceNo,
|
||||||
InvoiceDueAmount: invoice.dueAmountFormatted,
|
['Invoice DueAmount']: invoice.dueAmountFormatted,
|
||||||
InvoiceDueDate: invoice.dueDateFormatted,
|
['Invoice DueDate']: invoice.dueDateFormatted,
|
||||||
InvoiceDate: invoice.invoiceDateFormatted,
|
['Invoice Date']: invoice.invoiceDateFormatted,
|
||||||
InvoiceAmount: invoice.totalFormatted,
|
['Invoice Amount']: invoice.totalFormatted,
|
||||||
OverdueDays: invoice.overdueDays,
|
['Overdue Days']: invoice.overdueDays,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
|
|
||||||
export const DEFAULT_INVOICE_MAIL_SUBJECT =
|
export const DEFAULT_INVOICE_MAIL_SUBJECT =
|
||||||
'Invoice {InvoiceNumber} from {CompanyName}';
|
'Invoice {Invoice Number} from {Company Name}';
|
||||||
export const DEFAULT_INVOICE_MAIL_CONTENT = `
|
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>Thank you for your business, You can view or print your invoice from attachements.</p>
|
||||||
<p>
|
<p>
|
||||||
Invoice <strong>#{InvoiceNumber}</strong><br />
|
Invoice <strong>#{Invoice Number}</strong><br />
|
||||||
Due Date : <strong>{InvoiceDueDate}</strong><br />
|
Due Date : <strong>{Invoice Due Date}</strong><br />
|
||||||
Amount : <strong>{InvoiceAmount}</strong></br />
|
Amount : <strong>{Invoice Amount}</strong></br />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<i>Regards</i><br />
|
<i>Regards</i><br />
|
||||||
<i>{CompanyName}</i>
|
<i>{Company Name}</i>
|
||||||
</p>
|
</p>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
|
||||||
import { useDrawerActions } from '@/hooks/state';
|
import { useDrawerActions } from '@/hooks/state';
|
||||||
import { useInvoiceMailItems } from './_hooks';
|
import { useInvoiceMailItems, useSendInvoiceFormatArgsOptions } from './_hooks';
|
||||||
|
|
||||||
// Create new account renderer.
|
// Create new account renderer.
|
||||||
const createNewItemRenderer = (query, active, handleClick) => {
|
const createNewItemRenderer = (query, active, handleClick) => {
|
||||||
@@ -65,6 +65,7 @@ export function InvoiceSendMailFields() {
|
|||||||
|
|
||||||
const { values, setFieldValue } = useFormikContext();
|
const { values, setFieldValue } = useFormikContext();
|
||||||
const items = useInvoiceMailItems();
|
const items = useInvoiceMailItems();
|
||||||
|
const argsOptions = useSendInvoiceFormatArgsOptions();
|
||||||
|
|
||||||
const handleClickCcBtn = (event) => {
|
const handleClickCcBtn = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -124,7 +125,7 @@ export function InvoiceSendMailFields() {
|
|||||||
if (!textarea) return;
|
if (!textarea) return;
|
||||||
|
|
||||||
const { selectionStart, selectionEnd, value: text } = textarea;
|
const { selectionStart, selectionEnd, value: text } = textarea;
|
||||||
const insertText = item.value;
|
const insertText = `{${item.value}}`;
|
||||||
const message =
|
const message =
|
||||||
text.substring(0, selectionStart) +
|
text.substring(0, selectionStart) +
|
||||||
insertText +
|
insertText +
|
||||||
@@ -224,7 +225,7 @@ export function InvoiceSendMailFields() {
|
|||||||
<FSelect
|
<FSelect
|
||||||
selectedItem={'customerName'}
|
selectedItem={'customerName'}
|
||||||
name={'item'}
|
name={'item'}
|
||||||
items={[{ value: 'CustomerName', text: 'Customer Name' }]}
|
items={argsOptions}
|
||||||
onItemChange={handleTextareaChange}
|
onItemChange={handleTextareaChange}
|
||||||
popoverProps={{
|
popoverProps={{
|
||||||
fill: false,
|
fill: false,
|
||||||
@@ -238,7 +239,7 @@ export function InvoiceSendMailFields() {
|
|||||||
<Icon icon={'caret-down-16'} color={'#8F99A8'} />
|
<Icon icon={'caret-down-16'} color={'#8F99A8'} />
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{text}
|
Insert Variable
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
fill={false}
|
fill={false}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useFormikContext } from 'formik';
|
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 { InvoiceSendMailFormValues } from './_types';
|
||||||
import { useInvoiceSendMailBoot } from './InvoiceSendMailContentBoot';
|
import { useInvoiceSendMailBoot } from './InvoiceSendMailContentBoot';
|
||||||
import { useMemo } from 'react';
|
|
||||||
|
|
||||||
export const useInvoiceMailItems = () => {
|
export const useInvoiceMailItems = () => {
|
||||||
const { values } = useFormikContext<InvoiceSendMailFormValues>();
|
const { values } = useFormikContext<InvoiceSendMailFormValues>();
|
||||||
@@ -19,24 +20,33 @@ export const useInvoiceMailItems = () => {
|
|||||||
.value();
|
.value();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSendInvoiceMailFormatArgs = () => {
|
export const useSendInvoiceMailFormatArgs = (): Record<string, string> => {
|
||||||
const { invoiceMailOptions } = useInvoiceSendMailBoot();
|
const { invoiceMailOptions } = useInvoiceSendMailBoot();
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
return mapKeys(invoiceMailOptions?.formatArgs, (_, key) =>
|
return mapKeys(invoiceMailOptions?.formatArgs, (_, key) =>
|
||||||
upperFirst(camelCase(key)),
|
startCase(snakeCase(key).replace('_', ' ')),
|
||||||
);
|
);
|
||||||
}, [invoiceMailOptions]);
|
}, [invoiceMailOptions]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSendInvoiceMailSubject = () => {
|
export const useSendInvoiceMailSubject = (): string => {
|
||||||
const { values } = useFormikContext<InvoiceSendMailFormValues>();
|
const { values } = useFormikContext<InvoiceSendMailFormValues>();
|
||||||
const formatArgs = useSendInvoiceMailFormatArgs();
|
const formatArgs = useSendInvoiceMailFormatArgs();
|
||||||
|
|
||||||
return formatSmsMessage(values?.subject, formatArgs);
|
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 { values } = useFormikContext<InvoiceSendMailFormValues>();
|
||||||
const formatArgs = useSendInvoiceMailFormatArgs();
|
const formatArgs = useSendInvoiceMailFormatArgs();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user