feat: strip state prefixes from city values and format as title case in profile displays

This commit is contained in:
pradeepkumar
2026-04-15 23:44:44 +05:30
parent d764fe02c9
commit c60978aea1
2 changed files with 25 additions and 5 deletions

View File

@@ -120,7 +120,13 @@ function ProfileCard({ profile, resolvedAvatarUrl }: ProfileCardProps) {
let cityValue: string | null = null;
let stateValue: string | null = null;
// Helper to format snake_case to Title Case, with uppercase for 2-letter state codes
// Helper to format snake_case to Title Case, with uppercase for 2-letter state codes.
// City values carry a state prefix (e.g. "ne_adams", "co_aetna_estates") — strip it.
const formatCity = (v: string) => {
const trimmed = v.trim();
const stripped = trimmed.replace(/^[a-z]{2}_/i, '');
return stripped.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');
};
const formatValue = (v: string) => {
const trimmed = v.trim();
if (/^[a-z]{2}$/i.test(trimmed)) return trimmed.toUpperCase();
@@ -144,10 +150,10 @@ function ProfileCard({ profile, resolvedAvatarUrl }: ProfileCardProps) {
if (cityField && cityField.jsonValue) {
const value = cityField.jsonValue;
if (Array.isArray(value) && value.length > 0) {
// For multiselect, join all selected values
cityValue = value.map(v => formatValue(String(v))).join(', ');
// City values carry a state prefix — strip it before joining
cityValue = value.map(v => formatCity(String(v))).join(', ');
} else if (typeof value === 'string' && value.trim()) {
cityValue = formatValue(value);
cityValue = formatCity(value);
}
}
}

View File

@@ -377,11 +377,25 @@ export function mapFieldValuesToProfileCard(fieldValues: FieldValueResponse[]):
const cityValue = getFieldValue(fieldValues, 'city');
const stateValue = getFieldValue(fieldValues, 'state');
// City values carry a state prefix (e.g. "ne_adams") — strip before formatting
const stripCityPrefix = (value: unknown): string | null => {
const toPretty = (s: string) =>
s.replace(/^[a-z]{2}_/i, '')
.split('_')
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
.join(' ');
if (Array.isArray(value) && value.length > 0) {
return value.map((v) => toPretty(String(v))).join(', ');
}
if (typeof value === 'string' && value.trim()) return toPretty(value);
return null;
};
return {
bio: description || descrption || biography || bio || '',
expertise: aboutMeExpertise || expertiseAreas || specializations || areasOfExpertise || [],
serviceAreas: serviceAreas || licensedAreas || coverageAreas || [],
city: extractAllValues(cityValue),
city: stripCityPrefix(cityValue),
state: extractAllValues(stateValue),
};
}