fix
This commit is contained in:
@@ -7,6 +7,7 @@ import DynamicSection from './components/DynamicSection';
|
||||
import RepeatableSection, { RepeatableEntryData } from './components/RepeatableSection';
|
||||
import { profileSectionsService, ProfileSection, AgentTypeSectionsResponse } from '@/services/profile-sections.service';
|
||||
import { agentsService, AgentProfile, FieldValueInput } from '@/services/agents.service';
|
||||
import { usersService } from '@/services/users.service';
|
||||
import { MobileBackButton } from '@/components/layout/MobileBackButton';
|
||||
|
||||
export default function EditProfilePage() {
|
||||
@@ -38,6 +39,12 @@ export default function EditProfilePage() {
|
||||
const profile = await agentsService.getMyProfile();
|
||||
setAgentProfile(profile);
|
||||
|
||||
// Block editing when verification is under review
|
||||
if (profile.verificationStatus === 'PENDING_REVIEW') {
|
||||
router.push('/agent/dashboard');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!profile.agentTypeId) {
|
||||
setError('Your profile does not have an agent type assigned. Please contact support.');
|
||||
setLoading(false);
|
||||
@@ -276,28 +283,31 @@ export default function EditProfilePage() {
|
||||
await agentsService.saveFieldValues(fieldValues);
|
||||
|
||||
// Also update main profile fields (phone, email) to keep them in sync
|
||||
// This ensures that when the view page checks agentProfile.phone first,
|
||||
// it gets the correct (possibly empty) value
|
||||
const profileUpdates: Partial<{ phone: string | null; email: string | null }> = {};
|
||||
|
||||
// Sync phone field - check dynamic field slugs FIRST, then legacy 'phone'
|
||||
// Dynamic fields (phone_number, etc.) are the source of truth from the form
|
||||
// 'phone' is a legacy pre-populated key and should only be used as fallback
|
||||
const phoneFieldSlugs = ['phone_number', 'cell_number', 'office_number', 'phone'];
|
||||
for (const slug of phoneFieldSlugs) {
|
||||
const phoneValue = formData[slug];
|
||||
if (phoneValue !== undefined) {
|
||||
// Set to null if empty, otherwise use the value
|
||||
profileUpdates.phone = phoneValue === '' ? null : (phoneValue as string);
|
||||
break; // Use the first found phone field
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if there are changes to sync
|
||||
if (Object.keys(profileUpdates).length > 0) {
|
||||
await agentsService.updateProfile(profileUpdates);
|
||||
}
|
||||
|
||||
// Auto-submit for verification (status: NONE or REJECTED → PENDING_REVIEW)
|
||||
const status = agentProfile?.verificationStatus;
|
||||
if (!status || status === 'NONE' || status === 'REJECTED') {
|
||||
try {
|
||||
await usersService.submitForVerification();
|
||||
} catch {
|
||||
// If submit fails (e.g. already pending), still proceed
|
||||
}
|
||||
}
|
||||
|
||||
router.push('/agent/dashboard');
|
||||
} catch (err) {
|
||||
console.error('Failed to save:', err);
|
||||
@@ -444,7 +454,7 @@ export default function EditProfilePage() {
|
||||
{isSaving && (
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
)}
|
||||
{isSaving ? 'Saving...' : 'Save'}
|
||||
{isSaving ? 'Submitting...' : 'Submit for Review'}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user