diff --git a/web/ui/react-app/src/components/generic/boolean-with-default.tsx b/web/ui/react-app/src/components/generic/boolean-with-default.tsx index 339b48ec..eafad7d1 100644 --- a/web/ui/react-app/src/components/generic/boolean-with-default.tsx +++ b/web/ui/react-app/src/components/generic/boolean-with-default.tsx @@ -1,11 +1,11 @@ import { Button, ButtonGroup, Col, FormLabel } from 'react-bootstrap'; -import { Controller, useFormContext } from 'react-hook-form'; -import { FC, memo, useEffect } from 'react'; +import { FC, memo } from 'react'; import { faCheckCircle, faCircleXmark, } from '@fortawesome/free-solid-svg-icons'; +import { Controller } from 'react-hook-form'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { HelpTooltip } from 'components/generic'; import { strToBool } from 'utils'; @@ -33,7 +33,6 @@ const BooleanWithDefault: FC = ({ defaultValue, tooltip, }) => { - const { getValues, setValue } = useFormContext(); const options = [ { value: true, @@ -54,13 +53,6 @@ const BooleanWithDefault: FC = ({ icon: defaultValue ? faCheckCircle : faCircleXmark, class: defaultValue ? 'success' : 'danger', }; - // on load, convert the value if it's a string. - useEffect(() => { - const timeout = setTimeout(() => { - setValue(name, strToBool(getValues(name))); - }, 0); - return () => clearTimeout(timeout); - }, []); return ( = ({ > ( - <> - - {options.map((option) => ( - - ))} - - <>{' | '} - - - )} + render={({ field: { onChange, value } }) => { + const boolValue = strToBool(value); + return ( + <> + + {options.map((option) => ( + + ))} + + <>{' | '} + + + ); + }} /> diff --git a/web/ui/react-app/src/utils/string-boolean.tsx b/web/ui/react-app/src/utils/string-boolean.tsx index 125ddb81..79e09a3b 100644 --- a/web/ui/react-app/src/utils/string-boolean.tsx +++ b/web/ui/react-app/src/utils/string-boolean.tsx @@ -9,7 +9,7 @@ import isEmptyOrNull from './is-empty-or-null'; export const strToBool = (str?: string | boolean | null): boolean | null => { if (typeof str === 'boolean') return str; if (isEmptyOrNull(str)) return null; - return ['true', 'yes'].includes((str as string).toLowerCase()); + return ['true', 'yes'].includes(str.toLowerCase()); }; export const boolToStr = (bool?: boolean) =>