fix: persist form data across visits, don't overwrite local edits

Keep submitted data in localStorage so "Resume" works on return visits.
Stop overwriting local edits with older server data during resume —
email lookup now only sets the update flag, preserving local changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-04-07 11:46:22 -04:00
parent f4dca61631
commit 4e4273c27b
1 changed files with 4 additions and 6 deletions

View File

@ -1082,7 +1082,7 @@
currentStep = 1; currentStep = 1;
showStep(1); showStep(1);
// If we have an email, check server for existing application // If we have an email, check if application exists in DB (just set the update flag)
if (email) { if (email) {
try { try {
const resp = await fetch('/api/application/lookup?email=' + encodeURIComponent(email)); const resp = await fetch('/api/application/lookup?email=' + encodeURIComponent(email));
@ -1093,10 +1093,8 @@
alert('This email already has a completed (paid) application. Contact us at contact@valleyofthecommons.com if you need to make changes.'); alert('This email already has a completed (paid) application. Contact us at contact@valleyofthecommons.com if you need to make changes.');
return; return;
} }
// Silently load server data over localStorage data // Just flag for PUT on submit — localStorage already has the latest edits
window._existingApplicationId = result.application.id; window._existingApplicationId = result.application.id;
restoreFormData(result.application);
saveFormData();
} }
} }
} catch (e) { } catch (e) {
@ -1722,8 +1720,8 @@
const result = await response.json(); const result = await response.json();
if (response.ok && result.success) { if (response.ok && result.success) {
// Clear saved data // Save submitted data so "Resume" works on next visit
localStorage.removeItem(STORAGE_KEY); saveFormData();
// Show success state // Show success state
document.getElementById('confirm-name').textContent = data.first_name; document.getElementById('confirm-name').textContent = data.first_name;