fix: enable profile auto-save for all verification statuses including approved
This commit is contained in:
@@ -48,9 +48,7 @@ export default function EditProfilePage() {
|
|||||||
const repeatableDataRef = useRef<Record<string, RepeatableEntryData[]>>({});
|
const repeatableDataRef = useRef<Record<string, RepeatableEntryData[]>>({});
|
||||||
// Dirty (unsaved) field slugs; repeatable sections tracked as `${slug}_entries`
|
// Dirty (unsaved) field slugs; repeatable sections tracked as `${slug}_entries`
|
||||||
const dirtySlugsRef = useRef<Set<string>>(new Set());
|
const dirtySlugsRef = useRef<Set<string>>(new Set());
|
||||||
// Server auto-save stays off for APPROVED profiles — their field values are
|
// Set once the profile loads; guards flushes from firing before then
|
||||||
// live, so changes only go out via the explicit Save button. Local drafts
|
|
||||||
// still work for everyone.
|
|
||||||
const autoSaveEnabledRef = useRef(false);
|
const autoSaveEnabledRef = useRef(false);
|
||||||
const draftKeyRef = useRef<string | null>(null);
|
const draftKeyRef = useRef<string | null>(null);
|
||||||
const autoSaveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
const autoSaveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
@@ -233,12 +231,9 @@ export default function EditProfilePage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// APPROVED profiles are live — keep their changes behind the explicit
|
// Auto-save for all statuses. Note: APPROVED profiles are live, so
|
||||||
// Save button. Everyone else gets server auto-save while they build.
|
// auto-saved edits update the public profile immediately.
|
||||||
autoSaveEnabledRef.current =
|
autoSaveEnabledRef.current = true;
|
||||||
!profile.verificationStatus ||
|
|
||||||
profile.verificationStatus === 'NONE' ||
|
|
||||||
profile.verificationStatus === 'REJECTED';
|
|
||||||
draftKeyRef.current = `agent-profile-draft:${profile.userId}`;
|
draftKeyRef.current = `agent-profile-draft:${profile.userId}`;
|
||||||
|
|
||||||
if (!profile.agentTypeId) {
|
if (!profile.agentTypeId) {
|
||||||
@@ -656,9 +651,7 @@ export default function EditProfilePage() {
|
|||||||
{autoSaveStatus === 'saved' && lastSavedAt && `All changes saved at ${formatTime(lastSavedAt)}`}
|
{autoSaveStatus === 'saved' && lastSavedAt && `All changes saved at ${formatTime(lastSavedAt)}`}
|
||||||
{autoSaveStatus === 'error' && 'Auto-save failed — retrying'}
|
{autoSaveStatus === 'error' && 'Auto-save failed — retrying'}
|
||||||
{autoSaveStatus === 'dirty' &&
|
{autoSaveStatus === 'dirty' &&
|
||||||
(autoSaveEnabledRef.current
|
(lastSavedAt ? `Last saved at ${formatTime(lastSavedAt)}` : 'Unsaved changes')}
|
||||||
? 'Unsaved changes'
|
|
||||||
: 'Unsaved changes — remember to save')}
|
|
||||||
{autoSaveStatus === 'idle' && lastSavedAt && `Last saved at ${formatTime(lastSavedAt)}`}
|
{autoSaveStatus === 'idle' && lastSavedAt && `Last saved at ${formatTime(lastSavedAt)}`}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -675,9 +668,7 @@ export default function EditProfilePage() {
|
|||||||
hour: 'numeric',
|
hour: 'numeric',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
})}
|
})}
|
||||||
{autoSaveEnabledRef.current
|
. Keep editing — your progress is saved automatically.
|
||||||
? '. Keep editing — your progress is saved automatically.'
|
|
||||||
: '. Review them and press Save Changes to keep them.'}
|
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => setDraftRestoredAt(null)}
|
onClick={() => setDraftRestoredAt(null)}
|
||||||
|
|||||||
Reference in New Issue
Block a user