"use client"; import { memo, useMemo } from "react"; import Image from "next/image"; import { useRouter } from "next/navigation"; import icons from "@/constant/images/icons"; import { PATH } from "@/constant/config"; import { QUERY_KEY } from "@/constant/config/enum"; import { useQuery } from "@tanstack/react-query"; import { httpRequest } from "@/services"; import Moment from "react-moment"; import { Cake, Phone, MapPin, Mail, SquareUser, ShieldUser, } from "lucide-react"; import userServices from "@/services/userServices"; import CustomButton from "@/components/customs/custom-button"; import profileServices, { ProfileResponse } from "@/services/profileServices"; import { useSelector } from "react-redux"; import { RootState } from "@/redux/store"; function MainPageProfile() { const router = useRouter(); const { infoUser } = useSelector((state: RootState) => state.user); const profileQuery = useQuery({ queryKey: [QUERY_KEY.table_list_profile], queryFn: async () => { const res = await httpRequest({ showMessageFailed: true, http: profileServices.getProfile(), // Đảm bảo endpoint trỏ về /api/v1/UserProfile/list }); // Trả về đúng object chứa items theo cấu trúc của API return ( res || { items: [], page: 1, pageSize: 10, total: 0, totalPages: 0, } ); }, }); // Tìm kiếm thông tin profile của user hiện tại đang đăng nhập bằng useMemo // eslint-disable-next-line react-hooks/preserve-manual-memoization const currentUserProfile = useMemo(() => { const listItems = profileQuery.data?.items || []; if (!infoUser?.userId) return null; // So khớp accountId của API trả về với userId trong Redux (infoUser) return ( listItems.find((item: any) => item.accountId === infoUser.userId) || null ); }, [profileQuery.data, infoUser?.userId]); return (
{/* HEADER */}

Thông tin tài khoản

Chỉnh sửa
{/* AVATAR */}
avatar
{/* MAIN */}
{/* BASIC INFO */}
Thông tin cơ bản
{/* NAME */}

Họ và tên

{currentUserProfile?.fullName || "---"}
{/* DOB */}

Ngày sinh

{currentUserProfile?.birthDate ? ( {currentUserProfile.birthDate} ) : ( "---" )}
{/* CONTACT */}
Liên hệ
{/* EMAIL */}

Email

{currentUserProfile?.email || "---"}
{/* PHONE */}

Số điện thoại

{currentUserProfile?.phone || "---"}
); } export default memo(MainPageProfile);