change fields component & handle edit, delete, add data and save & change functional page doctor
This commit is contained in:
@@ -4,7 +4,7 @@ import { styleTextSelectRight } from "@/mui";
|
||||
function Field({
|
||||
title,
|
||||
error,
|
||||
spaceNull,
|
||||
placeholder,
|
||||
inputProps,
|
||||
type,
|
||||
dir,
|
||||
@@ -21,6 +21,7 @@ function Field({
|
||||
onChange={(e) => updateState(e.target.value)}
|
||||
className="!w-full !mx-auto !bg-[#FFF]"
|
||||
InputProps={inputProps}
|
||||
placeholder={placeholder || ""}
|
||||
sx={{
|
||||
".MuiOutlinedInput-notchedOutline.muirtl-1d3z3hw-MuiOutlinedInput-notchedOutline":
|
||||
{
|
||||
@@ -36,8 +37,8 @@ function Field({
|
||||
MozAppearance: "textfield",
|
||||
},
|
||||
"& .MuiInputBase-input": {
|
||||
padding: spaceNull ? "12.5px 0" : "12.5px 14px",
|
||||
color: spaceNull && "#0009",
|
||||
padding: "12.5px 14px",
|
||||
color: "#0009",
|
||||
},
|
||||
"& .MuiInputBase-root": { borderRadius: "6px !important" },
|
||||
"& .MuiOutlinedInput-notchedOutline": {
|
||||
|
||||
@@ -13,33 +13,17 @@ export default async function Dashboard({ searchParams }) {
|
||||
const ability = defineAbilitiesFor(user);
|
||||
const cookieStore = cookies();
|
||||
const token = cookieStore.get("access_token");
|
||||
const userInfo = cookieStore.get("userInfo");
|
||||
|
||||
if (!ability.can("access", "Dashboard")) {
|
||||
removeToken();
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
const response = await fetchReq(
|
||||
`https://back-dev.clinic-pro.ir/api/v1/user-profile/${JSON.parse(userInfo?.value).uuid}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.value}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const userAgent = headers().get("user-agent") || "";
|
||||
const isMobile = /Mobi|Android/i.test(userAgent);
|
||||
|
||||
return (
|
||||
<Content
|
||||
dataUser={response}
|
||||
logged={token.value}
|
||||
params={searchParams}
|
||||
matchedCity={matchedCity}
|
||||
initialTurnsDetails={isMobile}
|
||||
userInfo={JSON.parse(userInfo.value || {})}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ const listTab = ["درباره کلینیک", "اطلاعات تماس", "پزش
|
||||
function ClinicPage({ data, doctors }) {
|
||||
const [value, setValue] = useState(0);
|
||||
const handleChange = (event, newValue) => setValue(newValue);
|
||||
console.log(data);
|
||||
|
||||
const Components = [
|
||||
<About data={data} />,
|
||||
|
||||
@@ -11,7 +11,6 @@ import specialtiesData from "@/data/specialties.json";
|
||||
function ClinicsPage({ clinics, matchedCity, matchedState }) {
|
||||
const router = useRouter();
|
||||
const [filteredClinics, setFilteredClinics] = useState(clinics);
|
||||
console.log(clinics);
|
||||
|
||||
const [selected, setSelected] = useState({
|
||||
province: matchedState?.name || "",
|
||||
|
||||
@@ -5,29 +5,11 @@ import { useState } from "react";
|
||||
import userData from "@/data/userData.json";
|
||||
import DashboardPage from "@/components/dashboard";
|
||||
import UserAccountPage from "./userAccount";
|
||||
import { request } from "@/services/response";
|
||||
|
||||
function Content({
|
||||
matchedCity,
|
||||
userInfo,
|
||||
params,
|
||||
logged,
|
||||
initialIsOpenSide,
|
||||
dataUser,
|
||||
}) {
|
||||
function Content({ matchedCity, params, logged }) {
|
||||
const [value, setValue] = useState(Number(params?.sidebar) || 0);
|
||||
const [isOpenSide, setIsOpenSide] = useState(initialIsOpenSide);
|
||||
const [isOpenSide, setIsOpenSide] = useState();
|
||||
const [isTurnsDetails, setIsTurnsDetails] = useState(false);
|
||||
const [prevData, setPrevData] = useState(dataUser);
|
||||
|
||||
const updateDataUser = () => {
|
||||
request
|
||||
.getUserProfile(userInfo.uuid)
|
||||
.then((res) => {
|
||||
setPrevData(res);
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardPage
|
||||
@@ -43,11 +25,8 @@ function Content({
|
||||
>
|
||||
<UserAccountPage
|
||||
value={value}
|
||||
dataUser={prevData}
|
||||
userInfo={userInfo}
|
||||
user={userData.data}
|
||||
setIsOpenSide={setIsOpenSide}
|
||||
updateDataUser={updateDataUser}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
/>
|
||||
|
||||
@@ -5,8 +5,7 @@ import ItemAllergie from "./ItemAllergie";
|
||||
import ModalAddAlergie from "./modal";
|
||||
|
||||
function Allergies({ data, changeData, updateData, loading }) {
|
||||
const allergies =
|
||||
data && data.other && data.other[0] && data.other[0].allergies;
|
||||
const allergies = data && data.other && data.other.allergies;
|
||||
const tableHead = ["ردیف", "ماده آلرژیزا", "واکنش", "شدت", ""];
|
||||
const centerTable = [0];
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -22,13 +21,13 @@ function Allergies({ data, changeData, updateData, loading }) {
|
||||
changeData={changeData}
|
||||
/>
|
||||
</Head>
|
||||
{allergies.length ? (
|
||||
{allergies?.length ? (
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{allergies.map((row, idx) => (
|
||||
{allergies?.map((row, idx) => (
|
||||
<ItemAllergie
|
||||
key={idx}
|
||||
row={row}
|
||||
|
||||
@@ -5,23 +5,21 @@ import Head from "@/components/dashboard/userAccount/components/Head";
|
||||
import UpdateBtn from "@/components/dashboard/userAccount/components/UpdateBtn";
|
||||
|
||||
function Disease({ data, setData, updateData, loading }) {
|
||||
const disease = data && data.other && data.other[0] && data.other[0].disease;
|
||||
const disease = data && data.other && data.other.disease;
|
||||
const tableHead = ["ردیف", "اسم", "وضعیت", ""];
|
||||
const centerTable = [0];
|
||||
|
||||
const changeData = (id, payload) => {
|
||||
const newDisease = data.other[0].disease?.map((item, index) =>
|
||||
const newDisease = data.other.disease?.map((item, index) =>
|
||||
index === id ? { ...item, status: payload } : item
|
||||
);
|
||||
|
||||
const newData = {
|
||||
...data,
|
||||
other: [
|
||||
{
|
||||
...data.other[0],
|
||||
disease: newDisease,
|
||||
},
|
||||
],
|
||||
other: {
|
||||
...data.other,
|
||||
disease: newDisease,
|
||||
},
|
||||
};
|
||||
|
||||
setData(newData);
|
||||
|
||||
@@ -5,8 +5,7 @@ import ModalAddHistory from "./modal";
|
||||
import ItemHistory from "./ItemHistory";
|
||||
|
||||
function FamilyHistory({ data, changeData, loading, updateData }) {
|
||||
const family_history =
|
||||
data && data.other && data.other[0] && data.other[0].family_history;
|
||||
const family_history = data && data.other && data.other.family_history;
|
||||
const tableHead = ["ردیف", "بیماری", "نسبت خانوادگی", ""];
|
||||
const centerTable = [0];
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -22,13 +21,13 @@ function FamilyHistory({ data, changeData, loading, updateData }) {
|
||||
updateData={updateData}
|
||||
/>
|
||||
</Head>
|
||||
{family_history.length ? (
|
||||
{family_history?.length ? (
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{family_history.map((row, idx) => (
|
||||
{family_history?.map((row, idx) => (
|
||||
<ItemHistory
|
||||
key={idx}
|
||||
row={row}
|
||||
|
||||
@@ -6,15 +6,15 @@ export const setNewData = (action, name, id, payload, data, setData) => {
|
||||
|
||||
switch (action) {
|
||||
case "update":
|
||||
newData.other[0][name][id] = payload;
|
||||
newData.other[name][id] = payload;
|
||||
break;
|
||||
|
||||
case "add":
|
||||
newData.other[0][name].push(payload);
|
||||
newData.other[name].push(payload);
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
newData.other[0][name].splice(id, 1);
|
||||
newData.other[name].splice(id, 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -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]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import ArrowLeftWhiteD from "@/components/icons/ArrowLeftWhiteD";
|
||||
import {
|
||||
handleTimeExpiresToken,
|
||||
removeAdditionalKeysDashboard,
|
||||
} from "@/helper";
|
||||
import { request } from "@/services/response";
|
||||
import { Button } from "@mui/material";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
function ButtonSendData({
|
||||
loading,
|
||||
errors,
|
||||
information,
|
||||
setInformation,
|
||||
setLoading,
|
||||
setErrors,
|
||||
}) {
|
||||
const handleErrReq = (err) => {
|
||||
const errors = err?.response?.data;
|
||||
if (errors) {
|
||||
setErrors(typeof errors === "string" ? {} : errors);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const postData = () => {
|
||||
request
|
||||
.postUserProfile(information)
|
||||
.then((response) => {
|
||||
if (response.uuid) {
|
||||
const formData = new URLSearchParams();
|
||||
formData.append("grant_type", "refresh_token");
|
||||
formData.append("client_id", process.env.NEXT_PUBLIC_CLIENT_ID);
|
||||
formData.append(
|
||||
"client_secret",
|
||||
process.env.NEXT_PUBLIC_CLIENT_SECRET
|
||||
);
|
||||
formData.append("refresh_token", Cookies.get("refresh_token"));
|
||||
|
||||
request
|
||||
.postRefreshToken(formData)
|
||||
.then((res) => {
|
||||
const expiresTime = handleTimeExpiresToken(res.expires_in);
|
||||
Cookies.set("access_token", res.access_token, {
|
||||
expires: expiresTime.accessTokenExpires,
|
||||
path: "/",
|
||||
secure: true,
|
||||
sameSite: "strict",
|
||||
});
|
||||
|
||||
setInformation({
|
||||
...information,
|
||||
prev_data: true,
|
||||
uuid: response.uuid,
|
||||
});
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
handleErrReq(err);
|
||||
});
|
||||
};
|
||||
|
||||
const patchData = () => {
|
||||
const usedKays = removeAdditionalKeysDashboard(information);
|
||||
|
||||
request
|
||||
.patchUserProfile(
|
||||
usedKays,
|
||||
information?.uuid,
|
||||
Cookies.get("access_token")
|
||||
)
|
||||
.then(() => {
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err) => handleErrReq(err));
|
||||
};
|
||||
|
||||
const sendReq = () => {
|
||||
setLoading(true);
|
||||
|
||||
information.prev_data ? patchData() : postData();
|
||||
};
|
||||
const isDisabled = () => {
|
||||
return loading || Object.values(errors).some(Boolean) || !information;
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={sendReq}
|
||||
loading={loading}
|
||||
disabled={isDisabled()}
|
||||
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>
|
||||
);
|
||||
}
|
||||
|
||||
export default ButtonSendData;
|
||||
@@ -11,20 +11,14 @@ import {
|
||||
job,
|
||||
} from "./listSelector";
|
||||
|
||||
function Form({
|
||||
data,
|
||||
userInfo,
|
||||
insurance,
|
||||
errors,
|
||||
prevInfo,
|
||||
changeData,
|
||||
prevData,
|
||||
}) {
|
||||
function Form({ insurance, errors, changeData, information }) {
|
||||
const findVal = (list, name) =>
|
||||
data && list && list.length && list.find((g) => g.id === data[name]);
|
||||
console.log(errors);
|
||||
list &&
|
||||
list.length &&
|
||||
information &&
|
||||
information[name] &&
|
||||
list.find((g) => g.id === information[name]);
|
||||
const parsedUserInfo = getParsedUserInfo();
|
||||
console.log(parsedUserInfo);
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-x-[24px] gap-y-[10px]">
|
||||
@@ -36,7 +30,7 @@ function Form({
|
||||
name="work_phone"
|
||||
isTransparent={true}
|
||||
changeData={changeData}
|
||||
data={userInfo?.username}
|
||||
data={parsedUserInfo?.username}
|
||||
/>
|
||||
</Content>
|
||||
<Content error={errors?.national_code} title="کد ملی" isConfirmed={false}>
|
||||
@@ -47,8 +41,8 @@ function Form({
|
||||
name="national_code"
|
||||
isTransparent={true}
|
||||
changeData={changeData}
|
||||
data={data?.national_code}
|
||||
disable={prevInfo && prevInfo.national_code}
|
||||
data={information?.national_code}
|
||||
disable={information?.prev_data}
|
||||
/>
|
||||
</Content>
|
||||
<Content error={errors?.name} title="نام" isConfirmed={false}>
|
||||
@@ -57,7 +51,7 @@ function Form({
|
||||
isTransparent={true}
|
||||
iconGray={true}
|
||||
changeData={changeData}
|
||||
data={data?.name}
|
||||
data={information?.name}
|
||||
name="name"
|
||||
/>
|
||||
</Content>
|
||||
@@ -67,7 +61,7 @@ function Form({
|
||||
isTransparent={true}
|
||||
iconGray={true}
|
||||
changeData={changeData}
|
||||
data={data?.family}
|
||||
data={information?.family}
|
||||
name="family"
|
||||
/>
|
||||
</Content>
|
||||
@@ -86,7 +80,7 @@ function Form({
|
||||
<Content error={errors?.birthday} title="تاریخ تولد">
|
||||
<DateBirthday
|
||||
error={errors?.birthday}
|
||||
data={data?.birthday}
|
||||
data={information?.birthday}
|
||||
isConfirmed={false}
|
||||
changeData={changeData}
|
||||
/>
|
||||
@@ -97,18 +91,23 @@ function Form({
|
||||
isTransparent={true}
|
||||
iconGray={true}
|
||||
changeData={changeData}
|
||||
data={data?.fathers_name}
|
||||
data={information?.fathers_name}
|
||||
name="fathers_name"
|
||||
/>
|
||||
</Content>
|
||||
<Content title="نوع بیمه">
|
||||
<Content error={errors?.basic_insurance} title="نوع بیمه">
|
||||
<AutoSelector
|
||||
error={errors?.basic_insurance}
|
||||
updateData={(name, val) => {
|
||||
changeData([Number(val.id)], name);
|
||||
}}
|
||||
// value={findVal(insurance, "basic_insurance", true)?.name}
|
||||
value={insurance?.find(
|
||||
(g) => Number(g.id) === data.basic_insurance[0]
|
||||
(g) =>
|
||||
Number(g.id) ===
|
||||
(information?.basic_insurance
|
||||
? information?.basic_insurance[0]
|
||||
: false)
|
||||
)}
|
||||
name="basic_insurance"
|
||||
label="نوع بیمه"
|
||||
@@ -126,9 +125,9 @@ function Form({
|
||||
iconGray={true}
|
||||
type="number"
|
||||
changeData={changeData}
|
||||
data={data?.insurance_id}
|
||||
data={information?.insurance_id}
|
||||
name="insurance_id"
|
||||
// data={data?.supplementary_insurance}
|
||||
// data={information?.supplementary_insurance}
|
||||
// name="supplementary_insurance"
|
||||
/>
|
||||
</Content>
|
||||
@@ -162,7 +161,7 @@ function Form({
|
||||
iconGray={true}
|
||||
type="number"
|
||||
changeData={changeData}
|
||||
data={data?.home_phone}
|
||||
data={information?.home_phone}
|
||||
name="home_phone"
|
||||
/>
|
||||
</Content>
|
||||
@@ -170,10 +169,7 @@ function Form({
|
||||
<AutoSelector
|
||||
error={errors?.education}
|
||||
updateData={(name, value) =>
|
||||
changeData(
|
||||
education.find((g) => g.label === value).id,
|
||||
name
|
||||
)
|
||||
changeData(education.find((g) => g.label === value).id, name)
|
||||
}
|
||||
value={findVal(education, "education")}
|
||||
label="تحصیلات"
|
||||
@@ -199,7 +195,7 @@ function Form({
|
||||
type="number"
|
||||
iconGray={true}
|
||||
changeData={changeData}
|
||||
data={data?.work_phone}
|
||||
data={information?.work_phone}
|
||||
name="work_phone"
|
||||
/>
|
||||
</Content>
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export const dieses = [
|
||||
export const disease = [
|
||||
{
|
||||
id: 1,
|
||||
name: "فشار خون",
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import ItemMedication from "./ItemMedication";
|
||||
import ModalAddMedications from "./modal";
|
||||
|
||||
function Medications({ data, changeData, updateData, loading }) {
|
||||
const medications =
|
||||
data && data.other && data.other[0] && data.other[0].medications;
|
||||
const medications = data && data.other && data.other.medications;
|
||||
const tableHead = ["ردیف", "نام دارو", "دوز مصرفی", "تعداد و زمان مصرف", ""];
|
||||
const centerTable = [0];
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -22,13 +21,13 @@ function Medications({ data, changeData, updateData, loading }) {
|
||||
changeData={changeData}
|
||||
/>
|
||||
</Head>
|
||||
{medications.length ? (
|
||||
{medications?.length ? (
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{medications.map((row, idx) => (
|
||||
{medications?.map((row, idx) => (
|
||||
<ItemMedication
|
||||
key={idx}
|
||||
row={row}
|
||||
|
||||
@@ -5,8 +5,7 @@ import ModalAddRelatives from "./modal";
|
||||
import ItemRelatives from "./ItemRelatives";
|
||||
|
||||
function Relatives({ data, changeData, loading, updateData }) {
|
||||
const relatives =
|
||||
data && data.other && data.other[0] && data.other[0].relatives;
|
||||
const relatives = data && data.other && data.other.relatives;
|
||||
const tableHead = ["ردیف", "نام", "نسبت", "شماره تماس", "آدرس", ""];
|
||||
const centerTable = [0];
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -22,13 +21,13 @@ function Relatives({ data, changeData, loading, updateData }) {
|
||||
updateData={updateData}
|
||||
/>
|
||||
</Head>
|
||||
{relatives.length ? (
|
||||
{relatives?.length ? (
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{relatives.map((row, idx) => (
|
||||
{relatives?.map((row, idx) => (
|
||||
<ItemRelatives
|
||||
key={idx}
|
||||
row={row}
|
||||
|
||||
@@ -5,8 +5,7 @@ import ItemSurgeries from "./ItemSurgeries";
|
||||
import ModalAddSurgeries from "./modal";
|
||||
|
||||
function Surgeries({ data, changeData, loading, updateData }) {
|
||||
const surgeries =
|
||||
data && data.other && data.other[0] && data.other[0].surgeries;
|
||||
const surgeries = data && data.other && data.other.surgeries;
|
||||
const tableHead = [
|
||||
"ردیف",
|
||||
"نوع جراحی",
|
||||
@@ -28,13 +27,13 @@ function Surgeries({ data, changeData, loading, updateData }) {
|
||||
changeData={changeData}
|
||||
/>
|
||||
</Head>
|
||||
{surgeries.length ? (
|
||||
{surgeries?.length ? (
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{surgeries.map((row, idx) => (
|
||||
{surgeries?.map((row, idx) => (
|
||||
<ItemSurgeries
|
||||
key={idx}
|
||||
row={row}
|
||||
|
||||
@@ -26,17 +26,11 @@ function UserAccountPage({
|
||||
setIsTurnsDetails,
|
||||
value,
|
||||
setIsOpenSide,
|
||||
updateDataUser,
|
||||
dataUser,
|
||||
userInfo,
|
||||
}) {
|
||||
const sidebars = [
|
||||
<DetailUser
|
||||
user={user}
|
||||
dataUser={dataUser}
|
||||
userInfo={userInfo}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
updateDataUser={updateDataUser}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
/>,
|
||||
<Turns user={user} loading={false} setIsTurnsDetails={setIsTurnsDetails} />,
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import Field from "@/app/component/element/Field";
|
||||
import {
|
||||
changeNumToDefault,
|
||||
formatPhoneNumber,
|
||||
validatePhoneNumber,
|
||||
} from "@/helper";
|
||||
import { validatePhoneNumber } from "@/helper";
|
||||
import { request } from "@/services/response";
|
||||
import { InputAdornment, Button } from "@mui/material";
|
||||
import Link from "next/link";
|
||||
@@ -14,15 +10,14 @@ function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleChange = (val) => {
|
||||
const formatted = formatPhoneNumber(val);
|
||||
const checkedNum = validatePhoneNumber(formatted);
|
||||
const checkedNum = validatePhoneNumber(val);
|
||||
setError(checkedNum);
|
||||
setNum(formatted);
|
||||
setNum(val);
|
||||
};
|
||||
const handleReq = async () => {
|
||||
setLoading(true);
|
||||
request
|
||||
.sendCode(changeNumToDefault(num), "")
|
||||
.sendCode(num, "")
|
||||
.then((response) => {
|
||||
setLoading(false);
|
||||
if (response.uuid) {
|
||||
@@ -52,26 +47,7 @@ function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity }) {
|
||||
value={num}
|
||||
type="tel"
|
||||
error={!error.valid}
|
||||
spaceNull={true}
|
||||
inputProps={{
|
||||
startAdornment: (
|
||||
<InputAdornment
|
||||
className="!ml-4"
|
||||
position="start"
|
||||
sx={{
|
||||
".MuiTypography-root": {
|
||||
lineHeight: "0 !important",
|
||||
},
|
||||
".muirtl-1qj5e5k-MuiTypography-root": {
|
||||
color: "#000000de !important",
|
||||
},
|
||||
}}
|
||||
>
|
||||
09
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
title="شماره همراه"
|
||||
placeholder="09xxxxxxxxx"
|
||||
updateState={handleChange}
|
||||
/>
|
||||
<p
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Button } from "@mui/material";
|
||||
import { request } from "@/services/response";
|
||||
import Cookies from "js-cookie";
|
||||
import { handleTimeExpiresToken } from "@/helper";
|
||||
|
||||
function SendReq({
|
||||
loading,
|
||||
@@ -30,29 +31,24 @@ function SendReq({
|
||||
};
|
||||
|
||||
const handleSetCookie = (response) => {
|
||||
const accessTokenExpires = new Date();
|
||||
accessTokenExpires.setSeconds(
|
||||
accessTokenExpires.getSeconds() + response.expires_in
|
||||
);
|
||||
const refreshTokenExpires = new Date();
|
||||
refreshTokenExpires.setDate(refreshTokenExpires.getDate() + 30);
|
||||
const expiresTime = handleTimeExpiresToken(response.expires_in);
|
||||
|
||||
Cookies.set("access_token", response.access_token, {
|
||||
expires: accessTokenExpires,
|
||||
expires: expiresTime.accessTokenExpires,
|
||||
path: "/",
|
||||
secure: true,
|
||||
sameSite: "strict",
|
||||
});
|
||||
|
||||
Cookies.set("refresh_token", response.refresh_token, {
|
||||
expires: refreshTokenExpires,
|
||||
expires: expiresTime.refreshTokenExpires,
|
||||
path: "/",
|
||||
secure: true,
|
||||
sameSite: "strict",
|
||||
});
|
||||
|
||||
Cookies.set("uuid", uuid, {
|
||||
expires: refreshTokenExpires,
|
||||
expires: expiresTime.refreshTokenExpires,
|
||||
path: "/",
|
||||
secure: true,
|
||||
sameSite: "strict",
|
||||
|
||||
+30
-7
@@ -123,17 +123,15 @@ export const formatPhoneNumber = (input) => {
|
||||
};
|
||||
|
||||
export function validatePhoneNumber(input) {
|
||||
const digits = input.replace(/\D/g, "");
|
||||
|
||||
if (!digits) {
|
||||
if (!input) {
|
||||
return { valid: false, text: "شماره موبایل نمیتواند خالی باشد." };
|
||||
}
|
||||
|
||||
if (digits.length !== 9) {
|
||||
if (input.length !== 11) {
|
||||
return { valid: false, text: "شماره موبایل باید دقیقا 11 رقم باشد." };
|
||||
}
|
||||
|
||||
const isValid = /^[1-9]\d{8}$/.test(digits);
|
||||
const isValid = /^09\d{9}$/.test(input);
|
||||
if (!isValid) {
|
||||
return { valid: false, text: "شماره موبایل نامعتبر است." };
|
||||
}
|
||||
@@ -185,8 +183,6 @@ export function getCleanNumberValue(value, defaultValue = 0) {
|
||||
return isNaN(number) ? defaultValue : number;
|
||||
}
|
||||
|
||||
export const changeNumToDefault = (num) => `09${num.replace(/\D/g, "")}`;
|
||||
|
||||
export function hasDataChanged(previousData, newData) {
|
||||
const oldDataString = JSON.stringify(
|
||||
previousData,
|
||||
@@ -201,3 +197,30 @@ export const getParsedUserInfo = () => {
|
||||
const parsedUserInfo = user && JSON.parse(user);
|
||||
return parsedUserInfo;
|
||||
};
|
||||
|
||||
export const handleTimeExpiresToken = (expires_in) => {
|
||||
const accessTokenExpires = new Date();
|
||||
accessTokenExpires.setSeconds(accessTokenExpires.getSeconds() + expires_in);
|
||||
const refreshTokenExpires = new Date();
|
||||
refreshTokenExpires.setDate(refreshTokenExpires.getDate() + 30);
|
||||
|
||||
return {
|
||||
accessTokenExpires,
|
||||
refreshTokenExpires,
|
||||
};
|
||||
};
|
||||
|
||||
export const removeAdditionalKeysDashboard = (information) => {
|
||||
const {
|
||||
national_code,
|
||||
changed,
|
||||
created,
|
||||
id,
|
||||
status,
|
||||
prev_data,
|
||||
uuid,
|
||||
...usedKays
|
||||
} = information;
|
||||
|
||||
return usedKays;
|
||||
};
|
||||
|
||||
+22
-2
@@ -29,10 +29,22 @@ export const request = {
|
||||
},
|
||||
});
|
||||
},
|
||||
postRefreshToken: (formData) => {
|
||||
return api.post("oauth/token", formData, {
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Authorization: "",
|
||||
},
|
||||
});
|
||||
},
|
||||
getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`),
|
||||
postUserProfile: (data) => api.post("api/v1/user-profile", data),
|
||||
patchUserProfile: (data, uuid) =>
|
||||
api.patch(`api/v1/user-profile/${uuid}`, data),
|
||||
patchUserProfile: (data, uuid, token) =>
|
||||
api.patch(`api/v1/user-profile/${uuid}`, data, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}),
|
||||
getUserInfo: (headers) => api.get("oauth/userinfo", headers),
|
||||
getInsuranceType: () =>
|
||||
api.get("api/v1/categorys/insurance_type", {
|
||||
@@ -40,4 +52,12 @@ export const request = {
|
||||
Authorization: "",
|
||||
},
|
||||
}),
|
||||
getAppointmentWeeklySchedule: (uuid) =>
|
||||
api.get(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
|
||||
postAppointmentWeeklySchedule: () =>
|
||||
api.post("api/v1/appointment-settings/weekly-schedule/"),
|
||||
patchAppointmentWeeklySchedule: (uuid) =>
|
||||
api.patch(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
|
||||
deleteAppointmentWeeklySchedule: (uuid) =>
|
||||
api.delete(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user