diff --git a/src/components/profile/Profile.jsx b/src/components/profile/Profile.jsx index ca0b4fa..b7b0ca9 100644 --- a/src/components/profile/Profile.jsx +++ b/src/components/profile/Profile.jsx @@ -1,7 +1,6 @@ -/* eslint-disable @next/next/no-img-element */ +import React from "react"; import { useEffect, useState } from "react"; import { AiOutlineEdit, AiOutlineMail, AiOutlinePhone } from "react-icons/ai"; -import { BsBasketFill } from "react-icons/bs"; import { GoLocation } from "react-icons/go"; import { getDocData } from "@/lib/firebase/firestoreFunctions"; @@ -11,30 +10,58 @@ import Button from "@/components/button/Button"; import { useAuth } from "@/context/AuthContext"; import EditProfile from "./EditProfile"; +import { collection, getDocs } from "firebase/firestore"; +import { db } from "@/lib/firebase/firebase"; const Profile = () => { const { currentUser } = useAuth(); const [editProfile, setEditProfile] = useState(false); const [userData, setUserData] = useState({}); + const [hideAltTextBio, setHideAltTextBio] = useState(false); useEffect(() => { - getDocData("users", currentUser.uid).then((data) => { - setUserData(data); - }); + // Fetch user data when the component mounts + getUserData(); }, []); - const { name, avatarUrl, bio, publicEmail, publicPhoneNumber, location } = - userData; + useEffect(() => { + console.log(userData); + }, [userData]); + + async function getUserData() { + try { + const userdata = collection(db, "users"); + const response = await getDocs(userdata); + + const data = response.docs.map((doc) => ({ + data: doc.data(), + publicPhoneNumber: doc.data()["phone number"], + })); + + setUserData(data); + } catch (error) { + console.error("Error fetching user data:", error); + // Handle the error here (e.g., show an error message to the user) + } + } + + const { name, avatarurl, bio, email, location } = userData[0]?.data || {}; + const { publicPhoneNumber } = userData[0] || {}; + + const handleIconClick = () => { + setHideAltTextBio(true); + }; + return ( <> {editProfile && ( { )}

My account

-
-
-
+
+
+
profile
-
-
-
-

- {`${(bio && bio) || "Add Bio"}`} -

-

- {name} -

-
-
-
- -
- {/*
- - {5 + " "} - items -
*/} -
+ {`${(bio && bio) || "Add Bio"}`} +

+
+
+
+ +
+
+
- {publicEmail} + {email}
-
- - +
+ {publicPhoneNumber}
-
- +
+ {location}