type Section = "saved" | "profile" | "progress" | "view" | "survey"; export async function accountRequest(section: Section, body?: object): Promise< { data: T; error: null } | { data: null; error: string } > { try { const result = await fetch(`/api/account/${section}`, body === undefined ? undefined : { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); const payload = await result.json(); if (!result.ok) return { data: null, error: payload.error ?? "Could not update your account." }; return { data: payload.data, error: null }; } catch { return { data: null, error: "Could not reach your account. Try again." }; } }