I have created a page with some checkboxes and I want that the values of the checkboxes checked should be displayed in an array. the checkbox value should be removed if we uncheck the checkbox and added if it is checked. So far I have this code that gives only a single value in the array but I need all the checked values in one array.
import React from 'react';
import DropDown from './DropDown';
import TextField from '@material-ui/core/TextField';
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
import RadioButton from './RadioButtons';
import MultiSelect from './MultiSelect';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import FormControl from '@material-ui/core/FormControl';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import Button from '@material-ui/core/Button';
import Box from '@material-ui/core/Box';
import { DropzoneDialog } from 'material-ui-dropzone';
import createpagestyle from './Createpage.css';
import Chip from '@material-ui/core/Chip';
import AddCircleIcon from '@material-ui/icons/AddCircle';
import Checkbox from '@material-ui/core/Checkbox';
import { grey } from '@material-ui/core/colors';
import { useState } from 'react';
const useStyles = makeStyles((theme) => ({
typography: {
fontSize: '3.5 rem',
fontWeight: '550',
color: '#0E1941',
[theme.breakpoints.down('md')]: {
fontSize: '0.5rem',
},
[theme.breakpoints.up('md')]: {
fontSize: '1.0rem',
},
[theme.breakpoints.up('lg')]: {
fontSize: '1.2rem',
},
},
Table: {
width: '60%',
},
Td: {
width: '250px',
},
Td_Checkbox: {
width: '60px',
},
}));
var Claim = [
{ key: 0, label: 'CLAIM OWNER', name: 'DESIREE MOHUKA' },
{ key: 1, label: 'AUTHORITY CONSULTANT', name: 'XXXXXXXXXXXX' },
{ key: 2, label: 'PROCESSOR CLAIM', name: 'XXXXXXXXXXXX' },
{ key: 3, label: 'CONTROLLLER', name: 'XXXXXXXXXXXX' },
{ key: 4, label: 'MANAGER', name: 'XXXXXXXXXXXX' },
];
var Dwelling = [
{ key: 0, label: 'CLAIM HANDLER', name: 'DESIREE MOHUKA' },
{ key: 1, label: 'CONTROLLLER', name: 'XXXXXXXXXXXX' },
{ key: 2, label: 'PERFORMER', name: 'XXXXXXXXXXXX' },
];
var Unscheduler_pp = [
{ key: 0, label: 'CLAIM HANDLER', name: 'DESIREE MOHUKA' },
{ key: 1, label: 'CONTROLLLER', name: 'XXXXXXXXXXXX' },
{ key: 2, label: 'PERFORMER', name: 'XXXXXXXXXXXX' },
];
export default function Participantpage(props) {
if (props.visibility) {
const classes = useStyles();
const [participant, setParticipant] = React.useState([]);
let handleCheckboxChange = (event) => {
let newArray = [event.target.id];
if (participant.includes(event.target.id)) {
newArray = newArray.filter((value) => value !== event.target.id);
}
setParticipant(newArray);
};
return (
<div>
<Grid container spacing={2}>
<Grid item xs={9}>
POLICY: XXXXXXXXXX
</Grid>
<Grid item xs={3}>
INSURED: XXXXXXXXXX
</Grid>
<Grid item xs={12}>
<div style={{ backgroundColor: '#E9E9E9', width: '100%' }}>
<Typography
variant='body1'
className={classes.typography}
style={{
marginTop: '10px',
marginBottom: '30px',
font: 'normal normal medium 20px/24px Allstate Sans W',
}}
>
CLAIM{' '}
</Typography>
</div>
</Grid>
</Grid>
<tbody className={classes.Table}>
{Claim.map((data) => {
return (
<tr>
<td className={classes.Td_Checkbox}>
{' '}
<Checkbox
id={data.name}
onChange={handleCheckboxChange}
color='default'
/>{' '}
</td>
<td className={classes.Td}>{data.label}</td>
<td className={classes.Td}>{data.name}</td>
</tr>
);
})}
</tbody>
<Grid container spacing={2}>
<Grid item xs={12}>
<div style={{ backgroundColor: '#E9E9E9', width: '100%' }}>
<Typography
variant='body1'
className={classes.typography}
style={{
marginTop: '10px',
marginBottom: '30px',
font: 'normal normal medium 20px/24px Allstate Sans W',
}}
>
DWELLING{' '}
</Typography>
</div>
</Grid>
</Grid>
<tbody className={classes.Table}>
{Dwelling.map((data) => {
return (
<tr>
<td className={classes.Td_Checkbox}>
{' '}
<Checkbox
id={data.name}
onChange={handleCheckboxChange}
color='default'
/>{' '}
</td>
<td className={classes.Td}>{data.label}</td>
<td className={classes.Td}>{data.name}</td>
</tr>
);
})}
</tbody>
<Grid container spacing={2}>
<Grid item xs={12}>
<div style={{ backgroundColor: '#E9E9E9', width: '100%' }}>
<Typography
variant='body1'
className={classes.typography}
style={{
marginTop: '10px',
marginBottom: '30px',
font: 'normal normal medium 20px/24px Allstate Sans W',
}}
>
UNSCHEDULER PERSONAL PROPERTY{' '}
</Typography>
</div>
</Grid>
</Grid>
<tbody className={classes.Table}>
{Unscheduler_pp.map((data) => {
return (
<tr>
<td className={classes.Td_Checkbox}>
{' '}
<Checkbox
id={data.name}
onChange={handleCheckboxChange}
color='default'
/>{' '}
</td>
<td className={classes.Td}>{data.label}</td>
<td className={classes.Td}>{data.name}</td>
</tr>
);
})}
</tbody>
{console.log(participant)}
</div>
);
} else {
return <div></div>;
}
}