Add Preferences section to the admin Settings screen

Adds a typed settings client (fetchSettings / updateSettings) and a
Preferences section below Children that edits all ten household
settings. Save patches only the changed fields, says "No changes to
save." without a request when nothing changed, shows the 403 refusal
or the API's 422 detail, and shares the one-write-at-a-time lock with
the Children section.

Maestro task: cd3e0209-4575-4acd-bd87-d1595a4451de

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-24 15:23:46 -04:00
co-authored by Claude Opus 5.5
parent 1eb136fc67
commit 09f620343c
4 changed files with 512 additions and 4 deletions
+39
View File
@@ -0,0 +1,39 @@
/**
* Typed client for the admin household-settings routes
* (/api/v1/admin/settings).
*/
import { apiFetch } from "./client";
import { readJson } from "./definitions";
export interface HouseholdSettings {
horizon_days: number;
/** Local wall-clock "HH:MM", as are the other *_time fields. */
day_rollover_time: string;
notify_target: string;
morning_summary_time: string;
afternoon_reminder_time: string;
end_of_day_report_time: string;
morning_summary_enabled: boolean;
afternoon_reminder_enabled: boolean;
end_of_day_report_enabled: boolean;
celebration_enabled: boolean;
}
/** Only the supplied fields are updated; the API answers with all of them. */
export type SettingsChanges = Partial<HouseholdSettings>;
export const SETTINGS_PATH = "/api/v1/admin/settings";
export async function fetchSettings(): Promise<HouseholdSettings> {
return readJson<HouseholdSettings>(await apiFetch(SETTINGS_PATH));
}
export async function updateSettings(changes: SettingsChanges): Promise<HouseholdSettings> {
return readJson<HouseholdSettings>(
await apiFetch(SETTINGS_PATH, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(changes),
}),
);
}