2022-08-27 15:58:36 +02:00
|
|
|
import { Box, Checkbox } from '@chakra-ui/react';
|
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
import { ICheckbox } from '../../../interfaces/dialog';
|
2022-05-03 15:08:28 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
2022-08-09 23:50:14 +02:00
|
|
|
row: ICheckbox;
|
2022-05-03 15:08:28 +02:00
|
|
|
index: number;
|
2022-08-09 23:50:14 +02:00
|
|
|
handleChange: (value: boolean, index: number) => void;
|
2022-05-03 15:08:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CheckboxField: React.FC<Props> = (props) => {
|
2022-08-05 15:10:37 +02:00
|
|
|
useEffect(() => {
|
2022-08-27 15:58:36 +02:00
|
|
|
if (props.row.checked) props.handleChange(props.row.checked, props.index);
|
2022-08-05 15:10:37 +02:00
|
|
|
}, []);
|
|
|
|
|
|
2022-05-03 15:08:28 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box mb={3} key={`checkbox-${props.index}`}>
|
|
|
|
|
<Checkbox
|
2022-08-09 23:50:14 +02:00
|
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => props.handleChange(e.target.checked, props.index)}
|
2022-08-05 15:10:37 +02:00
|
|
|
defaultChecked={props.row.checked}
|
2022-05-03 15:08:28 +02:00
|
|
|
>
|
|
|
|
|
{props.row.label}
|
|
|
|
|
</Checkbox>
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default CheckboxField;
|