handle update data in tab dashboard
This commit is contained in:
@@ -10,10 +10,60 @@ import Allergies from "./allergies";
|
||||
import Surgeries from "./surgeries";
|
||||
import FamilyHistory from "./familyHistory";
|
||||
import Relatives from "./relatives";
|
||||
import { request } from "@/services/response";
|
||||
import { changeData } from "./function";
|
||||
|
||||
function DetailUser({ user, isTurnsDetails, setIsTurnsDetails, dataUser }) {
|
||||
function DetailUser({
|
||||
user,
|
||||
dataUser,
|
||||
userInfo,
|
||||
isTurnsDetails,
|
||||
setIsTurnsDetails,
|
||||
}) {
|
||||
const [tab, setTab] = useState(0);
|
||||
const [data, setData] = useState(profileData[0]);
|
||||
const {
|
||||
name,
|
||||
description,
|
||||
birthday,
|
||||
insurance_id,
|
||||
basic_insurance,
|
||||
blood_type,
|
||||
education,
|
||||
fathers_name,
|
||||
gender,
|
||||
home_phone,
|
||||
job,
|
||||
marital_status,
|
||||
national_code,
|
||||
national_code_approved,
|
||||
supplementary_insurance,
|
||||
work_phone,
|
||||
address,
|
||||
other,
|
||||
} = dataUser;
|
||||
const [data, setData] = useState({
|
||||
name: name,
|
||||
description: description,
|
||||
birthday: birthday,
|
||||
insurance_id: insurance_id,
|
||||
basic_insurance: basic_insurance,
|
||||
blood_type: blood_type,
|
||||
education: education,
|
||||
fathers_name: fathers_name,
|
||||
gender: gender,
|
||||
home_phone: home_phone,
|
||||
job: job,
|
||||
marital_status: marital_status,
|
||||
national_code: national_code,
|
||||
national_code_approved: national_code_approved,
|
||||
supplementary_insurance: supplementary_insurance,
|
||||
work_phone: work_phone,
|
||||
address: address,
|
||||
other: other,
|
||||
});
|
||||
console.log(data);
|
||||
console.log(dataUser);
|
||||
console.log(userInfo);
|
||||
|
||||
const listTab = [
|
||||
"اطلاعات عمومی",
|
||||
@@ -26,40 +76,24 @@ function DetailUser({ user, isTurnsDetails, setIsTurnsDetails, dataUser }) {
|
||||
];
|
||||
|
||||
const handleChange = (_, newValue) => setTab(newValue);
|
||||
const changeData = (action, name, id, payload) => {
|
||||
const newData = {
|
||||
...data,
|
||||
[name]: [...data[name]],
|
||||
};
|
||||
|
||||
switch (action) {
|
||||
case "update":
|
||||
newData[name][id] = payload;
|
||||
break;
|
||||
|
||||
case "add":
|
||||
newData[name].push(payload);
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
newData[name].splice(id, 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn(`Unknown action: ${action}`);
|
||||
return;
|
||||
}
|
||||
setData(newData);
|
||||
const updateData = () => {
|
||||
request
|
||||
.patchUserProfile(data, data.uuid)
|
||||
.then((res) => {})
|
||||
.catch((err) => {});
|
||||
};
|
||||
|
||||
const components = [
|
||||
<Information
|
||||
user={user}
|
||||
data={data}
|
||||
setData={setData}
|
||||
userInfo={userInfo}
|
||||
dataUser={dataUser}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
/>,
|
||||
<Disease data={data} />,
|
||||
<Disease data={data} setData={setData} updateData={updateData} />,
|
||||
<Allergies data={data} changeData={changeData} />,
|
||||
<Medications data={data} changeData={changeData} />,
|
||||
<Surgeries data={data} changeData={changeData} />,
|
||||
|
||||
Reference in New Issue
Block a user