handle update data in tab dashboard
This commit is contained in:
@@ -24,7 +24,9 @@ function AutoSelector({
|
||||
return option?.name || option?.label || "";
|
||||
}}
|
||||
className="!w-full !rounded-lg auto-complete-selector"
|
||||
onChange={(e, newValue) => updateData(name, newValue?.label || "")}
|
||||
onChange={(e, newValue) => {
|
||||
updateData(name, newValue?.label || newValue || "");
|
||||
}}
|
||||
sx={{
|
||||
...styleTextSelectRight,
|
||||
// Hide Icon Number
|
||||
|
||||
@@ -3,6 +3,7 @@ import { defineAbilitiesFor } from "@/lib/ability";
|
||||
import { getUser } from "@/lib/auth";
|
||||
import { getStateInfo } from "@/lib/getStateInfo";
|
||||
import { fetchReq } from "@/lib/req";
|
||||
import { removeToken } from "@/utils";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
@@ -13,22 +14,20 @@ export default async function Dashboard({ searchParams }) {
|
||||
const cookieStore = cookies();
|
||||
const token = cookieStore.get("access_token");
|
||||
const userInfo = cookieStore.get("userInfo");
|
||||
console.log(userInfo.value.uuid);
|
||||
|
||||
if (!ability.can("access", "Dashboard")) {
|
||||
return redirect("/");
|
||||
removeToken();
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
const response = await fetchReq(
|
||||
`https://back-dev.clinic-pro.ir/api/v1/user-profile/${userInfo.value.uuid}`,
|
||||
`https://back-dev.clinic-pro.ir/api/v1/user-profile/${JSON.parse(userInfo?.value).uuid}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.value}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((res) => console.log(res))
|
||||
.catch((err) => console.log(err));
|
||||
);
|
||||
|
||||
const userAgent = headers().get("user-agent") || "";
|
||||
const isMobile = /Mobi|Android/i.test(userAgent);
|
||||
@@ -40,6 +39,7 @@ export default async function Dashboard({ searchParams }) {
|
||||
params={searchParams}
|
||||
matchedCity={matchedCity}
|
||||
initialTurnsDetails={isMobile}
|
||||
userInfo={JSON.parse(userInfo.value || {})}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,17 @@ import userData from "@/data/userData.json";
|
||||
import DashboardPage from "@/components/dashboard";
|
||||
import UserAccountPage from "./userAccount";
|
||||
|
||||
function Content({ matchedCity, params, logged, initialIsOpenSide, dataUser }) {
|
||||
function Content({
|
||||
matchedCity,
|
||||
userInfo,
|
||||
params,
|
||||
logged,
|
||||
initialIsOpenSide,
|
||||
dataUser,
|
||||
}) {
|
||||
const [value, setValue] = useState(Number(params?.sidebar) || 0);
|
||||
const [isOpenSide, setIsOpenSide] = useState(initialIsOpenSide);
|
||||
const [isTurnsDetails, setIsTurnsDetails] = useState(false);
|
||||
console.log(dataUser);
|
||||
|
||||
return (
|
||||
<DashboardPage
|
||||
@@ -27,6 +33,7 @@ function Content({ matchedCity, params, logged, initialIsOpenSide, dataUser }) {
|
||||
<UserAccountPage
|
||||
value={value}
|
||||
dataUser={dataUser}
|
||||
userInfo={userInfo}
|
||||
user={userData.data}
|
||||
setIsOpenSide={setIsOpenSide}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import UpdateList from "@/components/icons/UpdateList";
|
||||
import { Button } from "@mui/material";
|
||||
|
||||
function UpdateBtn() {
|
||||
function UpdateBtn({ updateData }) {
|
||||
return (
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={updateData}
|
||||
className="!border-[#5559CE] !border-[2px] !flex !items-center !justify-center !gap-2 !text-[14px] !font-medium
|
||||
!py-[6px] md:!py-2 lg:!py-[9px] !px-[16px] sm:!px-[23px] md:!px-[29px] lg:!px-[36px] !mr-0 md:!mr-4"
|
||||
>
|
||||
|
||||
@@ -3,31 +3,42 @@ import TextLoading from "@/app/component/loading/Text";
|
||||
import { Switch, TableCell, TableRow } from "@mui/material";
|
||||
import Head from "@/components/dashboard/userAccount/components/Head";
|
||||
import UpdateBtn from "@/components/dashboard/userAccount/components/UpdateBtn";
|
||||
import { useState } from "react";
|
||||
import { dieses } from "../information/dieses";
|
||||
|
||||
function Disease() {
|
||||
function Disease({ data, setData, updateData }) {
|
||||
const { other } = data;
|
||||
const { disease } = other && other[0];
|
||||
const tableHead = ["ردیف", "اسم", "وضعیت", ""];
|
||||
const [data, setData] = useState(dieses);
|
||||
const centerTable = [0];
|
||||
|
||||
const changeData = (id, payload) => {
|
||||
const updatedData = data.map((item, index) =>
|
||||
const newDisease = data.other[0].disease?.map((item, index) =>
|
||||
index === id ? { ...item, status: payload } : item
|
||||
);
|
||||
setData(updatedData);
|
||||
|
||||
const newData = {
|
||||
...data,
|
||||
other: [
|
||||
{
|
||||
...data.other[0],
|
||||
disease: newDisease,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
setData(newData);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="opacity-page">
|
||||
<Head text="لیست بیماری ها" add={false}>
|
||||
<UpdateBtn />
|
||||
<UpdateBtn updateData={updateData} />
|
||||
</Head>
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{data.map((row, idx) => (
|
||||
{disease?.map((row, idx) => (
|
||||
<TableRow
|
||||
key={idx}
|
||||
className="!border-0 !border-b !border-[#DBDBDB] dark:!border-transparent"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
export 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);
|
||||
};
|
||||
@@ -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} />,
|
||||
|
||||
@@ -2,7 +2,6 @@ import Content from "./Content";
|
||||
import DateBirthday from "./DateBirthday";
|
||||
import Field from "./Field";
|
||||
import {
|
||||
insurance,
|
||||
gender,
|
||||
blood_group,
|
||||
marital_status,
|
||||
@@ -11,8 +10,9 @@ import {
|
||||
} from "./listSelector";
|
||||
import AutoSelector from "@/app/component/element/AutoSelector";
|
||||
|
||||
function Form({ data, changeData, prevData }) {
|
||||
const findVal = (list, name) => data && list.find((g) => g.id === data[name]);
|
||||
function Form({ data, userInfo, insurance, changeData, prevData }) {
|
||||
const findVal = (list, name) =>
|
||||
data && list && list.length && list.find((g) => g.id === data[name]);
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-[24px]">
|
||||
@@ -22,8 +22,8 @@ function Form({ data, changeData, prevData }) {
|
||||
iconGray={true}
|
||||
type="number"
|
||||
changeData={changeData}
|
||||
data={data?.work_phone}
|
||||
disable={prevData}
|
||||
data={userInfo?.username}
|
||||
disable={true}
|
||||
name="work_phone"
|
||||
/>
|
||||
</Content>
|
||||
@@ -75,7 +75,9 @@ function Form({ data, changeData, prevData }) {
|
||||
</Content>
|
||||
<Content title="نوع بیمه">
|
||||
<AutoSelector
|
||||
updateData={changeData}
|
||||
updateData={(name, val) => {
|
||||
changeData([Number(val.id)], "value", name);
|
||||
}}
|
||||
value={findVal(insurance, "basic_insurance")}
|
||||
label="نوع بیمه"
|
||||
name="basic_insurance"
|
||||
@@ -88,8 +90,8 @@ function Form({ data, changeData, prevData }) {
|
||||
iconGray={true}
|
||||
type="number"
|
||||
changeData={changeData}
|
||||
data={data?.insurance_number}
|
||||
name="insurance_number"
|
||||
data={data?.supplementary_insurance}
|
||||
name="supplementary_insurance"
|
||||
/>
|
||||
</Content>
|
||||
<Content title="گروه خونی">
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
import { useState } from "react";
|
||||
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";
|
||||
|
||||
function Information({ user, dataUser }) {
|
||||
function Information({ user, data, setData, userInfo, dataUser }) {
|
||||
const [disable, setDisable] = useState(true);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [data, setData] = useState(dataUser || {});
|
||||
const [insurance, setInsurance] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
request
|
||||
.getInsuranceType()
|
||||
.then((res) => {
|
||||
if (res && res.data) {
|
||||
setInsurance(res.data);
|
||||
}
|
||||
})
|
||||
.catch((err) => {});
|
||||
}, []);
|
||||
|
||||
const changeData = (value, type, name) => {
|
||||
disable && setDisable(false);
|
||||
@@ -19,7 +31,10 @@ function Information({ user, dataUser }) {
|
||||
|
||||
const sendReq = () => {
|
||||
setLoading(true);
|
||||
request[dataUser ? "patchUserProfile" : "postUserProfile"](data)
|
||||
request[dataUser ? "patchUserProfile" : "postUserProfile"](
|
||||
data,
|
||||
Cookies.get("uuid")
|
||||
)
|
||||
.then((res) => {
|
||||
setLoading(false);
|
||||
})
|
||||
@@ -30,7 +45,13 @@ function Information({ user, dataUser }) {
|
||||
|
||||
return (
|
||||
<div className="opacity-page">
|
||||
<Form data={data} changeData={changeData} prevData={dataUser} />
|
||||
<Form
|
||||
data={data}
|
||||
userInfo={userInfo}
|
||||
prevData={dataUser}
|
||||
insurance={insurance}
|
||||
changeData={changeData}
|
||||
/>
|
||||
<Button
|
||||
disabled={disable}
|
||||
variant="contained"
|
||||
|
||||
@@ -10,7 +10,6 @@ import Transactions from "./sidebars/transactions";
|
||||
import Turns from "./sidebars/turns";
|
||||
import DownloadD from "@/components/icons/DownloadD";
|
||||
import ArrowRightD from "@/components/icons/ArrowRightD";
|
||||
import { useState } from "react";
|
||||
|
||||
const listTab = [
|
||||
"حساب کاربری",
|
||||
@@ -28,11 +27,13 @@ function UserAccountPage({
|
||||
value,
|
||||
setIsOpenSide,
|
||||
dataUser,
|
||||
userInfo,
|
||||
}) {
|
||||
const sidebars = [
|
||||
<DetailUser
|
||||
user={user}
|
||||
dataUser={dataUser}
|
||||
userInfo={userInfo}
|
||||
isTurnsDetails={isTurnsDetails}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
/>,
|
||||
|
||||
@@ -44,7 +44,13 @@ function SelectSort() {
|
||||
);
|
||||
}}
|
||||
IconComponent={() => (
|
||||
<div className="mx-3 min-w-[20px] md:min-w-[22px] lg:min-w-[24px] min-h-[20px] md:min-h-[22px] lg:min-h-[24px]">
|
||||
<div
|
||||
className="mx-3
|
||||
min-w-[20px] md:min-w-[22px] lg:min-w-[24px] min-h-[20px] md:min-h-[22px] lg:min-h-[24px]
|
||||
max-w-[20px] md:max-w-[22px] lg:max-w-[24px] max-h-[20px] md:max-h-[22px] lg:max-h-[24px]
|
||||
w-[20px] md:w-[22px] lg:w-[24px] h-[20px] md:h-[22px] lg:h-[24px]
|
||||
"
|
||||
>
|
||||
<ArrowBottomD />
|
||||
</div>
|
||||
)}
|
||||
|
||||
+5
-1
@@ -2,7 +2,11 @@ import { cookies } from "next/headers";
|
||||
|
||||
export async function getUser() {
|
||||
const cookieStore = cookies();
|
||||
const raw = cookieStore.get("access_token");
|
||||
const raw =
|
||||
cookieStore.get("access_token") &&
|
||||
cookieStore.get("refresh_token") &&
|
||||
cookieStore.get("uuid") &&
|
||||
cookieStore.get("userInfo");
|
||||
if (!raw) return null;
|
||||
return raw;
|
||||
}
|
||||
|
||||
@@ -34,4 +34,10 @@ export const request = {
|
||||
patchUserProfile: (data, uuid) =>
|
||||
api.patch(`api/v1/user-profile/${uuid}`, data),
|
||||
getUserInfo: (headers) => api.get("oauth/userinfo", headers),
|
||||
getInsuranceType: () =>
|
||||
api.get("api/v1/categorys/insurance_type", {
|
||||
headers: {
|
||||
Authorization: "",
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user