change fields component & handle edit, delete, add data and save & change functional page doctor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import HeadTab from "../content/HeadTab";
|
||||
import { request } from "@/services/response";
|
||||
import { setNewData } from "./function";
|
||||
@@ -11,71 +11,13 @@ import Allergies from "./allergies";
|
||||
import Surgeries from "./surgeries";
|
||||
import FamilyHistory from "./familyHistory";
|
||||
import Relatives from "./relatives";
|
||||
import { dieses } from "./information/dieses";
|
||||
import { removeAdditionalKeysDashboard } from "@/helper";
|
||||
import Cookies from "js-cookie";
|
||||
import { getParsedUserInfo } from "@/helper";
|
||||
|
||||
function DetailUser({
|
||||
user,
|
||||
dataUser,
|
||||
userInfo,
|
||||
isTurnsDetails,
|
||||
updateDataUser,
|
||||
setIsTurnsDetails,
|
||||
}) {
|
||||
function DetailUser({ user, isTurnsDetails, setIsTurnsDetails }) {
|
||||
const [tab, setTab] = useState(0);
|
||||
const [information, setInformation] = useState();
|
||||
const [prevInfo, setPrevInfo] = useState();
|
||||
const initialData = {
|
||||
name: dataUser?.name,
|
||||
description: dataUser?.description,
|
||||
birthday: dataUser?.birthday,
|
||||
basic_insurance: [dataUser?.basic_insurance?.id],
|
||||
blood_type: dataUser?.blood_type,
|
||||
education: dataUser?.education,
|
||||
fathers_name: dataUser?.fathers_name,
|
||||
gender: dataUser?.gender,
|
||||
home_phone: dataUser?.home_phone,
|
||||
job: dataUser?.job,
|
||||
marital_status: dataUser?.marital_status,
|
||||
supplementary_insurance: dataUser?.supplementary_insurance,
|
||||
work_phone: dataUser?.work_phone,
|
||||
address: dataUser?.address,
|
||||
other: dataUser?.other,
|
||||
national_code: dataUser?.national_code,
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const parsedUserInfo = getParsedUserInfo();
|
||||
|
||||
if (parsedUserInfo) {
|
||||
request
|
||||
.getUserProfile(parsedUserInfo.uuid)
|
||||
.then((res) => {
|
||||
setInformation(res);
|
||||
setPrevInfo(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
// handle Error
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!dataUser) {
|
||||
initialData.other = [
|
||||
{
|
||||
disease: dieses,
|
||||
allergies: [],
|
||||
medications: [],
|
||||
surgeries: [],
|
||||
family_history: [],
|
||||
relatives: [],
|
||||
},
|
||||
];
|
||||
}
|
||||
const [data, setData] = useState(initialData);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const listTab = [
|
||||
@@ -90,9 +32,14 @@ function DetailUser({
|
||||
|
||||
const handleChange = (_, newValue) => setTab(newValue);
|
||||
const updateData = () => {
|
||||
const usedKays = removeAdditionalKeysDashboard(information);
|
||||
setLoading(true);
|
||||
request
|
||||
.patchUserProfile(data, dataUser.uuid)
|
||||
.patchUserProfile(
|
||||
usedKays,
|
||||
information?.uuid,
|
||||
Cookies.get("access_token")
|
||||
)
|
||||
.then(() => {
|
||||
setLoading(false);
|
||||
})
|
||||
@@ -101,55 +48,42 @@ function DetailUser({
|
||||
});
|
||||
};
|
||||
const changeData = (action, name, id, payload) =>
|
||||
setNewData(action, name, id, payload, data, setData);
|
||||
setNewData(action, name, id, payload, information, setInformation);
|
||||
|
||||
const components = [
|
||||
<Information
|
||||
user={user}
|
||||
data={data}
|
||||
setData={setData}
|
||||
prevInfo={prevInfo}
|
||||
userInfo={userInfo}
|
||||
dataUser={dataUser}
|
||||
information={information}
|
||||
initialData={initialData}
|
||||
setInformation={setInformation}
|
||||
updateDataUser={updateDataUser}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
/>,
|
||||
<Information information={information} setInformation={setInformation} />,
|
||||
<Disease
|
||||
data={data}
|
||||
setData={setData}
|
||||
data={information}
|
||||
setData={setInformation}
|
||||
loading={loading}
|
||||
updateData={updateData}
|
||||
/>,
|
||||
<Allergies
|
||||
data={data}
|
||||
data={information}
|
||||
loading={loading}
|
||||
changeData={changeData}
|
||||
updateData={updateData}
|
||||
/>,
|
||||
<Medications
|
||||
data={data}
|
||||
data={information}
|
||||
loading={loading}
|
||||
changeData={changeData}
|
||||
updateData={updateData}
|
||||
/>,
|
||||
<Surgeries
|
||||
data={data}
|
||||
data={information}
|
||||
loading={loading}
|
||||
changeData={changeData}
|
||||
updateData={updateData}
|
||||
/>,
|
||||
<FamilyHistory
|
||||
data={data}
|
||||
data={information}
|
||||
loading={loading}
|
||||
changeData={changeData}
|
||||
updateData={updateData}
|
||||
/>,
|
||||
<Relatives
|
||||
data={data}
|
||||
data={information}
|
||||
loading={loading}
|
||||
changeData={changeData}
|
||||
updateData={updateData}
|
||||
@@ -165,7 +99,7 @@ function DetailUser({
|
||||
handleChange={handleChange}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
inactives={dataUser ? [] : [1, 2, 3, 4, 5, 6]}
|
||||
inactives={information?.prev_data ? [] : [1, 2, 3, 4, 5, 6]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user