Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | 118x 118x 58x 53x 43x 9x 34x 118x 101x 97x 10x 87x 87x 87x 87x 2x 85x 85x 2x 1x 83x 83x 83x 83x 118x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 1x 1x 1x 64x 3x 61x 61x 61x 118x | import { ChangeItem, GroupType } from "@services/api/changelog/changelog";
import { formatInUTCMoment } from "@utils/date.helpers";
import { toCountryName } from "@hooks/helpers";
import {
businessTypes,
BusinessUnionTypes,
} from "@common/BusinessProfileInputs/BusinessTypeSelect";
import { betterPhoneNumber } from "@components/Merchants/MerchantPreview/hooks/useGetSectionItems";
import { toEnFormatWithDecimal } from "@utils/index";
const LABEL_MAP: Record<string, string> = {
profit: "For Profit Business",
non_profit: "Non-Profit Organization",
individual: "Individual",
crowdfunding: "Crowdfunding",
};
// `data` is read straight off an audit row, so every access is optional: a row
// can be missing entirely (empty fieldChanges) or lack a fieldName (GB-21601).
export const createCustomAction = (data?: ChangeItem) => {
if (!data?.oldValue && data?.operation === "insert") return "insert";
else if (!data?.oldValue && data?.newValue) return "add";
else if (
(data?.oldValue && !data?.newValue) ||
(!data?.oldValue && !data?.newValue) ||
(data?.fieldName?.includes("Phone") &&
data?.newValue?.toString().length === 1)
)
return "remove";
else return "update";
};
export const formatFieldValue = (value: any, field?: string) => {
if (!field) return value;
if (field.includes("date")) {
// Date fields arrive either as ISO "YYYY-MM-DD" strings (BE date.Date, e.g.
// a newly-changed PAH's Date of Birth) or as legacy Unix-seconds integers
// (older audit rows, e.g. Business Owner DOB). formatInUTCMoment handles
// both and returns "" for empty values, so a single row can no longer crash
// the changelog with "RangeError: Invalid time value" (PAH006).
return formatInUTCMoment(value);
}
Iif (
field.includes("citizenship country") ||
field.includes("country of residence") ||
field.includes("citizenship")
) {
return toCountryName(value);
}
Iif (field.includes("ticket amount") || field.includes("annual revenue")) {
return `${toEnFormatWithDecimal((value || 0) / 100)} USD`;
}
Iif (["tax id"].includes(field)) {
return `••••••${value?.slice(-4)}`;
}
if (field?.includes("account number")) {
return !!value && `•••• ${value?.slice(-4)}`;
}
Iif (["business type"].includes(field)) {
return businessTypes[value as BusinessUnionTypes];
}
if (["customer service", "phone number"].includes(field)) {
if (value == null || value === "") return value;
return `+${betterPhoneNumber(String(value).replace("+", ""))}`;
}
Iif (["ownership"].includes(field)) {
return `${value}%`;
}
Iif (field.includes("merchant class")) {
return typeof value === "string" ? LABEL_MAP[value] : value;
}
Iif (field.includes("document/passport") && value !== "passport_id") {
return !!value && `xxxxx${value}`;
}
return value;
};
export const formatFieldLabel = (
field: string | number | undefined,
category?: GroupType,
) => {
Iif (typeof field === "number" || !field) return field;
Iif (field.includes("tax id")) {
return capitalizePartOfString(field, -2);
}
Iif (field.includes("customer service")) {
if (category === "Merchant File") return "merchant phone number";
return `${field} phone number`;
}
Iif (field.includes("doing business as (dba)")) {
return capitalizePartOfString(field, -4);
}
Iif (field.includes("countries serviced outside the usa/canada")) {
return "countries where business is conducted outside the USA";
}
Iif (field.includes("citizenship country")) {
return "country of citizenship";
}
Iif (field.includes("date business opened")) {
return "business creation date";
}
Iif (field.includes("goods and/or services description")) {
return "goods and/or services description";
}
Iif (field.includes("permalink")) {
return "GivePayments URL";
}
if (field.includes("phone number")) {
Iif (category === "Primary Account Holder") return "mobile phone";
Iif (category === "Business Profile") return "business phone number";
return field;
}
if (field.includes("legal name")) {
return "legal name";
}
Iif (field.includes("merchant class")) {
return "classification";
}
Iif (field.includes("account type") || field.includes("account number")) {
return `bank ${field}`;
}
return field;
};
export const capitalizePartOfString = (
value: string,
startingIndex: number,
) => {
return (
value.slice(0, startingIndex) + value.slice(startingIndex).toUpperCase()
);
};
|