Description
I want to create table like this :

However, I have done it well, but I am doubtful of my code, it seems too complicated and not simple.
Here’s my code so far :
const FormCreateRole = ({ switches, onChange }) => {
// Array for table header and its data
const tableHeader = [
"No",
"Menu",
"Sub Menu",
"Lihat",
"Tambah",
"Ubah",
"Hapus",
"Export",
];
const submenu = [
["-"],
[
"Akun Pengguna",
"Grup & Kontrol Hak Akses Akun",
"Antrian Pasien",
"Rawat Jalan",
],
["Pemeriksaan Penunjang", "Rekam Medis", "Admisi Rawat Jalan"],
["Status dan Penempatan Kamar", "Transfer Pasien"],
];
let i = 1;
const tableDataMenu = [
[i++, "Dashboard", submenu[0], "", null, null, null, ""],
[i++, "Konfigurasi/Pengaturan", submenu[1], "", "", "", "", null],
[i++, "Layanan Pasien", submenu[2], "", "", "", "", null],
[i++, "Rawat Inap", submenu[3], "", "", "", "", null],
];
// end Array data
return (
<Table className="table-responsive">
<thead style={{ backgroundColor: "#ECEFF1" }}>
<tr>
{tableHeader.map((header, index) => (
<th
key={index}
className="txt-blue-grey-700 base-md text-bold text-center"
style={{ padding: "0.75rem" }}
>
{header}
</th>
))}
</tr>
</thead>
<tbody>
{tableDataMenu.map((row, idx) => (
<React.Fragment key={idx}>
<tr>
{row.slice(0, 2).map((cell, idx) => (
<td key={idx} className="text-center">
{cell}
</td>
))}
<td>
{row[2] && (
<div>
{row[2].map((sub, idx) => (
<div key={idx} className="mb-3">
{sub}
</div>
))}
</div>
)}
</td>
{row.slice(3).map((cell, idx) => {
return (
<td key={idx}>
{row[2] &&
row[2].map((subIdx) => {
if (cell !== null) {
return (
<div key={subIdx} className="mb-3 text-center">
<Form.Check
type="switch"
id={`${subIdx}-${idx}`}
label=""
checked={switches[`action${idx}`]}
onChange={onChange}
/>
</div>
);
}
})}
</td>
);
})}
</tr>
</React.Fragment>
))}
</tbody>
</Table>
);
};
Question
Can you help me in efficiently, readable and effectively creating the code for the table? I apologize, I am currently learning a lot and struggling to master React JS.
Any help will be appreciated, thank you.