"use client" import { useEffect, useState } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Label } from "@/components/ui/label" import { Button } from "@/components/ui/button" import { toast } from "sonner" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" interface Preferences { timezone: string dateFormat: string itemsPerPage: number } export function UserPreferencesForm() { const [prefs, setPrefs] = useState({ timezone: "america-los_angeles", dateFormat: "mdy", itemsPerPage: 20, }) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) useEffect(() => { async function load() { try { const res = await fetch("/api/settings/preferences") if (res.ok) { const json = await res.json() setPrefs(json) } } catch { // ignore } finally { setLoading(false) } } load() }, []) async function handleSave() { setSaving(true) try { const res = await fetch("/api/settings/preferences", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(prefs), }) if (res.ok) { toast.success("Preferences saved") } else { toast.error("Failed to save preferences") } } catch { toast.error("Failed to save preferences") } finally { setSaving(false) } } return ( User Preferences Customize your experience and default settings.
) }