fix
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
} from '@/components/profile';
|
} from '@/components/profile';
|
||||||
import { agentsService, AgentProfile, FieldValueResponse } from '@/services/agents.service';
|
import { agentsService, AgentProfile, FieldValueResponse } from '@/services/agents.service';
|
||||||
import { uploadService } from '@/services/upload.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
|
// Mock data for sections not yet available from API
|
||||||
const mockData = {
|
const mockData = {
|
||||||
@@ -83,11 +83,26 @@ const defaultExperience: ExperienceData = {
|
|||||||
certifications: [],
|
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() {
|
export default function AgentDashboard() {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const [agentProfile, setAgentProfile] = useState<AgentProfile | null>(null);
|
const [agentProfile, setAgentProfile] = useState<AgentProfile | null>(null);
|
||||||
const [fieldValues, setFieldValues] = useState<FieldValueResponse[]>([]);
|
const [fieldValues, setFieldValues] = useState<FieldValueResponse[]>([]);
|
||||||
const [experienceData, setExperienceData] = useState<ExperienceData>(defaultExperience);
|
const [experienceData, setExperienceData] = useState<ExperienceData>(defaultExperience);
|
||||||
|
const [profileCardData, setProfileCardData] = useState<ProfileCardData>(defaultProfileCardData);
|
||||||
|
const [availabilityData, setAvailabilityData] = useState<AvailabilityData>(defaultAvailabilityData);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [isPhotoModalOpen, setIsPhotoModalOpen] = useState(false);
|
const [isPhotoModalOpen, setIsPhotoModalOpen] = useState(false);
|
||||||
@@ -123,6 +138,14 @@ export default function AgentDashboard() {
|
|||||||
const mappedExperience = mapFieldValuesToExperience(fieldValuesResponse.fieldValues);
|
const mappedExperience = mapFieldValuesToExperience(fieldValuesResponse.fieldValues);
|
||||||
setExperienceData(mappedExperience);
|
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 avatar is an S3 key, fetch presigned URL
|
||||||
if (profile.avatar && isS3Key(profile.avatar)) {
|
if (profile.avatar && isS3Key(profile.avatar)) {
|
||||||
try {
|
try {
|
||||||
@@ -290,10 +313,10 @@ export default function AgentDashboard() {
|
|||||||
lastName={agentProfile.lastName}
|
lastName={agentProfile.lastName}
|
||||||
isVerified={agentProfile.isVerified}
|
isVerified={agentProfile.isVerified}
|
||||||
title={agentProfile.agentType?.name || 'Real Estate Agent'}
|
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)}
|
memberSince={formatMemberSince((agentProfile as unknown as { createdAt?: string }).createdAt)}
|
||||||
bio={agentProfile.bio || ''}
|
bio={profileCardData.bio || agentProfile.bio || ''}
|
||||||
expertise={agentProfile.specializations || []}
|
expertise={profileCardData.expertise}
|
||||||
showEditButton={true}
|
showEditButton={true}
|
||||||
editHref="/agent/edit"
|
editHref="/agent/edit"
|
||||||
messageHref="/agent/message"
|
messageHref="/agent/message"
|
||||||
@@ -317,11 +340,17 @@ export default function AgentDashboard() {
|
|||||||
}
|
}
|
||||||
content={
|
content={
|
||||||
<div>
|
<div>
|
||||||
<p className="font-semibold font-serif text-[14px] leading-[19px] text-[#00293D] mb-2">{mockData.availability.type}</p>
|
{availabilityData.type && (
|
||||||
|
<p className="font-semibold font-serif text-[14px] leading-[19px] text-[#00293D] mb-2">{availabilityData.type}</p>
|
||||||
|
)}
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
{mockData.availability.days.map((day) => (
|
{availabilityData.schedule.length > 0 ? (
|
||||||
<p key={day} className="font-normal font-serif text-[14px] leading-[19px] text-[#00293D]">{day}</p>
|
availabilityData.schedule.map((item, index) => (
|
||||||
))}
|
<p key={index} className="font-normal font-serif text-[14px] leading-[19px] text-[#00293D]">{item}</p>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<p className="font-normal font-serif text-[14px] leading-[19px] text-[#00293D]/60">Not specified</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,3 +124,98 @@ export function hasExperienceData(experience: ExperienceData): boolean {
|
|||||||
experience.certifications.length > 0
|
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<string, string> = {
|
||||||
|
'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 || [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user