"use client"; // A linked account's two settings, saved as soon as they're switched. import { useOptimistic, useState, useTransition } from "react"; import { FormMessage } from "@/components/forms"; import { Switch } from "@/components/ui/switch"; import type { ActionState } from "@/lib/actions"; import { saveSettings } from "./actions"; type Settings = { showBadge: boolean; showPresence: boolean; listRooms: boolean }; export function LinkSettings({ imvuId, ...saved }: Settings & { imvuId: number }) { const [settings, setOptimistic] = useOptimistic(saved); const [state, setState] = useState(null); const [pending, startTransition] = useTransition(); const change = (key: keyof Settings) => (value: boolean) => startTransition(async () => { setOptimistic({ ...settings, [key]: value }); setState(await saveSettings(imvuId, { [key]: value })); }); return (
); }