From 0bea6c900c7cadbbbb003207ffe1219b32e82cb4 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Fri, 11 Oct 2024 19:38:26 +0700 Subject: [PATCH] feat: checkbox fixes --- .../providers/tiktok/tiktok.provider.tsx | 8 +- .../src/form/checkbox.tsx | 107 +++++++++++------- 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx b/apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx index 9ec2c06d..6f2ca47c 100644 --- a/apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx +++ b/apps/frontend/src/components/launches/providers/tiktok/tiktok.provider.tsx @@ -130,6 +130,7 @@ const TikTokSettings: FC<{ values?: any }> = (props) => {
Allow User To:
= (props) => { /> = (props) => {
= (props) => {
-
+
= (props) => { This video will be classified as Brand Organic.
, - HTMLInputElement - > & { - error?: any; - extraForm?: RegisterOptions; +export const Checkbox = forwardRef< + null, + { + checked?: boolean; disableForm?: boolean; - label: string; - name: string; - hideErrors?: boolean; + name?: string; + className?: string; + label?: string; + onChange?: (event: { target: { name?: string; value: boolean } }) => void; + variant?: 'default' | 'hollow'; } -> = (props) => { - const { - label, - className, - hideErrors, - disableForm, - error, - extraForm, - name, - ...rest - } = props; +>((props, ref: any) => { + const { checked, className, label, disableForm, variant } = props; const form = useFormContext(); + const register = disableForm ? {} : form.register(props.name!); + + const watch = disableForm + ? undefined + : useWatch({ + name: props.name!, + }); + + const [currentStatus, setCurrentStatus] = useState(watch || checked); + const changeStatus = useCallback(() => { + setCurrentStatus(!currentStatus); + props?.onChange?.({ target: { name: props.name!, value: !currentStatus } }); + if (!disableForm) { + // @ts-ignore + register?.onChange?.({ + target: { name: props.name!, value: !currentStatus }, + }); + } + }, [currentStatus]); return ( -
- +
+
+ {currentStatus && ( +
+ + + +
+ )} +
+ {!!label &&
{label}
}
); -}; \ No newline at end of file +});