import React, { memo, useCallback } from 'react'; import { useField } from 'formik'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; import tw from 'twin.macro'; import Input from '@/components/elements/Input'; import isEqual from 'react-fast-compare'; interface Props { isEditable: boolean; title: string; permissions: string[]; className?: string; } const PermissionTitleBox: React.FC = memo(({ isEditable, title, permissions, className, children }) => { 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}
); }, isEqual); export default PermissionTitleBox;