This commit is contained in:
pradeepkumar
2026-01-24 21:06:13 +05:30
parent 0f84e3d4d7
commit eba83e2961
9 changed files with 585 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation';
import { QuickLinks } from './components';
import DynamicSection from './components/DynamicSection';
import { profileSectionsService, ProfileSection, AgentTypeSectionsResponse } from '@/services/profile-sections.service';
import { agentsService, AgentProfile } from '@/services/agents.service';
import { agentsService, AgentProfile, FieldValueInput } from '@/services/agents.service';
export default function EditProfilePage() {
const router = useRouter();
@@ -92,6 +92,23 @@ export default function EditProfilePage() {
}
});
});
// Fetch existing field values from the API
try {
const fieldValuesResponse = await agentsService.getFieldValues();
if (fieldValuesResponse.fieldValues) {
fieldValuesResponse.fieldValues.forEach(fv => {
// Only set if value exists and is not null/undefined
if (fv.value !== null && fv.value !== undefined) {
initialData[fv.fieldSlug] = fv.value;
}
});
}
} catch (fieldValueErr) {
// If field values don't exist yet, that's OK - just use defaults
console.log('No existing field values found, using defaults');
}
setFormData(initialData);
} catch (err: unknown) {
@@ -151,11 +168,14 @@ export default function EditProfilePage() {
return;
}
// TODO: Call API to save form data
console.log('Saving form data:', formData);
// Convert formData to field values array
const fieldValues: FieldValueInput[] = Object.entries(formData).map(([fieldSlug, value]) => ({
fieldSlug,
value: value as string | number | boolean | string[] | Record<string, unknown> | null,
}));
// Simulate save
await new Promise(resolve => setTimeout(resolve, 500));
// Save field values to API
await agentsService.saveFieldValues(fieldValues);
router.push('/agent/dashboard');
} catch (err) {