diff --git a/src/app/(app)/settings/page.tsx b/src/app/(app)/settings/page.tsx index 360802a..7c1ca56 100644 --- a/src/app/(app)/settings/page.tsx +++ b/src/app/(app)/settings/page.tsx @@ -41,6 +41,9 @@ export default function SettingsPage() { const [pedPhone, setPedPhone] = useState(""); const [pedName, setPedName] = useState(""); const [pedSaving, setPedSaving] = useState(false); + const [pedEditing, setPedEditing] = useState(false); + const [pedSaved, setPedSaved] = useState(false); + const [pedError, setPedError] = useState(""); // Check if can invite more members (client-side pre-check; server enforces) const canInvite = tier === "pro" || memberCount < 2; @@ -60,8 +63,10 @@ export default function SettingsPage() { fetchMembers(); fetchInvites(); fetch("/api/family").then(r => r.json()).then(d => { - if (d.family?.pediatrician_phone) setPedPhone(d.family.pediatrician_phone); - if (d.family?.pediatrician_name) setPedName(d.family.pediatrician_name); + setPedPhone(d.family?.pediatrician_phone || ""); + setPedName(d.family?.pediatrician_name || ""); + // If no data yet, open in edit mode so user can fill it in + if (!d.family?.pediatrician_phone && !d.family?.pediatrician_name) setPedEditing(true); }).catch(() => {}); } }, [familyId]); @@ -96,11 +101,24 @@ export default function SettingsPage() { const savePedInfo = async () => { setPedSaving(true); - await fetch("/api/family", { - method: "PATCH", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ pediatricianPhone: pedPhone, pediatricianName: pedName }), - }).catch(() => {}); + setPedError(""); + try { + const res = await fetch("/api/family", { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ pediatricianPhone: pedPhone, pediatricianName: pedName }), + }); + const data = await res.json(); + if (!res.ok) { + setPedError(data.error || "Failed to save. Please try again."); + } else { + setPedEditing(false); + setPedSaved(true); + setTimeout(() => setPedSaved(false), 3000); + } + } catch { + setPedError("Network error. Please try again."); + } setPedSaving(false); }; @@ -360,21 +378,54 @@ export default function SettingsPage() { {/* Pediatrician */}
Shown on the emergency guide and in AI medical redirects.
- setPedName(e.target.value)} - placeholder="Dr. Priya Sharma" - /> -Shown on the emergency guide and in AI medical redirects.
+ setPedName(e.target.value)} + placeholder="Dr. Priya Sharma" + /> +{pedError}
} +