fix
This commit is contained in:
@@ -270,26 +270,55 @@ export default function CmsPage() {
|
|||||||
const subtitle = agent?.agentType?.name || agent?.headline || '';
|
const subtitle = agent?.agentType?.name || agent?.headline || '';
|
||||||
const imageUrl = profile?.avatar || '';
|
const imageUrl = profile?.avatar || '';
|
||||||
|
|
||||||
|
// Helper to format snake_case to Title Case
|
||||||
|
const formatLabel = (v: string) =>
|
||||||
|
v.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');
|
||||||
|
|
||||||
|
// Helper to stringify a field value
|
||||||
|
const valueToString = (val: any): string => {
|
||||||
|
if (val == null) return '';
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
return val.map((v) => (typeof v === 'object' ? (v.label || v.name || JSON.stringify(v)) : formatLabel(String(v)))).join(', ');
|
||||||
|
}
|
||||||
|
if (typeof val === 'object') return val.label || val.name || JSON.stringify(val);
|
||||||
|
return formatLabel(String(val));
|
||||||
|
};
|
||||||
|
|
||||||
// Fetch full agent profile with field values for location/experience/expertise
|
// Fetch full agent profile with field values for location/experience/expertise
|
||||||
let location = [profile?.city, profile?.state].filter(Boolean).join(', ');
|
let location = [profile?.city, profile?.state].filter(Boolean).join(', ');
|
||||||
let experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : '';
|
let experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : '';
|
||||||
let expertise: string[] = [];
|
let expertise: string[] = [];
|
||||||
|
|
||||||
|
// Specific slugs to look for (matches profile field seed)
|
||||||
|
const EXPERIENCE_SLUGS = ['years_in_business', 'years_of_experience'];
|
||||||
|
const EXPERTISE_SLUGS = ['about_me_expertise', 'expertise_areas'];
|
||||||
|
|
||||||
if (agent?.id) {
|
if (agent?.id) {
|
||||||
try {
|
try {
|
||||||
const res = await api.get(`/agents/${agent.id}/field-values`);
|
const res = await api.get(`/agents/${agent.id}/field-values`);
|
||||||
const fieldValues = res.data?.data?.fieldValues || res.data?.data || [];
|
const fieldValues = res.data?.data?.fieldValues || res.data?.data || [];
|
||||||
for (const fv of fieldValues) {
|
for (const fv of fieldValues) {
|
||||||
const slug = fv.field?.slug || fv.fieldSlug || '';
|
const slug: string = (fv.fieldSlug || fv.field?.slug || '').toLowerCase();
|
||||||
if (!location && (slug === 'city' || slug === 'state')) {
|
const value = fv.value ?? fv.jsonValue ?? fv.textValue;
|
||||||
const vals = Array.isArray(fv.jsonValue) ? fv.jsonValue.join(', ') : (fv.textValue || '');
|
if (value == null || value === '') continue;
|
||||||
if (vals) location = location ? `${location}, ${vals}` : vals;
|
|
||||||
|
// Location: city/state fields
|
||||||
|
if ((slug === 'city' || slug === 'state') && !location) {
|
||||||
|
location = Array.isArray(value) ? value.join(', ') : String(value);
|
||||||
}
|
}
|
||||||
if (!experience && (slug === 'years_in_business' || slug === 'experience')) {
|
|
||||||
experience = fv.textValue ? `${fv.textValue} years in real estate.` : '';
|
// Experience: only specific known slugs (backend already resolves option labels)
|
||||||
|
if (!experience && EXPERIENCE_SLUGS.includes(slug)) {
|
||||||
|
experience = Array.isArray(value) ? value.join(', ') : String(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expertise: only specific known slugs (backend already resolves option labels)
|
||||||
|
if (EXPERTISE_SLUGS.includes(slug)) {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
expertise.push(...value.map((v: any) => typeof v === 'object' ? (v.label || v.name || String(v)) : String(v)));
|
||||||
|
} else if (typeof value === 'string' && value.trim()) {
|
||||||
|
expertise.push(value);
|
||||||
}
|
}
|
||||||
if (slug === 'about_me_expertise' || slug === 'expertise_areas') {
|
|
||||||
if (Array.isArray(fv.jsonValue)) expertise = [...expertise, ...fv.jsonValue];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -314,22 +343,39 @@ export default function CmsPage() {
|
|||||||
const role = agent?.agentType?.name || agent?.headline || '';
|
const role = agent?.agentType?.name || agent?.headline || '';
|
||||||
const imageUrl = profile?.avatar || '';
|
const imageUrl = profile?.avatar || '';
|
||||||
|
|
||||||
|
// Helper to format snake_case to Title Case
|
||||||
|
const formatLabel = (v: string) =>
|
||||||
|
v.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');
|
||||||
|
|
||||||
|
const valueToString = (val: any): string => {
|
||||||
|
if (val == null) return '';
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
return val.map((v) => (typeof v === 'object' ? (v.label || v.name || JSON.stringify(v)) : formatLabel(String(v)))).join(', ');
|
||||||
|
}
|
||||||
|
if (typeof val === 'object') return val.label || val.name || JSON.stringify(val);
|
||||||
|
return formatLabel(String(val));
|
||||||
|
};
|
||||||
|
|
||||||
let location = [profile?.city, profile?.state].filter(Boolean).join(', ');
|
let location = [profile?.city, profile?.state].filter(Boolean).join(', ');
|
||||||
let experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : '';
|
let experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years` : '';
|
||||||
const rating = '';
|
const rating = agent?.averageRating ? String(agent.averageRating) : '';
|
||||||
|
|
||||||
|
const EXPERIENCE_SLUGS = ['years_in_business', 'years_of_experience'];
|
||||||
|
|
||||||
if (agent?.id) {
|
if (agent?.id) {
|
||||||
try {
|
try {
|
||||||
const res = await api.get(`/agents/${agent.id}/field-values`);
|
const res = await api.get(`/agents/${agent.id}/field-values`);
|
||||||
const fieldValues = res.data?.data?.fieldValues || res.data?.data || [];
|
const fieldValues = res.data?.data?.fieldValues || res.data?.data || [];
|
||||||
for (const fv of fieldValues) {
|
for (const fv of fieldValues) {
|
||||||
const slug = fv.field?.slug || fv.fieldSlug || '';
|
const slug: string = (fv.fieldSlug || fv.field?.slug || '').toLowerCase();
|
||||||
if (!location && (slug === 'city' || slug === 'state')) {
|
const value = fv.value ?? fv.jsonValue ?? fv.textValue;
|
||||||
const vals = Array.isArray(fv.jsonValue) ? fv.jsonValue.join(', ') : (fv.textValue || '');
|
if (value == null || value === '') continue;
|
||||||
if (vals) location = location ? `${location}, ${vals}` : vals;
|
|
||||||
|
if ((slug === 'city' || slug === 'state') && !location) {
|
||||||
|
location = Array.isArray(value) ? value.join(', ') : String(value);
|
||||||
}
|
}
|
||||||
if (!experience && (slug === 'years_in_business' || slug === 'experience')) {
|
if (!experience && EXPERIENCE_SLUGS.includes(slug)) {
|
||||||
experience = fv.textValue ? `${fv.textValue} years in real estate.` : '';
|
experience = Array.isArray(value) ? value.join(', ') : String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ export interface AgentProfileDetails {
|
|||||||
verificationNote?: string | null;
|
verificationNote?: string | null;
|
||||||
verifiedAt?: string | null;
|
verifiedAt?: string | null;
|
||||||
verifiedBy?: string | null;
|
verifiedBy?: string | null;
|
||||||
|
// Stats
|
||||||
|
averageRating?: number | null;
|
||||||
|
totalReviews?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
|
|||||||
Reference in New Issue
Block a user