-
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 #31 from atlp-rwanda/password-reset
ft: This PR enable password reset feature for user
- Loading branch information
Showing
51 changed files
with
2,350 additions
and
32 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ dist | |
.env | ||
dist-ssr | ||
*.local | ||
yarn.lock | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
107 changes: 107 additions & 0 deletions
107
src/components/Dashboard/DashboardNavbar/DashboardNavbar.tsx
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,107 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { jwtDecode } from 'jwt-decode'; | ||
import notificationIcon from '/notification.svg'; | ||
import searchIcon from '/search.svg'; | ||
import { Link } from 'react-router-dom'; | ||
import { AlignJustify } from 'lucide-react'; | ||
|
||
interface DashboardNavBarProps { | ||
setOpenNav: (open: boolean) => void; | ||
} | ||
|
||
interface TokenPayload { | ||
email: string; | ||
name: string; | ||
userType: string; | ||
exp: number; | ||
firstName: string; | ||
} | ||
|
||
const DashboardNavbar: React.FC<DashboardNavBarProps> = ({ setOpenNav }) => { | ||
const [searchTerm, setSearchTerm] = useState(''); | ||
const [currentDateTime, setCurrentDateTime] = useState(''); | ||
const [userName, setUserName] = useState(''); | ||
const navigate = useNavigate(); | ||
|
||
const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchTerm(event.target.value); | ||
}; | ||
|
||
useEffect(() => { | ||
const updateDateTime = () => { | ||
const now = new Date(); | ||
const options: Intl.DateTimeFormatOptions = { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
hour12: true, | ||
timeZone: 'Etc/GMT-2', | ||
timeZoneName: 'short' | ||
}; | ||
const formattedDateTime = new Intl.DateTimeFormat('en-GB', options).format(now); | ||
setCurrentDateTime(formattedDateTime); | ||
}; | ||
|
||
updateDateTime(); | ||
const intervalId = setInterval(updateDateTime, 60000); | ||
|
||
return () => clearInterval(intervalId); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const tokenString = localStorage.getItem('userToken'); | ||
if (!tokenString) { | ||
navigate('/login'); | ||
return; | ||
} | ||
|
||
try { | ||
const decodedToken = jwtDecode<TokenPayload>(tokenString); | ||
//send name in token | ||
setUserName(decodedToken.firstName); | ||
} catch (error) { | ||
console.error('Failed to decode token:', error); | ||
navigate('/login'); | ||
} | ||
}, [navigate]); | ||
|
||
return ( | ||
<div | ||
className="flex justify-end gap-4 lg:gap-0 flex-col-reverse items-end lg:flex-row lg:justify-between lg:items-center p-8 border-b-[1px] border-[#7c7c7c] text-black relative" | ||
data-testid="navbar" | ||
> | ||
<Link to={'/vendor/dashboard'} className="lg:hidden text-4xl font-bold text-[#070f2b] absolute left-8 top-8"> | ||
Knight | ||
</Link> | ||
<div className="flex flex-col items-end lg:items-start"> | ||
<p className="font-bold text-xl">Welcome, {userName}</p> | ||
<p className="text-[#7c7c7c] text-sm">{currentDateTime}</p> | ||
</div> | ||
<div className="flex flex-col lg:flex-row gap-4"> | ||
<div className="flex gap-4 items-center"> | ||
<button className="px-4 lg:border-r-2 border-[#7c7c7c]"> | ||
<img src={notificationIcon} alt="Notification" /> | ||
</button> | ||
<button onClick={() => setOpenNav(true)} className="lg:hidden"> | ||
<AlignJustify /> | ||
</button> | ||
</div> | ||
<div className="hidden lg:flex px-4 py-2 rounded-lg border border-[#d1d1d1] gap-2"> | ||
<img src={searchIcon} alt="Search" /> | ||
<input | ||
type="text" | ||
className="bg-white w-[200px] outline-none" | ||
placeholder="Search..." | ||
value={searchTerm} | ||
onChange={handleSearchChange} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DashboardNavbar; |
Oops, something went wrong.