diff --git a/client/app/profile/[userId]/page.tsx b/client/app/profile/[userId]/page.tsx index b4dd4f2..ccd7165 100644 --- a/client/app/profile/[userId]/page.tsx +++ b/client/app/profile/[userId]/page.tsx @@ -1,26 +1,45 @@ "use client"; +import BackgroundComponent from "@/components/profile/backgroundComp"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import useGetUserProfile from "@/hooks/user_data/useGetUserProfile"; import { PersonIcon } from "@radix-ui/react-icons"; import { useParams } from "next/navigation"; import { useRouter } from "next/navigation"; +import { EditIcon, Factory, CircleUser } from "lucide-react"; +import {useEffect, useState} from "react"; + + export default function ProfilePage() { - const userId = useParams().userId.toString(); + const router = useRouter(); - const { userData } = useGetUserProfile(userId); + const { user, stsDetails, landfillDetails, getUserDetails} = useGetUserProfile(); // Destructure user and getUserDetails + const [role, setRole] = useState("Role Name"); + const RolePlace = 'Station'; + + useEffect(() => { + getUserDetails(); + setRole(user.roleName); + + }, []); + return ( -
+
+ -
+
+ {user.roleName} +
+
+
@@ -28,12 +47,53 @@ export default function ProfilePage() {

Profile Page

-

ID: {userId}

-

Email: {userData.email}

-

Role: {userData.role}

-

Name: {userData.name}

-

Assigned Area: {userData.assignedArea}

+

ID:

+

Email: {user.email}

+

Role: {user.roleName}

+

Name: {user.profileName}

+

Role Description: {user.roleDescription}

+ +
+ + +
+ + + + {user?.roleName === 'STS_MANAGER' &&
+
STS Details
+

Id: {stsDetails.stsId}

+

STS Name: {stsDetails.stsName}

+

Ward Number: {stsDetails.stsWardNumber}

+

Capacity: {stsDetails.stsCapacity}

+

Current Total Waste: {stsDetails.stsCurrentTotalWaste}

+

Coordinate: {stsDetails.stsLatitude}, {stsDetails.stsLongitude}

+ + +
+ + } + {user?.roleName === 'LAND_MANAGER' &&
+
Landfill Details
+

ID: {landfillDetails.landfillId}

+

Landfill Name: {landfillDetails.landFillName}

+

Capacity: {landfillDetails.landFillCapacity}

+

Current Total Waste: {landfillDetails.landFillCurrentWaste}

+

Coordinate: {landfillDetails.landfillLatitude}, {landfillDetails.landFillLongitude}

+ + +
} + {user?.roleName !== 'STS_MANAGER' && user?.roleName !== 'LAND_MANAGER' && ( +
Oops! Your role has not assigned yet
+ )} +
); diff --git a/client/components/maps/AllStsShow.tsx b/client/components/maps/AllStsShow.tsx index 4bae776..6531a26 100644 --- a/client/components/maps/AllStsShow.tsx +++ b/client/components/maps/AllStsShow.tsx @@ -1,6 +1,7 @@ import useGetAllSTS from "@/hooks/stsdata/useGetAllSTS"; import GoogleMapComponent from "@/components/maps/GoogleMap"; import * as React from "react"; +import useGetUserProfile from "@/hooks/user_data/useGetUserProfile"; type StsShow = { lat: number; @@ -10,6 +11,7 @@ type StsShow = { export const AllStsMapShow = () => { const { getAllSTS, stsCoordinate, storagePercentage } = useGetAllSTS(); + const staticCoordinates: StsShow[] = [ { lat: 23.7031879, lng: 90.35564201 }, @@ -25,6 +27,7 @@ export const AllStsMapShow = () => { React.useEffect(() => { getAllSTS(); + }, []); return ; diff --git a/client/components/profile/backgroundComp.tsx b/client/components/profile/backgroundComp.tsx new file mode 100644 index 0000000..47d8518 --- /dev/null +++ b/client/components/profile/backgroundComp.tsx @@ -0,0 +1,17 @@ +// components/BackgroundComponent.tsx +"use client"; + +import React from 'react'; + +const BackgroundComponent: React.FC = () => { + return ( +
+ +
+ ); +}; + +export default BackgroundComponent; diff --git a/client/data/apiRoutes.ts b/client/data/apiRoutes.ts index 9af7026..e08418d 100644 --- a/client/data/apiRoutes.ts +++ b/client/data/apiRoutes.ts @@ -27,6 +27,7 @@ export const apiRoutes = { edit: `${baseUrl}/landfills/`, }, rbac: { + create: `${baseUrl}/rbac/roles`, getByRole: `${baseUrl}/rbac/roles/get/`, delete: `${baseUrl}/rbac/roles/delete/`, @@ -51,4 +52,7 @@ export const apiRoutes = { makeBill: `${baseUrl}/bills/create-from-trip/`, search: `${baseUrl}/bills/search`, }, + profile: { + getProfile: `${baseUrl}/profile`, + } } \ No newline at end of file diff --git a/client/hooks/user_data/useGetUserProfile.tsx b/client/hooks/user_data/useGetUserProfile.tsx index 5227fbe..ccaa720 100644 --- a/client/hooks/user_data/useGetUserProfile.tsx +++ b/client/hooks/user_data/useGetUserProfile.tsx @@ -1,35 +1,163 @@ + + + import { useState, useEffect } from 'react'; +import axios from 'axios'; +import { apiRoutes } from '@/data/apiRoutes'; // Adjust the import path +import { jwtToken } from '@/data/cookieNames'; // Adjust the import path +import { getCookie } from '@/lib/cookieFunctions'; // Adjust the import path + +type User = { + id: string; + username: string; + email: string; + profileName: string; + roleName: string; + roleDescription: string; + +}; -export default function useGetUserProfile(userId: string) { +type STSType = { + stsId: string ; + stsName: string; + stsWardNumber: string; + stsCapacity: string; + stsCurrentTotalWaste: string; + stsLatitude: string; + stsLongitude: string; +} - const [userData, setUserData] = useState({ - email: "", - role: "", - name: "", - assignedArea: "", +type LandfillType = { + landfillId: string ; + landFillName: string; + landFillCapacity: string; + landFillCurrentWaste: string; + landfillLatitude: string; + landFillLongitude: string; +} + +export default function useGetUserProfile() { + const [user, setUser] = useState({ + id: '', + username: '', + email: '', + profileName: '', + roleName: '', + roleDescription: '', + }); // Initialize with undefined + const [stsDetails, setStsDetails] = useState({ + stsId: '', + stsName: '', + stsWardNumber: '', + stsCapacity: '', + stsCurrentTotalWaste: '', + stsLatitude: '', + stsLongitude: '', }); - useEffect(() => { - fetchUser(); - }, []); - - async function fetchUser() { - - setUserData({ - email: userId + "@gmail.com", - role: "STS Manager", - name: "Mehrajul Islam", - assignedArea: "Gulshan-1, Dhaka", - }); - - if (userData) { - // Call the API + const [landfillDetails, setLandfillDetails] = useState({ + landfillId: '', + landFillName: '', + landFillCapacity: '', + landFillCurrentWaste: '', + landfillLatitude: '', + landFillLongitude: '', + }); + + async function getUserDetails() { + try { + const res = await axios.get(apiRoutes.profile.getProfile, { + headers: { Authorization: `Bearer ${getCookie(jwtToken)}` }, + }); + console.log(res.data); + if (res.data.roleName === "STS_MANAGER" ) { + const userDetails: User = { + id: res.data.id, + username: res.data.username, + email: res.data.email, + profileName: res.data.profileName, + roleName: res.data.roleName, + roleDescription: res.data.role.description, + + + }; + + if(res.data.stsId){ + const ResStsDetails: STSType = { + stsId: res.data.sts.id, + stsName: res.data.sts.name, + stsWardNumber: res.data.sts.wardNumber, + stsCapacity: res.data.sts.capacity, + stsCurrentTotalWaste: res.data.sts.currentTotalWaste, + stsLatitude: res.data.sts.latitude, + stsLongitude: res.data.sts.longitude, + } + setStsDetails(ResStsDetails); + } + + + + setUser(userDetails); - return userData; - } - - return null; + } else if(res.data.roleName === "LAND_MANAGER" ) { + + const userDetails: User = { + id: res.data.id, + username: res.data.username, + email: res.data.email, + profileName: res.data.profileName, + roleName: res.data.roleName, + roleDescription: res.data.role.description, + + + }; + + if(res.data.landfillId){ + const ResLandDetails: LandfillType = { + + landfillId: res.data.landfill.id, + landFillName: res.data.landfill.name, + landFillCapacity: res.data.landfill.capacity, + landFillCurrentWaste: res.data.landfill.currentTotalWaste, + landfillLatitude: res.data.landfill.latitude, + landFillLongitude: res.data.landfill.longitude, + }; + setLandfillDetails(ResLandDetails); + + } + + + + setUser(userDetails); + + + }else{ + const userDetails: User = { + id: res.data.id, + username: res.data.username, + email: res.data.email, + profileName: res.data.profileName, + roleName: res.data.roleName, + roleDescription: res.data.role.description, + + + }; + setUser(userDetails); + + } + + + + } catch (error: any) { + alert(error.message?.toString() || 'Error fetching user profile'); // Updated error message + } } - return {userData}; -} \ No newline at end of file + useEffect(() => { + console.log(user); + console.log(stsDetails); + console.log(landfillDetails) + }, [user, stsDetails, landfillDetails]); // Call getUserDetails when the component mounts + + return { user, stsDetails, landfillDetails, getUserDetails }; +} diff --git a/client/public/profileBack.png b/client/public/profileBack.png new file mode 100644 index 0000000..2889ec5 Binary files /dev/null and b/client/public/profileBack.png differ diff --git a/server/src/controllers/auth.ts b/server/src/controllers/auth.ts index c59a828..e17f06b 100644 --- a/server/src/controllers/auth.ts +++ b/server/src/controllers/auth.ts @@ -7,7 +7,7 @@ import { getToken, invalidateToken, verifyToken, -} from "../services/token"; +} from "../services/Token"; import CustomError from "../services/CustomError"; import { randomOTPGenerator, randomPasswordGenerator } from "../services/utils"; import { sendMail, sendOTPMail } from "../services/mailService"; diff --git a/server/src/controllers/profile.ts b/server/src/controllers/profile.ts index c0b62de..5ccc7de 100644 --- a/server/src/controllers/profile.ts +++ b/server/src/controllers/profile.ts @@ -2,7 +2,7 @@ import errorWrapper from "../middlewares/errorWrapper"; import { PrismaClient, User } from "@prisma/client"; import { Request, Response } from "express"; import CustomError from "../services/CustomError"; -import { getToken, verifyToken } from "../services/token"; +import { getToken, verifyToken } from "../services/Token"; const prisma = new PrismaClient(); @@ -15,6 +15,8 @@ const getUserById = errorWrapper( }, include: { role: true, + sts: true, + landfill: true }, }); diff --git a/server/src/middlewares/auth.ts b/server/src/middlewares/auth.ts index 86a2009..5eea6b4 100644 --- a/server/src/middlewares/auth.ts +++ b/server/src/middlewares/auth.ts @@ -1,7 +1,7 @@ import { Request, Response, NextFunction } from "express"; import errorWrapper from "./errorWrapper"; import CustomError from "../services/CustomError"; -import { getToken, verifyToken } from "../services/token"; +import { getToken, verifyToken } from "../services/Token"; const authChecker = errorWrapper( async (req: Request, res: Response, next: NextFunction) => { diff --git a/server/src/prisma/seed.ts b/server/src/prisma/seed.ts index d53ed54..3c51b28 100644 --- a/server/src/prisma/seed.ts +++ b/server/src/prisma/seed.ts @@ -375,7 +375,7 @@ const stsData: Prisma.STSCreateInput[] = [ }, { id: "sts6", - name: "Motijheel", + name: "Motijheel STS", wardNumber: "4", capacity: 1500, currentTotalWaste: 1400,