diff --git a/src/app/(agent)/agent/dashboard/page.tsx b/src/app/(agent)/agent/dashboard/page.tsx index 1e5e688..b7d6d44 100644 --- a/src/app/(agent)/agent/dashboard/page.tsx +++ b/src/app/(agent)/agent/dashboard/page.tsx @@ -17,7 +17,7 @@ import { } from '@/components/profile'; import { agentsService, AgentProfile, FieldValueResponse } from '@/services/agents.service'; import { uploadService } from '@/services/upload.service'; -import { mapFieldValuesToExperience, ExperienceData } from '@/utils/profileDataMapper'; +import { mapFieldValuesToExperience, mapFieldValuesToProfileCard, mapFieldValuesToAvailability, ExperienceData, ProfileCardData, AvailabilityData } from '@/utils/profileDataMapper'; // Mock data for sections not yet available from API const mockData = { @@ -83,11 +83,26 @@ const defaultExperience: ExperienceData = { certifications: [], }; +// Default profile card data when no field values are available +const defaultProfileCardData: ProfileCardData = { + bio: '', + expertise: [], + serviceAreas: [], +}; + +// Default availability data when no field values are available +const defaultAvailabilityData: AvailabilityData = { + type: '', + schedule: [], +}; + export default function AgentDashboard() { const { data: session } = useSession(); const [agentProfile, setAgentProfile] = useState(null); const [fieldValues, setFieldValues] = useState([]); const [experienceData, setExperienceData] = useState(defaultExperience); + const [profileCardData, setProfileCardData] = useState(defaultProfileCardData); + const [availabilityData, setAvailabilityData] = useState(defaultAvailabilityData); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [isPhotoModalOpen, setIsPhotoModalOpen] = useState(false); @@ -123,6 +138,14 @@ export default function AgentDashboard() { const mappedExperience = mapFieldValuesToExperience(fieldValuesResponse.fieldValues); setExperienceData(mappedExperience); + // Map field values to profile card data (bio, expertise) + const mappedProfileCard = mapFieldValuesToProfileCard(fieldValuesResponse.fieldValues); + setProfileCardData(mappedProfileCard); + + // Map field values to availability data + const mappedAvailability = mapFieldValuesToAvailability(fieldValuesResponse.fieldValues); + setAvailabilityData(mappedAvailability); + // If avatar is an S3 key, fetch presigned URL if (profile.avatar && isS3Key(profile.avatar)) { try { @@ -290,10 +313,10 @@ export default function AgentDashboard() { lastName={agentProfile.lastName} isVerified={agentProfile.isVerified} title={agentProfile.agentType?.name || 'Real Estate Agent'} - location={agentProfile.serviceAreas?.[0] || 'United States'} + location={profileCardData.serviceAreas?.[0] || (agentProfile as unknown as { city?: string }).city || 'United States'} memberSince={formatMemberSince((agentProfile as unknown as { createdAt?: string }).createdAt)} - bio={agentProfile.bio || ''} - expertise={agentProfile.specializations || []} + bio={profileCardData.bio || agentProfile.bio || ''} + expertise={profileCardData.expertise} showEditButton={true} editHref="/agent/edit" messageHref="/agent/message" @@ -317,11 +340,17 @@ export default function AgentDashboard() { } content={
-

{mockData.availability.type}

+ {availabilityData.type && ( +

{availabilityData.type}

+ )}
- {mockData.availability.days.map((day) => ( -

{day}

- ))} + {availabilityData.schedule.length > 0 ? ( + availabilityData.schedule.map((item, index) => ( +

{item}

+ )) + ) : ( +

Not specified

+ )}
} diff --git a/src/utils/profileDataMapper.ts b/src/utils/profileDataMapper.ts index c7df354..88a3a73 100644 --- a/src/utils/profileDataMapper.ts +++ b/src/utils/profileDataMapper.ts @@ -124,3 +124,98 @@ export function hasExperienceData(experience: ExperienceData): boolean { experience.certifications.length > 0 ); } + +// Profile card data structure +export interface ProfileCardData { + bio: string; + expertise: string[]; + serviceAreas: string[]; +} + +// Availability data structure +export interface AvailabilityData { + type: string; + schedule: string[]; +} + +// Map availability option values to human-readable labels +const availabilityLabels: Record = { + 'mf_9_5': 'Monday - Friday, 9 AM - 5 PM', + 'mf_8_6': 'Monday - Friday, 8 AM - 6 PM', + 'weekends': 'Weekends', + 'evenings': 'Evenings', + 'flexible': 'Flexible Schedule', + 'full_time': 'Full-time', + 'part_time': 'Part-time', + '24_7': '24/7 Available', + 'by_appointment': 'By Appointment Only', + 'monday': 'Monday', + 'tuesday': 'Tuesday', + 'wednesday': 'Wednesday', + 'thursday': 'Thursday', + 'friday': 'Friday', + 'saturday': 'Saturday', + 'sunday': 'Sunday', +}; + +/** + * Maps field values to availability data + */ +export function mapFieldValuesToAvailability(fieldValues: FieldValueResponse[]): AvailabilityData { + const availabilityValues = getFieldValue(fieldValues, 'availability') as string[] | undefined; + + if (!availabilityValues || availabilityValues.length === 0) { + return { + type: '', + schedule: [], + }; + } + + // Map values to human-readable labels + const schedule = availabilityValues.map(val => + availabilityLabels[val] || val.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) + ); + + // Determine type based on values + let type = 'Available'; + if (availabilityValues.includes('full_time') || availabilityValues.includes('mf_9_5') || availabilityValues.includes('mf_8_6')) { + type = 'Full-time'; + } else if (availabilityValues.includes('part_time')) { + type = 'Part-time'; + } else if (availabilityValues.includes('flexible')) { + type = 'Flexible'; + } + + return { + type, + schedule, + }; +} + +/** + * Maps field values to profile card data (bio, expertise, service areas) + */ +export function mapFieldValuesToProfileCard(fieldValues: FieldValueResponse[]): ProfileCardData { + // Get bio/description from various possible fields + const description = getFieldValue(fieldValues, 'description') as string | undefined; + const descrption = getFieldValue(fieldValues, 'descrption') as string | undefined; // typo in field slug + const biography = getFieldValue(fieldValues, 'biography') as string | undefined; + const bio = getFieldValue(fieldValues, 'bio') as string | undefined; + + // Get expertise from various possible fields + const aboutMeExpertise = getFieldValue(fieldValues, 'about_me_expertise') as string[] | undefined; + const expertiseAreas = getFieldValue(fieldValues, 'expertise_areas') as string[] | undefined; + const specializations = getFieldValue(fieldValues, 'specializations') as string[] | undefined; + const areasOfExpertise = getFieldValue(fieldValues, 'areas_of_expertise') as string[] | undefined; + + // Get service areas from various possible fields + const serviceAreas = getFieldValue(fieldValues, 'service_areas') as string[] | undefined; + const licensedAreas = getFieldValue(fieldValues, 'licensed_areas') as string[] | undefined; + const coverageAreas = getFieldValue(fieldValues, 'coverage_areas') as string[] | undefined; + + return { + bio: description || descrption || biography || bio || '', + expertise: aboutMeExpertise || expertiseAreas || specializations || areasOfExpertise || [], + serviceAreas: serviceAreas || licensedAreas || coverageAreas || [], + }; +}