From 53db465a24d727aaeedc5a3578f0247cbb37cb49 Mon Sep 17 00:00:00 2001 From: AmirReza Jamali Date: Tue, 30 Sep 2025 17:31:02 +0330 Subject: [PATCH] feat(profile): display dynamic user data from context The previous profile page was a static placeholder using hardcoded data. This commit refactors the entire component to fetch and display real user information from the `useUser` context, making the page functional. Key changes include: - Replaced static `useState` with the `useUser` context hook for data fetching. - Completely overhauled the UI for a cleaner, more organized, and responsive layout. - Displays dynamic user details such as full name, email, phone number, and join date. - Implemented a `Status` component to visually indicate email and phone verification status. - Added an error fallback for the profile image, showing a default user icon if the image fails to load. - Removed the previous local state management and image upload logic. --- src/app/profile/page.tsx | 231 ++++++++---------- .../Layouts/header/user-info/index.tsx | 40 ++- src/components/ui/Status.tsx | 6 +- 3 files changed, 124 insertions(+), 153 deletions(-) diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index 8aa724e..5f70706 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -1,148 +1,125 @@ "use client"; +import { CheckIcon, CrossIcon, UserIcon } from "@/assets/icons"; +import Status from "@/components/ui/Status"; +import { useUser } from "@/contexts"; +import { formatPhoneNumber, unixToDate } from "@/utils/shared"; import Image from "next/image"; - import { useState } from "react"; -import { CameraIcon } from "./_components/icons"; -import { SocialAccounts } from "./_components/social-accounts"; export default function Page() { - const [data, setData] = useState({ - name: "Danish Heilium", - profilePhoto: "/images/user/user-03.png", - coverPhoto: "/images/cover/cover-01.png", - }); + const { user: data } = useUser(); + const [imageError, setImageError] = useState(false); - const handleChange = (e: any) => { - if (e.target.name === "profilePhoto") { - const file = e.target?.files[0]; - - setData({ - ...data, - profilePhoto: file && URL.createObjectURL(file), - }); - } else if (e.target.name === "coverPhoto") { - const file = e.target?.files[0]; - - setData({ - ...data, - coverPhoto: file && URL.createObjectURL(file), - }); - } else { - setData({ - ...data, - [e.target.name]: e.target.value, - }); - } - }; + const hasProfileImage = data?.profile_image && !imageError; return ( -
-
-
- profile cover -
-