fix: send invoice receipt addresses

This commit is contained in:
Ahmed Bouhuolia
2024-11-06 14:04:29 +02:00
parent de8a867d33
commit c32aff82ee
6 changed files with 55 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ export default class Mail {
to: string | string[]; to: string | string[];
cc: string | string[]; cc: string | string[];
bcc: string | string[]; bcc: string | string[];
replyTo: string | string[];
from: string = `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`; from: string = `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`;
data: { [key: string]: string | number }; data: { [key: string]: string | number };
attachments: IMailAttachment[]; attachments: IMailAttachment[];
@@ -27,6 +28,7 @@ export default class Mail {
subject: this.subject, subject: this.subject,
html: this.html, html: this.html,
attachments: this.attachments, attachments: this.attachments,
replyTo: this.replyTo,
}; };
} }
@@ -74,6 +76,11 @@ export default class Mail {
return this; return this;
} }
setReplyTo(replyTo: string | string[]) {
this.replyTo = replyTo;
return this;
}
/** /**
* Sets from address to the mail. * Sets from address to the mail.
* @param {string} from * @param {string} from

View File

@@ -39,9 +39,19 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer {
'companyLogoUri', 'companyLogoUri',
'primaryColor', 'primaryColor',
'customerName',
]; ];
}; };
/**
* Retrieves the customer name of the invoice.
* @returns {string}
*/
protected customerName = (invoice) => {
return invoice.customer.displayName;
};
/** /**
* Retrieves the company name. * Retrieves the company name.
* @returns {string} * @returns {string}

View File

@@ -153,6 +153,13 @@ export function InvoiceSendMailFields() {
[setFieldValue], [setFieldValue],
); );
const handleTagInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
// Prevent the form from submitting when the user presses the Enter key
if (e.key === 'Enter') {
e.preventDefault();
}
};
return ( return (
<Stack <Stack
bg="white" bg="white"
@@ -174,6 +181,9 @@ export function InvoiceSendMailFields() {
tagProps: { round: true, minimal: true, large: true }, tagProps: { round: true, minimal: true, large: true },
rightElement: rightElementsToField, rightElement: rightElementsToField,
large: true, large: true,
inputProps: {
onKeyDown: handleTagInputKeyDown,
},
}} }}
createNewItemRenderer={createNewItemRenderer} createNewItemRenderer={createNewItemRenderer}
createNewItemFromQuery={createNewItemFromQuery} createNewItemFromQuery={createNewItemFromQuery}
@@ -192,6 +202,9 @@ export function InvoiceSendMailFields() {
tagInputProps={{ tagInputProps={{
tagProps: { round: true, minimal: true, large: true }, tagProps: { round: true, minimal: true, large: true },
large: true, large: true,
inputProps: {
onKeyDown: handleTagInputKeyDown,
},
}} }}
createNewItemRenderer={createNewItemRenderer} createNewItemRenderer={createNewItemRenderer}
createNewItemFromQuery={createNewItemFromQuery} createNewItemFromQuery={createNewItemFromQuery}
@@ -211,6 +224,9 @@ export function InvoiceSendMailFields() {
tagInputProps={{ tagInputProps={{
tagProps: { round: true, minimal: true, large: true }, tagProps: { round: true, minimal: true, large: true },
large: true, large: true,
inputProps: {
onKeyDown: handleTagInputKeyDown,
},
}} }}
createNewItemRenderer={createNewItemRenderer} createNewItemRenderer={createNewItemRenderer}
createNewItemFromQuery={createNewItemFromQuery} createNewItemFromQuery={createNewItemFromQuery}
@@ -244,6 +260,9 @@ export function InvoiceSendMailFields() {
fill: false, fill: false,
position: Position.BOTTOM_LEFT, position: Position.BOTTOM_LEFT,
minimal: true, minimal: true,
inputProps: {
onKeyDown: handleTagInputKeyDown,
},
}} }}
input={() => ( input={() => (
<Button <Button

View File

@@ -4,8 +4,8 @@ export const InvoiceSendMailFormSchema = Yup.object().shape({
subject: Yup.string().required('Subject is required'), subject: Yup.string().required('Subject is required'),
message: Yup.string().required('Message is required'), message: Yup.string().required('Message is required'),
to: Yup.array() to: Yup.array()
.of(Yup.string().email('Invalid email')) .of(Yup.string().email('Invalid email address'))
.required('To address is required'), .required('To address is required'),
cc: Yup.array().of(Yup.string().email('Invalid email')), cc: Yup.array().of(Yup.string().email('Invalid email address')),
bcc: Yup.array().of(Yup.string().email('Invalid email')), bcc: Yup.array().of(Yup.string().email('Invalid email address')),
}); });

View File

@@ -8,6 +8,7 @@ export function InvoiceSendMailHeaderPreview() {
const mailSubject = useSendInvoiceMailSubject(); const mailSubject = useSendInvoiceMailSubject();
const { invoiceMailState } = useInvoiceSendMailBoot(); const { invoiceMailState } = useInvoiceSendMailBoot();
const toAddresses = useMailHeaderToAddresses(); const toAddresses = useMailHeaderToAddresses();
const fromAddresses = useMailHeaderFromAddresses();
return ( return (
<Stack <Stack
@@ -44,14 +45,12 @@ export function InvoiceSendMailHeaderPreview() {
<Stack spacing={2}> <Stack spacing={2}>
<Group spacing={2}> <Group spacing={2}>
<Box fontWeight={600}>Ahmed </Box> <Box fontWeight={600}>{invoiceMailState?.companyName} </Box>
<Box color={'#738091'}> <Box color={'#738091'}>{fromAddresses}</Box>
&lt;messaging-service@post.bigcapital.app&gt;
</Box>
</Group> </Group>
<Box fontSize={'sm'} color={'#738091'}> <Box fontSize={'sm'} color={'#738091'}>
Reply to: {invoiceMailState?.companyName} {toAddresses}; Send to: {invoiceMailState?.customerName} {toAddresses};
</Box> </Box>
</Stack> </Stack>
</Group> </Group>
@@ -80,3 +79,13 @@ export const useMailHeaderToAddresses = () => {
return useMemo(() => to?.map((email) => '<' + email + '>').join(' '), [to]); return useMemo(() => to?.map((email) => '<' + email + '>').join(' '), [to]);
}; };
export const useMailHeaderFromAddresses = () => {
const { invoiceMailState } = useInvoiceSendMailBoot();
const from = invoiceMailState?.from;
return useMemo(
() => from?.map((email) => '<' + email + '>').join(', '),
[from],
);
};

View File

@@ -402,6 +402,8 @@ export interface GetSaleInvoiceDefaultOptionsResponse {
companyName: string; companyName: string;
companyLogoUri: string; companyLogoUri: string;
customerName: string;
dueDate: string; dueDate: string;
dueDateFormatted: string; dueDateFormatted: string;