From a987a83280bcf81f5124e17276fb4588909fee99 Mon Sep 17 00:00:00 2001 From: ducanh Date: Sat, 30 May 2026 23:05:14 +0700 Subject: [PATCH] feat: implement user profile page with dynamic historian application rendering --- src/app/user/account/page.tsx | 46 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/app/user/account/page.tsx b/src/app/user/account/page.tsx index d319861..1305915 100644 --- a/src/app/user/account/page.tsx +++ b/src/app/user/account/page.tsx @@ -7,38 +7,38 @@ import { UserMetaCardProps } from "@/interface/user"; import { apiGetCurrentUser } from "@/service/auth"; import { setUserData } from "@/store/features/userSlice"; import { useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; +import { RootState } from "@/store/store"; import StickyHeader from "@/components/ui/StickyHeader"; import { SafeHTMLRenderer } from "@/components/ui/parse/SafeHTMLRenderer"; import { apiGetCurrentUserApplications } from "@/service/userService"; import Loading from "@/app/loading"; export default function Profile() { - const [user, setUser] = useState(null); - const [loading, setLoading] = useState(true); - const [application, setApplication] = useState(null); - const [appLoading, setAppLoading] = useState(false); + const currentUser = useSelector((state: RootState) => state.user.data); const dispatch = useDispatch(); - const isHistorian = !!user?.data?.roles?.some( + const [application, setApplication] = useState(null); + const [appLoading, setAppLoading] = useState(false); + + const isHistorian = !!currentUser?.roles?.some( (role: any) => role.name === "HISTORIAN" ); + // Background refresh of user data to ensure eventual consistency useEffect(() => { const fetchUser = async () => { try { const userData = await apiGetCurrentUser(); dispatch(setUserData(userData.data)); - setUser(userData); } catch (err) { console.error("Lỗi:", err); - } finally { - setLoading(false); } }; fetchUser(); }, [dispatch]); + // Fetch applications in parallel immediately if user is a historian useEffect(() => { if (isHistorian) { const fetchApp = async () => { @@ -61,12 +61,16 @@ export default function Profile() { } }, [isHistorian]); - if (loading) { - return ( - - ); + // Only show full page spinner on initial load when Redux state has no cached data + if (!currentUser) { + return ; } + const userMetaProps: UserMetaCardProps = { + data: currentUser, + status: true, + }; + // Nếu người dùng có role là HISTORIAN if (isHistorian) { return ( @@ -74,15 +78,15 @@ export default function Profile() {
- - - + + +
{appLoading ? ( -
- +
+
) : application ? (
@@ -106,9 +110,9 @@ export default function Profile() { Thông tin tài khoản
- - - + + +