Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove empty lines from address formats #690

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,24 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
);
}

protected formattedCustomerAddress(invoice) {
return contactAddressTextFormat(invoice.customer, `{ADDRESS_1}
get customerAddressFormat() {
return `{ADDRESS_1}
{ADDRESS_2}
{CITY}, {STATE} {POSTAL_CODE}
{CITY} {STATE} {POSTAL_CODE}
{COUNTRY}
{PHONE}`);
{PHONE}`;
}

/**
* Retrieves the formatted customer address.
* @param invoice
* @returns {string}
*/
protected formattedCustomerAddress(invoice) {
return contactAddressTextFormat(
invoice.customer,
this.customerAddressFormat
);
}
}

Expand Down
14 changes: 5 additions & 9 deletions packages/server/src/system/models/TenantMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { organizationAddressTextFormat } from '@/utils/address-text-format';
import {
defaultOrganizationAddressFormat,
organizationAddressTextFormat,
} from '@/utils/address-text-format';
import BaseModel from 'models/Model';
import { getUploadedObjectUri } from '../../services/Attachments/utils';

Expand Down Expand Up @@ -67,14 +70,7 @@ export default class TenantMetadata extends BaseModel {
* @returns {string}
*/
public get addressTextFormatted() {
const defaultMessage = `<strong>{ORGANIZATION_NAME}</strong>
{ADDRESS_1}
{ADDRESS_2}
{CITY}, {STATE} {POSTAL_CODE}
{COUNTRY}
{PHONE}
`;
return organizationAddressTextFormat(defaultMessage, {
return organizationAddressTextFormat(defaultOrganizationAddressFormat, {
organizationName: this.name,
address1: this.address?.address1,
address2: this.address?.address2,
Expand Down
24 changes: 13 additions & 11 deletions packages/server/src/utils/address-text-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ interface OrganizationAddressFormatArgs {
phone?: string;
}

const defaultMessage = `
<strong>{ORGANIZATION_NAME}</strong>
{ADDRESS_1}
{ADDRESS_2}
{CITY}, {STATE} {POSTAL_CODE}
{COUNTRY}
{PHONE}
export const defaultOrganizationAddressFormat = `
<strong>{ORGANIZATION_NAME}</strong>
{ADDRESS_1}
{ADDRESS_2}
{CITY} {STATE} {POSTAL_CODE}
{COUNTRY}
{PHONE}
`;
/**
* Formats the address text based on the provided message and arguments.
Expand All @@ -36,7 +36,9 @@ const formatText = (message: string, replacements: Record<string, string>) => {
},
message
);
formattedMessage = formattedMessage.replace(/\n{2,}/g, '\n').trim();
// Removes any empty lines.
formattedMessage = formattedMessage.replace(/^\s*[\r\n]/gm, '');
formattedMessage = formattedMessage.replace(/\n{2,}/g, '\n');
formattedMessage = formattedMessage.replace(/\n/g, '<br />');
formattedMessage = formattedMessage.trim();

Expand Down Expand Up @@ -72,17 +74,17 @@ interface ContactAddressTextFormatArgs {
phone?: string;
}

const contactFormatMessage = `{CONTACT_NAME}
export const defaultContactAddressFormat = `{CONTACT_NAME}
{ADDRESS_1}
{ADDRESS_2}
{CITY}, {STATE} {POSTAL_CODE}
{CITY} {STATE} {POSTAL_CODE}
{COUNTRY}
{PHONE}
`;

export const contactAddressTextFormat = (
contact: IContact,
message: string = contactFormatMessage
message: string = defaultContactAddressFormat
) => {
const args = {
displayName: contact.displayName,
Expand Down
Loading