I'm implementing a worker shift scheduler. See screenshot below:
I receive an array of object from the backend. The first one is for employee list
[{
"employeeId": "id",
"name": "bob"
},{
"employeeId": "id",
"name": "steve",
}]
The second one is available shifts:
[{"shiftStart":"00:00","shiftEnd":"08:00"},{"shiftStart":"08:00","shiftEnd":"15:00"},{"shiftStart":"15:00","shiftEnd":"00:00"}]
This is the React component that I created:
class PlanningShiftManagement extends Component {
render() {
const availableShifts = this.props.shifts.map((shift) => {
return (
<th>
{shift.shiftStart} - {shift.shiftEnd}
</th>
)
})
const employees = this.props.employeeList.map((employee) => {
let employeecheckbox = this.props.shifts.map((shift) => {
return(
<td>
<input type="checkbox" />
</td>
)
});
return(
<tr className="table-row">
<td>{employee.title}</td>
{employeecheckbox}
</tr>
)
})
return(
<div>
<table className="scheduler-table">
<thead className="table-head">
<tr>
<th>Employee Name</th>
{availableShifts}
</tr>
</thead>
<tbody className="table-body">
{employees}
</tbody>
</table>
</div>
);
}
}
Now, my question is, how can I create the state containing the employee and the shift selected. So I want to create an object that I could send to the backend.
[{
"shiftStart": "20170313 10:00",
"shiftEnd": "20170313 17:00",
"employeeId": "id"
}]
