Skip to content

Commit

Permalink
🍁 admin profile made dynamic using localstorage (#865)
Browse files Browse the repository at this point in the history
* admin profile made dynamic successfully

* admin functionality made dynamic

---------

Co-authored-by: Mandar007007 <[email protected]>
  • Loading branch information
Mandar007007 and Mandar007007 authored May 13, 2024
1 parent ba0684a commit 1e6fd02
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/app/routes/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = async (req, res, next) => {
name: `${userRecord.firstName} ${userRecord.lastName}`,
email: userRecord.email,
isSuperAdmin: userRecord.isSuperAdmin,
phone: userRecord.contact,
};
const JWT = generateJWT(JWTPayload);
const response = { ...JWTPayload, token: JWT };
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/Admin/Admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Admin = (props) => {
const toggleNav = () => setIsMenuOpen(!isMenuOpen);
const closeMobileMenu = () => setIsMenuOpen(false);
const dispatch = useDispatch();
const firstName = localStorage.getItem("firstName");

useEffect(() => {
const token = localStorage.getItem("token");
Expand All @@ -55,7 +56,7 @@ export const Admin = (props) => {
className={style["img-admin"]}
alt="admin_img"
/>
<h1 className={style["h1"]}>Welcome Admin!</h1>
<h1 className={style["h1"]}>Welcome {firstName}!</h1>
</div>
<ul
className={
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/pages/Admin/Components/Profile/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import EditIcon from "@material-ui/icons/Edit";
import CloseIcon from "@material-ui/icons/Close";
import style from "./profile.module.scss";

export function Profile() {
const [name, setName] = useState("Super Admin Name");
const [email, setEmail] = useState("[email protected]");
const [phone, setPhone] = useState("+91-1234567891");
const [phone, setPhone] = useState("+91-123456789");
const [edit, setEdit] = useState(false);

useEffect(() => {
setName(localStorage.getItem("firstName"));
setEmail(localStorage.getItem("email"));
setPhone(localStorage.getItem("phone"));
},[setName,setEmail,setPhone])

return (
<div className={style["profile-container"]}>
<h1>My Profile</h1>
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,22 @@ export function Login(props) {
.json()
.then((res) => {
if (response.status === 200) {
const firstName = res.name.split(' ')[0];
localStorage.setItem("token", res.token);
localStorage.setItem("isSuperAdmin", res.isSuperAdmin);
localStorage.setItem("firstName", firstName);
localStorage.setItem("email", res.email);
localStorage.setItem("phone", res.phone);
window.location = "/dashboard?loggedin";
} else if (response.status === 400) {
setOpenError2Toast(true);
} else {
setOpenError3Toast(true);
}
})
.catch((err) => setOpenError3Toast(true))
.catch((err) => {
console.error(err);
setOpenError3Toast(true)})
)
.catch((err) => {
setOpenError1Toast(true);
Expand Down

0 comments on commit 1e6fd02

Please sign in to comment.