import { useField } from 'formik'; import type { ReactNode } from 'react'; import { memo, useCallback } from 'react'; import isEqual from 'react-fast-compare'; import tw from 'twin.macro'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; import Input from '@/components/elements/Input'; interface Props { children?: ReactNode; className?: string; isEditable?: boolean; title: string; permissions: string[]; } function PermissionTitleBox({ isEditable, title, permissions, className, children }: Props) { const [{ value }, , { setValue }] = useField('permissions'); const onCheckboxClicked = useCallback( (e: React.ChangeEvent) => { if (e.currentTarget.checked) { setValue([...value, ...permissions.filter(p => !value.includes(p))]); } else { setValue(value.filter(p => !permissions.includes(p))); } }, [permissions, value], ); return (

{title}

{isEditable && ( value.includes(p))} onChange={onCheckboxClicked} /> )} } className={className} > {children}
); } const MemoizedPermissionTitleBox = memo(PermissionTitleBox, isEqual); export default MemoizedPermissionTitleBox;