diff --git a/client/app/profile/[userId]/page.tsx b/client/app/profile/[userId]/page.tsx index ccd7165..82928e3 100644 --- a/client/app/profile/[userId]/page.tsx +++ b/client/app/profile/[userId]/page.tsx @@ -8,6 +8,7 @@ import { useParams } from "next/navigation"; import { useRouter } from "next/navigation"; import { EditIcon, Factory, CircleUser } from "lucide-react"; import {useEffect, useState} from "react"; +import { ProfileEditModal } from "@/components/modals/ProfileEditModal"; @@ -50,16 +51,12 @@ export default function ProfilePage() {

ID:

Email: {user.email}

Role: {user.roleName}

-

Name: {user.profileName}

+

Profile Name: {user.profileName}

+

Username: {user.username}

Role Description: {user.roleDescription}

- + + @@ -90,7 +87,11 @@ export default function ProfilePage() { } - {user?.roleName !== 'STS_MANAGER' && user?.roleName !== 'LAND_MANAGER' && ( + {user?.roleName === 'SYSTEM_ADMIN' &&
+
Admin
+
You are admin
+
} + {user?.roleName !== 'STS_MANAGER' && user?.roleName !== 'LAND_MANAGER' && user?.roleName !== 'SYSTEM_ADMIN' && (
Oops! Your role has not assigned yet
)} diff --git a/client/components/modals/ProfileEditModal.tsx b/client/components/modals/ProfileEditModal.tsx new file mode 100644 index 0000000..f98e2e4 --- /dev/null +++ b/client/components/modals/ProfileEditModal.tsx @@ -0,0 +1,158 @@ +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, + DialogClose +} from "@/components/ui/dialog"; + +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import React, { use, useEffect, useState } from "react"; +import { Send, Trash,EditIcon } from "lucide-react"; +import deleteUser from "@/hooks/user_data/deleteUser"; +import { + Select, + SelectTrigger, + SelectValue, + SelectContent, + SelectGroup, + SelectLabel, + SelectItem, +} from "../ui/select"; +import editUser from "@/hooks/user_data/editUser"; +import gettAllRoles from "@/hooks/user_data/useGetAllRole"; +import { number } from "prop-types"; +import { admin, landfillManager, stsManager, unassigned } from "@/data/roles"; +import editSTS from "@/hooks/entityCreation/editSTS"; +import getUserByRole from "@/hooks/user_data/getUserByRole"; +import VehicleRelaseRoute from "../maps/VehicleReleaseRoute"; +import useVehicleReleaseFromSTS from "@/hooks/StsDashboard/useVehicleReleaseFromSTS"; +import useUpcomingVehicle from "@/hooks/landFillDashboard/useUpcomingVehiclesList"; +import useTripComplete from "@/hooks/landFillDashboard/useTripComplete"; +import { profile } from "console"; +import useEditProfileInfo from "@/hooks/user_data/useEditProfileInfo"; +import useGetUserProfile from "@/hooks/user_data/useGetUserProfile"; + + +type User = { + id: string; + username: string; + email: string; + profileName: string; + roleName: string; + roleDescription: string; + +}; + + +export const ProfileEditModal = ({ profileInfo }: { profileInfo: User }) => { + const [profileData, setProfileData] = useState(profileInfo); + + const { user, stsDetails, landfillDetails, getUserDetails} = useGetUserProfile(); + + + const [username , setUsername] = useState(user.username); + const [profilename , setProfilename] = useState(user.profileName); + + const { EditProfileInfo } = useEditProfileInfo(); + + + + + const handleSaveChanges = async () => { + try { + + + const postEntry = await EditProfileInfo({ + username : username, + profileName: profilename + }); + + } catch (error) { + console.error("Error:", error); + } + + + }; + useEffect(() => { + getUserDetails(); + }, []); + + + return ( + + + + + + + + Edit Profile + + +
+

+ Role Name: + {user.roleName} +

+

+ Email: + {user.email} +

+

+ Username: + {user.username} +

+

+ Profile Name: + {user.profileName} +

+ + + +
+
+
+
+
+ + setUsername(e.target.value)} + /> +
+ +
+ + setProfilename(e.target.value)} + /> +
+
+ + + + + +
+
+ ); +}; diff --git a/client/data/apiRoutes.ts b/client/data/apiRoutes.ts index db9adc1..f5aa185 100644 --- a/client/data/apiRoutes.ts +++ b/client/data/apiRoutes.ts @@ -51,5 +51,6 @@ export const apiRoutes = { }, profile: { getProfile: `${baseUrl}/profile`, + edit: `${baseUrl}/profile`, } } \ No newline at end of file diff --git a/client/hooks/user_data/useEditProfileInfo.tsx b/client/hooks/user_data/useEditProfileInfo.tsx new file mode 100644 index 0000000..df963f4 --- /dev/null +++ b/client/hooks/user_data/useEditProfileInfo.tsx @@ -0,0 +1,39 @@ +import { useState } from 'react'; +import { setCookie, getCookie } from '@/lib/cookieFunctions'; +import axios from 'axios'; +import { jwtToken, stsId } from '@/data/cookieNames'; // Ensure these variables are properly defined +import { apiRoutes } from '@/data/apiRoutes'; + +export default function useEditProfileInfo() { + async function EditProfileInfo(data: { + username: string; + profileName: string; + }) { + + + try { + const editedProfile = { + username: data.username, + profileName: data.profileName, + }; + + + const res = await axios.put( + apiRoutes.profile.edit, + editedProfile, + { + headers: { Authorization: `Bearer ${getCookie(jwtToken)}` }, + } + ); + + + + return true; + } catch (error: any) { + alert(error.message?.toString() || 'Error Editing'); + return false; + } + } + + return { EditProfileInfo }; +} diff --git a/client/hooks/user_data/useGetUserProfile.tsx b/client/hooks/user_data/useGetUserProfile.tsx index ccaa720..3064a76 100644 --- a/client/hooks/user_data/useGetUserProfile.tsx +++ b/client/hooks/user_data/useGetUserProfile.tsx @@ -68,6 +68,7 @@ export default function useGetUserProfile() { try { const res = await axios.get(apiRoutes.profile.getProfile, { headers: { Authorization: `Bearer ${getCookie(jwtToken)}` }, + }); console.log(res.data); if (res.data.roleName === "STS_MANAGER" ) { @@ -125,12 +126,24 @@ export default function useGetUserProfile() { setLandfillDetails(ResLandDetails); } + setUser(userDetails); + + }else if(res.data.roleName === "SYSTEM_ADMIN" ) { + + 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); - }else{ const userDetails: User = { id: res.data.id, @@ -153,11 +166,11 @@ export default function useGetUserProfile() { } } - useEffect(() => { - console.log(user); - console.log(stsDetails); - console.log(landfillDetails) - }, [user, stsDetails, landfillDetails]); // Call getUserDetails when the component mounts + // useEffect(() => { + // console.log(user); + // console.log(stsDetails); + // console.log(landfillDetails) + // }, [user, stsDetails, landfillDetails]); // Call getUserDetails when the component mounts return { user, stsDetails, landfillDetails, getUserDetails }; }