Files
nobat724_front/components/dashboard/userAccount/detailUser/index.js
T
hamedandClaude Opus 4.8 e7db7c705b feat(dashboard): loading spinner and success toast on profile save
The ثبت اطلاعات button gave no feedback. Show a spinner while saving
(both POST and PATCH) and a 'اطلاعات با موفقیت ثبت شد' toast on success,
for the info tab and the medical-history sub-tabs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 22:21:09 +03:30

111 lines
2.9 KiB
JavaScript

import { useState } from "react";
import HeadTab from "../content/HeadTab";
import { request } from "@/services/response";
import { setNewData } from "./function";
// Tabs
import Medications from "./medications";
import Information from "./information";
import Disease from "./disease";
import Allergies from "./allergies";
import Surgeries from "./surgeries";
import FamilyHistory from "./familyHistory";
import Relatives from "./relatives";
import { removeAdditionalKeysDashboard } from "@/helper";
import Cookies from "js-cookie";
import { toast } from "react-toastify";
import LoadingComponent from "@/app/component/LoadingComponent";
function DetailUser({ user, isTurnsDetails, setIsTurnsDetails }) {
const [tab, setTab] = useState(0);
const [information, setInformation] = useState();
const [loading, setLoading] = useState(false);
const listTab = [
"اطلاعات عمومی",
"بیماری‌ها",
"آلرژی‌ها",
"داروهای مصرفی",
"جراحی‌ها",
"سابقه خانوادگی بیماری",
"بستگان",
];
const handleChange = (_, newValue) => setTab(newValue);
const updateData = () => {
const usedKays = removeAdditionalKeysDashboard(information);
setLoading(true);
request
.patchUserProfile(
usedKays,
information?.uuid,
Cookies.get("access_token")
)
.then(() => {
setLoading(false);
toast.success("اطلاعات با موفقیت ثبت شد");
})
.catch(() => {
setLoading(false);
});
};
const changeData = (action, name, id, payload) =>
setNewData(action, name, id, payload, information, setInformation);
const components = [
<Information information={information} setInformation={setInformation} />,
<Disease
data={information}
setData={setInformation}
loading={loading}
updateData={updateData}
/>,
<Allergies
data={information}
loading={loading}
changeData={changeData}
updateData={updateData}
/>,
<Medications
data={information}
loading={loading}
changeData={changeData}
updateData={updateData}
/>,
<Surgeries
data={information}
loading={loading}
changeData={changeData}
updateData={updateData}
/>,
<FamilyHistory
data={information}
loading={loading}
changeData={changeData}
updateData={updateData}
/>,
<Relatives
data={information}
loading={loading}
changeData={changeData}
updateData={updateData}
/>,
];
return (
<HeadTab
tab={tab}
user={user}
listTab={listTab}
components={components}
handleChange={handleChange}
isTurnsDetails={isTurnsDetails}
setIsTurnsDetails={setIsTurnsDetails}
inactives={information?.prev_data ? [] : [1, 2, 3, 4, 5, 6]}
/>
);
}
export default DetailUser;