handle update data in tab dashboard
This commit is contained in:
@@ -3,31 +3,42 @@ import TextLoading from "@/app/component/loading/Text";
|
||||
import { Switch, TableCell, TableRow } from "@mui/material";
|
||||
import Head from "@/components/dashboard/userAccount/components/Head";
|
||||
import UpdateBtn from "@/components/dashboard/userAccount/components/UpdateBtn";
|
||||
import { useState } from "react";
|
||||
import { dieses } from "../information/dieses";
|
||||
|
||||
function Disease() {
|
||||
function Disease({ data, setData, updateData }) {
|
||||
const { other } = data;
|
||||
const { disease } = other && other[0];
|
||||
const tableHead = ["ردیف", "اسم", "وضعیت", ""];
|
||||
const [data, setData] = useState(dieses);
|
||||
const centerTable = [0];
|
||||
|
||||
const changeData = (id, payload) => {
|
||||
const updatedData = data.map((item, index) =>
|
||||
const newDisease = data.other[0].disease?.map((item, index) =>
|
||||
index === id ? { ...item, status: payload } : item
|
||||
);
|
||||
setData(updatedData);
|
||||
|
||||
const newData = {
|
||||
...data,
|
||||
other: [
|
||||
{
|
||||
...data.other[0],
|
||||
disease: newDisease,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
setData(newData);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="opacity-page">
|
||||
<Head text="لیست بیماری ها" add={false}>
|
||||
<UpdateBtn />
|
||||
<UpdateBtn updateData={updateData} />
|
||||
</Head>
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{data.map((row, idx) => (
|
||||
{disease?.map((row, idx) => (
|
||||
<TableRow
|
||||
key={idx}
|
||||
className="!border-0 !border-b !border-[#DBDBDB] dark:!border-transparent"
|
||||
|
||||
Reference in New Issue
Block a user