import { t } from "@lingui/core/macro"; import { useEffect, useState } from "react"; import { api } from "~/utils/api"; export default function UpdateWeekStartDayForm({ workspacePublicId, weekStartDay, disabled = false, }: { workspacePublicId: string; weekStartDay: number; disabled?: boolean; }) { const utils = api.useUtils(); const [value, setValue] = useState(weekStartDay); useEffect(() => { setValue(weekStartDay); }, [weekStartDay]); const updateWorkspace = api.workspace.update.useMutation({ onSuccess: () => { if (workspacePublicId && workspacePublicId.length >= 12) { void utils.workspace.byId.invalidate({ workspacePublicId, }); void utils.workspace.all.invalidate(); } }, }); const handleChange = (e: React.ChangeEvent) => { if (disabled) return; const newValue = Number(e.target.value); setValue(newValue); updateWorkspace.mutate({ workspacePublicId, weekStartDay: newValue as 0 | 1 | 6, }); }; return (
); }