change fields component & handle edit, delete, add data and save & change functional page doctor
This commit is contained in:
@@ -1,34 +1,49 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import Form from "./Form";
|
||||
import { Button } from "@mui/material";
|
||||
import ArrowLeftWhiteD from "@/components/icons/ArrowLeftWhiteD";
|
||||
import { request } from "@/services/response";
|
||||
import Cookies from "js-cookie";
|
||||
import ButtonSendData from "./ButtonSendData";
|
||||
import { getParsedUserInfo } from "@/helper";
|
||||
import { disease } from "../information/disease";
|
||||
|
||||
function Information({
|
||||
user,
|
||||
data,
|
||||
setData,
|
||||
userInfo,
|
||||
prevInfo,
|
||||
dataUser,
|
||||
initialData,
|
||||
information,
|
||||
setInformation,
|
||||
updateDataUser,
|
||||
}) {
|
||||
const [disable, setDisable] = useState(true);
|
||||
const [insurance, setInsurance] = useState();
|
||||
function Information({ information, setInformation }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [insurance, setInsurance] = useState();
|
||||
const [errors, setErrors] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const parsedUserInfo = getParsedUserInfo();
|
||||
|
||||
request.getInsuranceType().then((res) => {
|
||||
if (res && res.data) {
|
||||
setInsurance(res.data);
|
||||
}
|
||||
});
|
||||
// .catch((err) => {});
|
||||
|
||||
if (parsedUserInfo) {
|
||||
request
|
||||
.getUserProfile(parsedUserInfo.uuid)
|
||||
.then((res) => {
|
||||
const changedData = res;
|
||||
changedData.basic_insurance = [Number(res?.basic_insurance?.id)];
|
||||
changedData.prev_data = true;
|
||||
setInformation(changedData);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err?.response?.data === "Entity not found") {
|
||||
setInformation({
|
||||
prev_data: false,
|
||||
other: {
|
||||
disease: disease,
|
||||
allergies: [],
|
||||
medications: [],
|
||||
surgeries: [],
|
||||
family_history: [],
|
||||
relatives: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
const changeData = (value, name) => {
|
||||
@@ -37,70 +52,29 @@ function Information({
|
||||
[name]: value,
|
||||
});
|
||||
if (errors && errors[name]) {
|
||||
setErrors({
|
||||
...errors,
|
||||
setErrors((prevErrors) => ({
|
||||
...prevErrors,
|
||||
[name]: false,
|
||||
});
|
||||
}));
|
||||
}
|
||||
};
|
||||
console.log(information);
|
||||
|
||||
const validationInfo = () => {};
|
||||
|
||||
const sendReq = () => {
|
||||
setLoading(true);
|
||||
console.log(prevInfo);
|
||||
console.log(prevInfo ? true : false);
|
||||
console.log(information);
|
||||
|
||||
if (!validationInfo())
|
||||
request[prevInfo ? "patchUserProfile" : "postUserProfile"](
|
||||
information,
|
||||
prevInfo ? prevInfo.uuid : Cookies.get("uuid")
|
||||
)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
|
||||
if (!dataUser) {
|
||||
updateDataUser();
|
||||
}
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
console.log(err?.response?.data);
|
||||
if (err?.response?.data) {
|
||||
setErrors(err.response.data);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="opacity-page">
|
||||
<Form
|
||||
data={data}
|
||||
errors={errors}
|
||||
userInfo={userInfo}
|
||||
prevInfo={prevInfo}
|
||||
prevData={dataUser}
|
||||
insurance={insurance}
|
||||
changeData={changeData}
|
||||
information={information}
|
||||
/>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={sendReq}
|
||||
<ButtonSendData
|
||||
setInformation={setInformation}
|
||||
information={information}
|
||||
setLoading={setLoading}
|
||||
setErrors={setErrors}
|
||||
loading={loading}
|
||||
disabled={Object.values(errors).find((error) => error)}
|
||||
className={`!gap-[4px] !mr-auto !text-nowrap !flex !flex-nowrap !py-[8px]
|
||||
!rounded-[4px] !text-[14px] md:!text-[16px] !font-medium
|
||||
!mt-[32px] sm:!mt-[38px] md:!mt-[43px] lg:!mt-[48px] !px-[16px] sm:!px-[19px] md:!px-[22px] lg:!px-[24px]
|
||||
`}
|
||||
>
|
||||
ثبت اطلاعات
|
||||
<ArrowLeftWhiteD />
|
||||
</Button>
|
||||
errors={errors}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user