import { cx } from "@twind/core"; import React, { ReactNode, useState } from "react"; import useSWR from "swr"; import { apiClient, handleResponse } from "./apiClient.tsx"; export function SettingsPage(props: { sessionId: string }) { const { sessionId } = props; const session = useSWR( ["sessions", "GET", { query: { sessionId } }] as const, (args) => apiClient.fetch(...args).then(handleResponse), ); const user = useSWR( session.data?.userId ? ["users", "GET", { query: { userId: session.data.userId } }] as const : null, (args) => apiClient.fetch(...args).then(handleResponse), ); const params = useSWR( ["settings/params", "GET", {}] as const, (args) => apiClient.fetch(...args).then(handleResponse), ); const [changedParams, setChangedParams] = useState>({}); const [error, setError] = useState(); return (
{ e.preventDefault(); params.mutate(() => apiClient.fetch("settings/params", "PATCH", { query: { sessionId }, type: "application/json", body: changedParams ?? {}, }).then(handleResponse) ) .then(() => setChangedParams({})) .catch((e) => setError(String(e))); }} >