From 07a9c539fafed2fefe25a9ab5ccc644712324a7b Mon Sep 17 00:00:00 2001 From: kihan2518B Date: Mon, 15 Jul 2024 20:48:56 +0530 Subject: [PATCH] Show user data to my profile page --- src/app/CustomerDashboard/MyProfile/page.tsx | 34 +++++++------------- src/components/CustomerDashboardBox.tsx | 6 ++-- src/types.index.ts | 14 ++++++++ src/utils/GetDataFromCollection.ts | 7 ++++ 4 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 src/types.index.ts create mode 100644 src/utils/GetDataFromCollection.ts diff --git a/src/app/CustomerDashboard/MyProfile/page.tsx b/src/app/CustomerDashboard/MyProfile/page.tsx index 462ce9a..070a939 100644 --- a/src/app/CustomerDashboard/MyProfile/page.tsx +++ b/src/app/CustomerDashboard/MyProfile/page.tsx @@ -1,32 +1,20 @@ "use client"; +import { useEffect, useState } from "react"; import CustomerDashboardBox from "../../../Components/CustomerDashboardBox"; +import { User } from "@/types.index"; -const userData = { - Name: "abc abc", - Email: "abc@abc.in", - - Address: "123 Main Street", - - Pincode: "123456", - - DateOfBirth: "00-00-0000", - - City: "Visnagar", - - State: "Gujarat", - - Country: "India", - - phone: "90000 00000", +const page = () => { + const [userData, setUserData] = useState({}); - customer: "true", + useEffect(() => { + const UserFromLocalStorage = localStorage.getItem("User"); + const user = JSON.parse(UserFromLocalStorage) + console.log(user); + setUserData(user) + }, []) - seller: "false", -}; - -const page = () => { const displayedUserData = Object.fromEntries( Object.entries(userData).filter( ([key]) => key !== "customer" && key !== "seller" @@ -40,7 +28,7 @@ const page = () => {

- Customer Profile Page + Customer Profile Page

diff --git a/src/components/CustomerDashboardBox.tsx b/src/components/CustomerDashboardBox.tsx index 6c0b980..788881a 100644 --- a/src/components/CustomerDashboardBox.tsx +++ b/src/components/CustomerDashboardBox.tsx @@ -1,12 +1,14 @@ "use client"; import CustomerDashboardPagesAPI from "../API/CustomerDashboardPagesAPI"; - +import { User } from "@/types.index"; import Link from "next/link"; import { usePathname } from "next/navigation"; const page = () => { + const user = localStorage.getItem("User"); + const userObject: User = JSON.parse(user); const pathname = usePathname(); const activePathClassName = "text-gray-950 font-medium"; @@ -18,7 +20,7 @@ const page = () => {

Customer Profile

User Avatar diff --git a/src/types.index.ts b/src/types.index.ts new file mode 100644 index 0000000..75962fe --- /dev/null +++ b/src/types.index.ts @@ -0,0 +1,14 @@ +export interface User { + address: string, + city: string, + country: string, + dateOfBirth: string, + email: string, + isSeller: boolean, + name: string, + phone: string + photo: string, + pincode: string, + state: string, + uid: string +} \ No newline at end of file diff --git a/src/utils/GetDataFromCollection.ts b/src/utils/GetDataFromCollection.ts new file mode 100644 index 0000000..134bcf5 --- /dev/null +++ b/src/utils/GetDataFromCollection.ts @@ -0,0 +1,7 @@ +import { db } from "@/firebase/config"; +import { collection, getDocs} from "firebase/firestore"; + +export const GetDataFromCollection = async (collectionName: string) => { + const querySnapshot = await getDocs(collection(db, collectionName)); + return querySnapshot.docs; +} \ No newline at end of file