From eea8737778efc1151173589fa69c69fc8a54e932 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Thu, 12 Jun 2025 21:46:27 +0330 Subject: [PATCH] Fix dashboard data requests, update dashboard data handling, change login field type, and redesign home button --- components/dashboard/Content.js | 14 +++++++++++- .../dashboard/userAccount/detailUser/index.js | 22 ++++++++++++++++--- .../detailUser/information/Form.js | 22 +++++++++---------- .../detailUser/information/dieses.js | 22 +++++++++---------- .../detailUser/information/index.js | 15 +++++++++++-- components/dashboard/userAccount/index.js | 2 ++ components/layout/sidebar/Head.js | 12 ++++++++-- components/register/element/OTPForm.js | 3 ++- 8 files changed, 81 insertions(+), 31 deletions(-) diff --git a/components/dashboard/Content.js b/components/dashboard/Content.js index a53fa3d..06c144b 100644 --- a/components/dashboard/Content.js +++ b/components/dashboard/Content.js @@ -5,6 +5,7 @@ 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, @@ -17,6 +18,16 @@ function Content({ const [value, setValue] = useState(Number(params?.sidebar) || 0); const [isOpenSide, setIsOpenSide] = useState(initialIsOpenSide); const [isTurnsDetails, setIsTurnsDetails] = useState(false); + const [prevData, setPrevData] = useState(dataUser); + + const updateDataUser = () => { + request + .getUserProfile(userInfo.uuid) + .then((res) => { + setPrevData(res); + }) + .catch(() => {}); + }; return ( diff --git a/components/dashboard/userAccount/detailUser/index.js b/components/dashboard/userAccount/detailUser/index.js index eb1513e..bb2e439 100644 --- a/components/dashboard/userAccount/detailUser/index.js +++ b/components/dashboard/userAccount/detailUser/index.js @@ -11,15 +11,17 @@ import Allergies from "./allergies"; import Surgeries from "./surgeries"; import FamilyHistory from "./familyHistory"; import Relatives from "./relatives"; +import { dieses } from "./information/dieses"; function DetailUser({ user, dataUser, userInfo, isTurnsDetails, + updateDataUser, setIsTurnsDetails, }) { - const [tab, setTab] = useState(5); + const [tab, setTab] = useState(0); const initialData = { name: dataUser?.name, description: dataUser?.description, @@ -39,6 +41,18 @@ function DetailUser({ national_code: dataUser?.national_code, }; + if (!dataUser) { + initialData.other = [ + { + disease: dieses, + allergies: [], + medications: [], + surgeries: [], + family_history: [], + relatives: [], + }, + ]; + } const [data, setData] = useState(initialData); const [loading, setLoading] = useState(false); @@ -57,10 +71,10 @@ function DetailUser({ setLoading(true); request .patchUserProfile(data, dataUser.uuid) - .then((res) => { + .then(() => { setLoading(false); }) - .catch((err) => { + .catch(() => { setLoading(false); }); }; @@ -74,6 +88,8 @@ function DetailUser({ setData={setData} userInfo={userInfo} dataUser={dataUser} + initialData={initialData} + updateDataUser={updateDataUser} isTurnsDetails={isTurnsDetails} setIsTurnsDetails={setIsTurnsDetails} />, diff --git a/components/dashboard/userAccount/detailUser/information/Form.js b/components/dashboard/userAccount/detailUser/information/Form.js index aa1ca8e..05c0ae0 100644 --- a/components/dashboard/userAccount/detailUser/information/Form.js +++ b/components/dashboard/userAccount/detailUser/information/Form.js @@ -11,23 +11,20 @@ import { import AutoSelector from "@/app/component/element/AutoSelector"; function Form({ data, userInfo, insurance, changeData, prevData }) { - const findVal = (list, name, arr) => - data && - list && - list.length && - list.find((g) => g.id === (arr ? data[name][0] : data[name])); + const findVal = (list, name) => + data && list && list.length && list.find((g) => g.id === data[name]); return (
@@ -81,9 +78,12 @@ function Form({ data, userInfo, insurance, changeData, prevData }) { updateData={(name, val) => { changeData([Number(val.id)], "value", name); }} - value={findVal(insurance, "basic_insurance", true)?.name} - label="نوع بیمه" + // value={findVal(insurance, "basic_insurance", true)?.name} + value={insurance?.find( + (g) => Number(g.id) === data.basic_insurance[0] + )} name="basic_insurance" + label="نوع بیمه" list={insurance} /> diff --git a/components/dashboard/userAccount/detailUser/information/dieses.js b/components/dashboard/userAccount/detailUser/information/dieses.js index 4df03b4..8b9ef16 100644 --- a/components/dashboard/userAccount/detailUser/information/dieses.js +++ b/components/dashboard/userAccount/detailUser/information/dieses.js @@ -7,7 +7,7 @@ export const dieses = [ { id: 2, name: "دیابت", - status: "true", + status: "false", }, { id: 3, @@ -17,17 +17,17 @@ export const dieses = [ { id: 4, name: "بیماری قلبی عروقی", - status: "true", + status: "false", }, { id: 5, name: "سرطان", - status: "true", + status: "false", }, { id: 6, name: "آلزایمر", - status: "true", + status: "false", }, { id: 7, @@ -37,7 +37,7 @@ export const dieses = [ { id: 8, name: "بیماری کلیوی", - status: "true", + status: "false", }, { id: 9, @@ -57,7 +57,7 @@ export const dieses = [ { id: 12, name: "اضطراب مزمن", - status: "true", + status: "false", }, { id: 13, @@ -72,7 +72,7 @@ export const dieses = [ { id: 15, name: "پرکاری تیروئید", - status: "true", + status: "false", }, { id: 16, @@ -87,7 +87,7 @@ export const dieses = [ { id: 18, name: "هپاتیت C", - status: "true", + status: "false", }, { id: 19, @@ -97,17 +97,17 @@ export const dieses = [ { id: 20, name: "COVID-19", - status: "true", + status: "false", }, { id: 21, name: "لوپوس", - status: "true", + status: "false", }, { id: 22, name: "ام‌اس (MS)", - status: "true", + status: "false", }, { id: 23, diff --git a/components/dashboard/userAccount/detailUser/information/index.js b/components/dashboard/userAccount/detailUser/information/index.js index a409f32..2c781bf 100644 --- a/components/dashboard/userAccount/detailUser/information/index.js +++ b/components/dashboard/userAccount/detailUser/information/index.js @@ -5,7 +5,15 @@ import ArrowLeftWhiteD from "@/components/icons/ArrowLeftWhiteD"; import { request } from "@/services/response"; import Cookies from "js-cookie"; -function Information({ user, data, setData, userInfo, dataUser }) { +function Information({ + user, + data, + setData, + userInfo, + dataUser, + initialData, + updateDataUser, +}) { const [disable, setDisable] = useState(true); const [loading, setLoading] = useState(false); const [insurance, setInsurance] = useState(); @@ -18,7 +26,7 @@ function Information({ user, data, setData, userInfo, dataUser }) { setInsurance(res.data); } }) - .catch((err) => {}); + // .catch((err) => {}); }, []); const changeData = (value, type, name) => { @@ -36,6 +44,9 @@ function Information({ user, data, setData, userInfo, dataUser }) { dataUser ? dataUser.uuid : Cookies.get("uuid") ) .then((res) => { + if (!dataUser) { + updateDataUser(); + } setLoading(false); }) .catch((err) => { diff --git a/components/dashboard/userAccount/index.js b/components/dashboard/userAccount/index.js index 9d2148f..32ca0e3 100644 --- a/components/dashboard/userAccount/index.js +++ b/components/dashboard/userAccount/index.js @@ -26,6 +26,7 @@ function UserAccountPage({ setIsTurnsDetails, value, setIsOpenSide, + updateDataUser, dataUser, userInfo, }) { @@ -35,6 +36,7 @@ function UserAccountPage({ dataUser={dataUser} userInfo={userInfo} isTurnsDetails={isTurnsDetails} + updateDataUser={updateDataUser} setIsTurnsDetails={setIsTurnsDetails} />, , diff --git a/components/layout/sidebar/Head.js b/components/layout/sidebar/Head.js index 72ced0a..ed717d6 100644 --- a/components/layout/sidebar/Head.js +++ b/components/layout/sidebar/Head.js @@ -1,6 +1,10 @@ +import Cookies from "js-cookie"; import Image from "next/image"; function Head({ user }) { + const userInfo = Cookies.get("userInfo"); + const parsedInfo = JSON.parse(userInfo); + return (
-

{user.name}

-

{user.phone}

+

+ {parsedInfo.realName} +

+

+ {parsedInfo.username} +

); diff --git a/components/register/element/OTPForm.js b/components/register/element/OTPForm.js index db1d0b3..3f08f94 100644 --- a/components/register/element/OTPForm.js +++ b/components/register/element/OTPForm.js @@ -1,9 +1,10 @@ function OTPForm({ index, value, onChange, inputRef, isError }) { return ( { const val = e.target.value; if (/^\d?$/.test(val)) {