mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: Hook up customer/company address to invoice preview of payment page
This commit is contained in:
@@ -8,17 +8,27 @@ interface OrganizationAddressFormatArgs {
|
||||
city?: string;
|
||||
country?: string;
|
||||
postalCode?: string;
|
||||
phone?: string;
|
||||
}
|
||||
|
||||
const defaultMessage = `
|
||||
<strong>{ORGANIZATION_NAME}</strong>
|
||||
{ADDRESS_1},
|
||||
{ADDRESS_2},
|
||||
{CITY} {STATE},
|
||||
{POSTAL_CODE},
|
||||
{ADDRESS_1}
|
||||
{ADDRESS_2}
|
||||
{CITY}, {STATE} {POSTAL_CODE}
|
||||
{COUNTRY}
|
||||
{PHONE}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Formats the address text based on the provided message and arguments.
|
||||
* This function replaces placeholders in the message with actual values
|
||||
* from the OrganizationAddressFormatArgs. It ensures that the final
|
||||
* formatted message is clean and free of excessive newlines.
|
||||
*
|
||||
* @param {string} message - The message template containing placeholders.
|
||||
* @param {Record<string, string>} args - The arguments containing the values to replace in the message.
|
||||
* @returns {string} - The formatted address text.
|
||||
*/
|
||||
const formatText = (message: string, replacements: Record<string, string>) => {
|
||||
let formattedMessage = Object.entries(replacements).reduce(
|
||||
(msg, [key, value]) => {
|
||||
@@ -26,9 +36,11 @@ const formatText = (message: string, replacements: Record<string, string>) => {
|
||||
},
|
||||
message
|
||||
);
|
||||
formattedMessage = formattedMessage.replace(/\n{2,}/g, '\n').trim();
|
||||
formattedMessage = formattedMessage.replace(/\n/g, '<br />');
|
||||
formattedMessage = formattedMessage.trim();
|
||||
|
||||
return formattedMessage.trim();
|
||||
return formattedMessage;
|
||||
};
|
||||
|
||||
export const organizationAddressTextFormat = (
|
||||
@@ -43,6 +55,7 @@ export const organizationAddressTextFormat = (
|
||||
STATE: args.state || '',
|
||||
POSTAL_CODE: args.postalCode || '',
|
||||
COUNTRY: args.country || '',
|
||||
PHONE: args.phone || '',
|
||||
};
|
||||
return formatText(message, replacements);
|
||||
};
|
||||
@@ -56,15 +69,15 @@ interface ContactAddressTextFormatArgs {
|
||||
city?: string;
|
||||
address2?: string;
|
||||
address1?: string;
|
||||
phone?: string;
|
||||
}
|
||||
|
||||
const contactFormatMessage = `{CONTACT_NAME}
|
||||
{ADDRESS_1}
|
||||
{ADDRESS_2}
|
||||
{CITY} {STATE}
|
||||
{POSTAL_CODE}
|
||||
{CITY}, {STATE} {POSTAL_CODE}
|
||||
{COUNTRY}
|
||||
{EMAIL}
|
||||
{PHONE}
|
||||
`;
|
||||
|
||||
export const contactAddressTextFormat = (
|
||||
@@ -80,6 +93,7 @@ export const contactAddressTextFormat = (
|
||||
postalCode: contact?.billingAddressPostcode,
|
||||
city: contact?.billingAddressCity,
|
||||
email: contact?.email,
|
||||
phone: contact?.billingAddressPhone,
|
||||
} as ContactAddressTextFormatArgs;
|
||||
|
||||
const replacements: Record<string, string> = {
|
||||
@@ -91,6 +105,7 @@ export const contactAddressTextFormat = (
|
||||
POSTAL_CODE: args.postalCode || '',
|
||||
COUNTRY: args.country || '',
|
||||
EMAIL: args?.email || '',
|
||||
PHONE: args?.phone || '',
|
||||
};
|
||||
return formatText(message, replacements);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user