fix
This commit is contained in:
@@ -53,6 +53,9 @@ export default function EditProfilePage() {
|
||||
|
||||
setSections(sortedSections);
|
||||
|
||||
// Debug: Log all sections and their isRepeatable status
|
||||
console.log('All sections:', sortedSections.map(s => ({ slug: s.slug, name: s.name, isRepeatable: s.isRepeatable })));
|
||||
|
||||
// Initialize form data with existing profile data + default values from fields
|
||||
const initialData: Record<string, unknown> = {};
|
||||
|
||||
@@ -100,7 +103,6 @@ export default function EditProfilePage() {
|
||||
// Fetch existing field values from the API
|
||||
try {
|
||||
const fieldValuesResponse = await agentsService.getFieldValues();
|
||||
console.log('Field values from API:', fieldValuesResponse.fieldValues);
|
||||
if (fieldValuesResponse.fieldValues) {
|
||||
fieldValuesResponse.fieldValues.forEach(fv => {
|
||||
// Only set if value exists and is not null/undefined
|
||||
@@ -114,8 +116,6 @@ export default function EditProfilePage() {
|
||||
console.log('No existing field values found, using defaults');
|
||||
}
|
||||
|
||||
console.log('initialData after field values:', initialData);
|
||||
|
||||
setFormData(initialData);
|
||||
|
||||
// Initialize repeatable sections data
|
||||
@@ -124,9 +124,7 @@ export default function EditProfilePage() {
|
||||
if (section.isRepeatable) {
|
||||
// Check if there's existing data for this section (stored as `${sectionSlug}_entries`)
|
||||
const entriesKey = `${section.slug}_entries`;
|
||||
console.log(`Checking repeatable section: ${section.slug}, entriesKey: ${entriesKey}`);
|
||||
const existingEntries = initialData[entriesKey];
|
||||
console.log(`Existing entries for ${entriesKey}:`, existingEntries);
|
||||
if (Array.isArray(existingEntries) && existingEntries.length > 0) {
|
||||
initialRepeatableData[section.slug] = existingEntries as RepeatableEntryData[];
|
||||
} else {
|
||||
@@ -135,7 +133,22 @@ export default function EditProfilePage() {
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log('initialRepeatableData:', initialRepeatableData);
|
||||
|
||||
// Also check for any _entries fields that might not match a repeatable section
|
||||
// This handles cases where data was saved but section isn't marked as repeatable
|
||||
Object.keys(initialData).forEach(key => {
|
||||
if (key.endsWith('_entries') && Array.isArray(initialData[key])) {
|
||||
const sectionSlug = key.replace('_entries', '');
|
||||
if (!initialRepeatableData[sectionSlug]) {
|
||||
// Find the section by slug
|
||||
const section = sortedSections.find(s => s.slug === sectionSlug);
|
||||
if (section) {
|
||||
initialRepeatableData[sectionSlug] = initialData[key] as RepeatableEntryData[];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setRepeatableData(initialRepeatableData);
|
||||
|
||||
} catch (err: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user