From c60978aea19d72375373b182985c496b473c07c0 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Wed, 15 Apr 2026 23:44:44 +0530 Subject: [PATCH] feat: strip state prefixes from city values and format as title case in profile displays --- src/app/(user)/user/profiles/page.tsx | 14 ++++++++++---- src/utils/profileDataMapper.ts | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/app/(user)/user/profiles/page.tsx b/src/app/(user)/user/profiles/page.tsx index ea95955..e71f85b 100644 --- a/src/app/(user)/user/profiles/page.tsx +++ b/src/app/(user)/user/profiles/page.tsx @@ -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); } } } diff --git a/src/utils/profileDataMapper.ts b/src/utils/profileDataMapper.ts index 42dfd0f..31cda9f 100644 --- a/src/utils/profileDataMapper.ts +++ b/src/utils/profileDataMapper.ts @@ -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), }; }