diff --git a/public/loadingSpinner.svg b/public/loadingSpinner.svg new file mode 100644 index 00000000..a3b0f76f --- /dev/null +++ b/public/loadingSpinner.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/app/(routes)/recruiter/profile/page.tsx b/src/app/(routes)/recruiter/profile/page.tsx new file mode 100644 index 00000000..8dda9872 --- /dev/null +++ b/src/app/(routes)/recruiter/profile/page.tsx @@ -0,0 +1,31 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import RecruiterProfile from "@/components/Recruiters/profile"; +import { fetchProfile } from "@/helpers/recruiter/api"; +import Cookies from "js-cookie"; +import loadingImg from "@/../public/loadingSpinner.svg"; +import { ProfileFC } from "@/helpers/recruiter/api"; + +const Profile = ({ params }: { params: { RecruiterId: string } }) => { + const [data, setData] = useState(); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const profileData = async () => { + const jsonData = await fetchProfile(Cookies.get("accessToken")); + setData(jsonData); + setLoading(false); + }; + profileData(); + }, []); + + return ( + + {loading && } + {data && } + + ); +}; + +export default Profile; diff --git a/src/components/Faculty/Profile.tsx b/src/components/Faculty/Profile.tsx index 5d8d076c..66b5e567 100644 --- a/src/components/Faculty/Profile.tsx +++ b/src/components/Faculty/Profile.tsx @@ -28,8 +28,12 @@ const EditForm = (params: { profile: ProfileFC }) => { contact: contact, }, }; - patchProfile(Cookies.get("accessToken"), data); - window.location.reload(); + + const triggerUpdate = async () => { + await patchProfile(Cookies.get("accessToken"), data); + window.location.reload(); + }; + triggerUpdate(); }; return ( diff --git a/src/components/NavButtonGroup.tsx b/src/components/NavButtonGroup.tsx index 7566d180..ff73e092 100644 --- a/src/components/NavButtonGroup.tsx +++ b/src/components/NavButtonGroup.tsx @@ -8,6 +8,7 @@ import Link, { LinkProps } from "next/link"; import { usePathname } from "next/navigation"; import { ToggleContext } from "@/contextProviders/ToggleProvider"; import { motion } from "framer-motion"; +import Cookies from "js-cookie"; const NavLink = ({ href }: LinkProps) => { const path = usePathname(); @@ -88,49 +89,65 @@ const NavLink = ({ href }: LinkProps) => { ); }; -const NavButtonGroup = () => { +const LogoutButton = () => { + const context = useContext(ToggleContext); + + const logOut = () => { + Cookies.remove("user"); + window.location.reload(); + }; + + return ( + + + + + + + + + + + Logout + + + + ); +}; + +const NavButtonGroup = (params: { loggedIn: boolean }) => { const context = useContext(ToggleContext); return ( - - - - - - - - - - - - Logout - - - + {!params.loggedIn && } + {params.loggedIn && } ); }; -export default NavButtonGroup; \ No newline at end of file +export default NavButtonGroup; diff --git a/src/components/Recruiters/profile.tsx b/src/components/Recruiters/profile.tsx new file mode 100644 index 00000000..5a8960b1 --- /dev/null +++ b/src/components/Recruiters/profile.tsx @@ -0,0 +1,166 @@ +import React, { useState } from "react"; +import profileImg from "@/../public/profile-icon.svg"; +import { ProfileFC, updateProfileFC } from "@/helpers/recruiter/api"; +import { Button } from "../ui/button"; +import { + Dialog, + DialogClose, + DialogTrigger, + DialogTitle, + DialogContent, +} from "../ui/dialog"; +import { patchProfile } from "@/helpers/recruiter/api"; +import Cookies from "js-cookie"; + +const EditForm = (params: { profile: ProfileFC }) => { + const { profile } = params; + const [email, updateEmail] = useState( + profile.user.email ? profile.user.email : "" + ); + const [contact, updateContact] = useState( + profile.user.contact ? profile.user.contact : "" + ); + const [name, updateName] = useState( + profile.user.name ? profile.user.name : "" + ); + const [designation, setDesignation] = useState( + profile.designation ? profile.designation : "" + ); + const [landline, setlandline] = useState( + profile.landline ? profile.landline : "" + ); + + const updateProfile = () => { + const data: updateProfileFC = { + designation: designation, + landline: landline, + user: { + name: name, + email: email, + contact: contact, + }, + }; + const triggerUpdate = async () => { + const res = await patchProfile(Cookies.get("accessToken"), data); + window.location.reload(); + }; + triggerUpdate(); + }; + + return ( + + + + Name: + { + updateName(e.target.value); + }} + /> + + + Designation: + { + setDesignation(e.target.value); + }} + /> + + + Landline: + { + setlandline(e.target.value); + }} + /> + + + Email: + { + updateEmail(e.target.value); + }} + /> + + + Contact: + { + updateContact(e.target.value); + }} + /> + + + + { + updateProfile(); + }} + > + Update + + + + + ); +}; + +const RecruiterProfile = (params: { profile: ProfileFC }) => { + return ( + + + + + + + Edit Details + + + + + + + + + + Name: + {params.profile.user.name} + + + Designation: + {params.profile.designation} + + + Landline: + {params.profile.landline} + + + Email: + {params.profile.user.email} + + + Contact: + {params.profile.user.contact} + + + + + ); +}; + +export default RecruiterProfile; diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 5a777893..6eaf94fb 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -10,7 +10,6 @@ import AdminDashboard from "./SideBar/Roles/admin"; import StudentDashboard from "./SideBar/Roles/student"; import RecruiterDashboard from "./SideBar/Roles/recruiter"; - interface Framework { value: string; label: string; @@ -31,21 +30,24 @@ interface Props { } const Sidebar = () => { - const isSmallScreen = useMediaQuery({ query: "(max-width: 768px)" }); const context = useContext(ToggleContext); const [isAdmin, setIsAdmin] = useState(false); const [isRecruiter, setIsRecruiter] = useState(false); const [isStudent, setIsStudent] = useState(false); + const [isLoggedIn, setLoggedIn] = useState(false); -useEffect(()=>{ + useEffect(() => { const userString = Cookies.get("user"); const user = userString ? JSON.parse(userString) : null; - setIsAdmin(user?.role === "ADMIN") - setIsRecruiter(user?.role === "RECRUITER") - setIsStudent(user?.role === "STUDENT") - }, []) + if (user) { + setLoggedIn(true); + } + setIsAdmin(user?.role === "ADMIN"); + setIsRecruiter(user?.role === "RECRUITER"); + setIsStudent(user?.role === "STUDENT"); + }, []); return ( { {/* */} - + - {isAdmin && ( - - )} - {isStudent && ( - - )} - {isRecruiter&& ( - - )} + {isAdmin && } + {isStudent && } + {isRecruiter && } ); }; -export default Sidebar; \ No newline at end of file +export default Sidebar; diff --git a/src/components/loginForms/loginForm.tsx b/src/components/loginForms/loginForm.tsx index 49f4fe31..aa61b814 100644 --- a/src/components/loginForms/loginForm.tsx +++ b/src/components/loginForms/loginForm.tsx @@ -97,8 +97,10 @@ const LoginForm = () => { > Request Access - - + + + + diff --git a/src/helpers/faculty/api.ts b/src/helpers/faculty/api.ts index 1961653b..d1e2eaf2 100644 --- a/src/helpers/faculty/api.ts +++ b/src/helpers/faculty/api.ts @@ -107,7 +107,5 @@ export const patchProfile = async ( }, body: JSON.stringify(changes), }); - console.log(JSON.stringify(changes)); - console.log(res.json()); return res.ok; }; diff --git a/src/helpers/recruiter/api.ts b/src/helpers/recruiter/api.ts new file mode 100644 index 00000000..c40ce49b --- /dev/null +++ b/src/helpers/recruiter/api.ts @@ -0,0 +1,81 @@ +const redirect = () => {}; + +const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + +const url = (NextUrl: string) => { + return `${baseUrl}/api/v1${NextUrl}`; +}; + +export interface ProfileFC { + id: string; + designation: string; + landline: string; + user: { + id: string; + email: string; + name: string; + contact: string; + }; +} + +export const fetchProfile = async (accessToken: string | undefined) => { + if (!accessToken || accessToken === undefined) { + redirect(); + return; + } + const res = await fetch(url(`/recruiter-view/recruiter`), { + cache: "no-store", + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + const json: ProfileFC = await res.json(); + return json; +}; + +export interface updateProfileFC { + designation?: string; + landline?: string; + company?: { + name: string; + website: string; + domains: [string]; + category: string; + address: { + line1: string; + line2: string; + city: string; + state: string; + country: string; + }; + size: number; + yearOfEstablishment: string; + annualTurnover: string; + socialMediaLink: string; + }; + user?: { + name: string; + email: string; + contact: string; + }; +} + +export const patchProfile = async ( + accessToken: string | undefined, + changes: updateProfileFC +) => { + if (!accessToken || accessToken === undefined) { + redirect(); + return; + } + const res = await fetch(url(`/recruiter-view/recruiter`), { + method: "PATCH", + headers: { + "Content-type": "application/json", + Authorization: `Bearer ${accessToken}`, + }, + body: JSON.stringify(changes), + }); + return res.ok; +};