feat: strip state prefixes from city values and format as title case in profile displays
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user