-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from NashTech-Labs/feature/userDetail
added login, register, dropdown
- Loading branch information
Showing
15 changed files
with
819 additions
and
251 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Link, useNavigate } from "react-router-dom"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export const DropdownLoggedIn = ({ setDropdown }) => { | ||
const naviagte = useNavigate(); | ||
const [userEmail, setUserEmail] = useState(""); | ||
|
||
useEffect(() => { | ||
// Fetch user data from db.json | ||
const fetchUserData = async () => { | ||
try { | ||
const response = await fetch("http://localhost:8000/users"); | ||
const userData = await response.json(); | ||
|
||
// Assuming sessionStorage has been set after login | ||
const userId = sessionStorage.getItem("userId"); | ||
|
||
// Find the user with the matching id | ||
const user = userData.find((user) => user.id === Number(userId)); | ||
|
||
// Update the userEmail state with the user's email | ||
setUserEmail(user.email); | ||
} catch (error) { | ||
console.error("Error fetching user data:", error); | ||
} | ||
}; | ||
|
||
fetchUserData(); | ||
}, []); | ||
|
||
function handleLogout() { | ||
sessionStorage.removeItem("userName"); | ||
sessionStorage.removeItem("userId"); | ||
setDropdown(false); | ||
naviagte("/"); | ||
} | ||
return ( | ||
<div | ||
id="dropdownAvatar" | ||
className="select-none absolute top-10 right-0 z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 dark:divide-gray-600" | ||
> | ||
<div className="py-3 px-4 text-sm text-gray-900 dark:text-white"> | ||
<div className="font-medium truncate">{userEmail}</div> | ||
</div> | ||
<ul | ||
className="py-1 text-sm text-gray-700 dark:text-gray-200" | ||
aria-labelledby="dropdownUserAvatarButton" | ||
> | ||
<li> | ||
<Link | ||
onClick={() => setDropdown(false)} | ||
to="/products" | ||
className="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white" | ||
> | ||
All Cars | ||
</Link> | ||
</li> | ||
<li> | ||
<Link | ||
onClick={() => setDropdown(false)} | ||
to="/dashboard" | ||
className="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white" | ||
> | ||
Dashboard | ||
</Link> | ||
</li> | ||
</ul> | ||
<div className="py-1"> | ||
<span | ||
onClick={handleLogout} | ||
className="cursor-pointer block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white" | ||
> | ||
Log out | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Link } from "react-router-dom"; | ||
|
||
export const DropdownLoggedOut = ({setDropdown}) => { | ||
return ( | ||
<div id="dropdownAvatar" className="select-none absolute top-10 right-0 z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 dark:divide-gray-600"> | ||
<ul className="py-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownUserAvatarButton"> | ||
<li> | ||
<Link onClick={() => setDropdown(false)} to="/products" className="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">All Cars</Link> | ||
</li> | ||
<li> | ||
<Link onClick={() => setDropdown(false)} to="/login" className="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Login</Link> | ||
</li> | ||
<li> | ||
<Link onClick={() => setDropdown(false)} to="/register" className="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Register</Link> | ||
</li> | ||
</ul> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export { Header } from "./Layout/Header" | ||
export { Footer } from "./Layout/Footer" | ||
export { ProductCard } from "./Elements/ProductCard" | ||
export { Rating } from "./Elements/Rating"; | ||
export { DropdownLoggedIn } from "./Elements/DropdownLoggedIn"; | ||
export {DropdownLoggedOut } from "./Elements/DropdownLoggedOut"; | ||
export { Rating } from "./Elements/Rating"; |
Oops, something went wrong.