fix admin save state architecture

This commit is contained in:
MOH
2026-03-10 05:24:50 +01:00
parent e219295327
commit f2b5a15191
12 changed files with 123 additions and 38 deletions
+7 -2
View File
@@ -5,22 +5,27 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import { cn } from "@/lib/utils";
import { useHiddenInputSync } from "@/components/ui/use-hidden-input-sync";
type CheckboxProps = React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> & {
name?: string;
checkedValue?: string;
uncheckedValue?: string;
};
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
CheckboxProps
>(({ className, name, checked, defaultChecked, onCheckedChange, ...props }, ref) => {
>(({ className, name, checked, defaultChecked, onCheckedChange, checkedValue = "on", uncheckedValue = "false", ...props }, ref) => {
const [internalChecked, setInternalChecked] = React.useState(defaultChecked === true);
const isControlled = checked !== undefined;
const currentChecked = isControlled ? checked === true : internalChecked;
const hiddenValue = currentChecked ? checkedValue : uncheckedValue;
const hiddenInputRef = useHiddenInputSync(hiddenValue);
return (
<>
{name ? <input type="hidden" name={name} value={currentChecked ? "on" : "false"} /> : null}
{name ? <input ref={hiddenInputRef} type="hidden" name={name} value={hiddenValue} /> : null}
<CheckboxPrimitive.Root
ref={ref}
checked={checked}