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