Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes:#495 - Jashwanth/navlogin #522

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions client/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const Navbar = () => {
const handleToggleMode = () => {
setDark(dark === 'light' ? 'dark' : 'light');
};
const handleLogoutlocal = () => {
localStorage.removeItem('basicDetails');
window.location.reload();
};

// Scroll event listener
const controlNavbar = useCallback(() => {
Expand Down Expand Up @@ -185,6 +189,15 @@ const Navbar = () => {
</NavLink>
)}


{localStorage.getItem('basicDetails') ? (
<button
className="bg-white px-5 py-1 rounded-lg text-black font-bold hover:brightness-75"
onClick={handleLogout}
>
Log Out
</button>

{isAuthenticated ? (
<>
{/* Profile Avatar with Name */}
Expand Down Expand Up @@ -213,6 +226,7 @@ const Navbar = () => {
Log Out
</button>
</>

) : (
<div className="flex gap-2 flex-col xs:flex-row w-full xs:w-auto pr-4 xs:pr-0">
<NavLink
Expand Down Expand Up @@ -261,6 +275,22 @@ const Navbar = () => {
<p className="font-bold text-lg hover:brightness-50">About</p>
</NavLink>


<NavLink to="/labtest" className="flex items-baseline gap-2">
<MdOutlineLocalHospital className="mr-0.5 relative top-[4px] text-xl" />{' '}
<p className="font-bold text-lg hover:brightness-50">Lab Test</p>
</NavLink>

{/* Add the new Hospitals Around Link for Desktop */}
<NavLink to="/hospitals-around" className="flex items-baseline gap-2">
<FaHospitalAlt className="mr-0.5 relative top-[3px] text-xl" />
<p className="font-bold text-lg hover:brightness-50">
Hospitals Around
</p>
</NavLink>

{localStorage.getItem('basicDetails') ? (

{/* Conditional Links */}
{!isAuthenticated && (
<NavLink to="/hospitals" className="flex items-baseline gap-2">
Expand All @@ -271,6 +301,7 @@ const Navbar = () => {

{/* Show Lab Tests and Hospitals Around for regular user */}
{isAuthenticated && user?.role === 'user' && (

<>
<NavLink to="/labtest" className="flex items-baseline gap-2">
<MdOutlineLocalHospital />
Expand All @@ -284,18 +315,38 @@ const Navbar = () => {
</p>
</NavLink>
</>

) : (
<NavLink to="/registerOPD" className="flex items-baseline gap-2">
<MdOutlineLocalHospital className="mr-0.5 relative top-[4px] text-xl" />

)}

{/* Show only Hospitals Around for hospital */}
{isAuthenticated && user?.role === 'hospital' && (
<NavLink to="/hospitals-around" className="flex items-baseline gap-2">
<FaHospitalAlt />

<p className="font-bold text-lg hover:brightness-50">
Hospitals Around
</p>
</NavLink>
)}


<div className="flex gap-3">
{localStorage.getItem('basicDetails') ? (
<button
className={`${
dark === 'dark'
? 'bg-gray-900 text-gray-100'
: 'bg-white text-black'
} flex gap-2 items-center px-5 py-1 rounded-lg font-bold hover:brightness-75 ml-32`}
onClick={handleLogoutlocal}
>
Log Out
</button>

{isAuthenticated ? (
<>
{/* Profile Avatar with Name */}
Expand Down Expand Up @@ -328,6 +379,7 @@ const Navbar = () => {
Log Out
</button>
</>

) : (
<div className="flex gap-5">
<NavLink
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ReviewDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function ReviewDetails() {

if (response.ok) {
notify('Registration successful', 'success');
navigate('/login');
} else {
notify(data.message || 'An error occurred. Please try again.', 'warn');
}
Expand All @@ -98,6 +97,7 @@ function ReviewDetails() {
} finally {
setIsLoading(false);
}
navigate('/');
};

return (
Expand Down
140 changes: 80 additions & 60 deletions client/src/components/StepOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function StepOne() {

return newErrors;
};

const handleContinue = (e) => {
e.preventDefault();

Expand All @@ -91,34 +90,41 @@ function StepOne() {
}));
return;
}
nextStep();

// Store basicDetails in localStorage
localStorage.setItem('basicDetails', JSON.stringify(basicDetails));

nextStep(); // Move to the next step
};

return (
<>
<form
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
>
<div className="form-section">
<label
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
>
User Type:
</label>
<select
name="type"
value={basicDetails.type}
onChange={handleChange}
className={`${dark === 'dark'
? 'bg-gray-800 text-yellow-400 border-yellow-400'
: 'bg-white text-gray-700 border-gray-300'
}`}
className={`${
dark === 'dark'
? 'bg-gray-800 text-yellow-400 border-yellow-400'
: 'bg-white text-gray-700 border-gray-300'
}`}
>
<option value="user">User</option>
<option value="hospital">Hospital</option>
Expand All @@ -128,10 +134,11 @@ function StepOne() {
<div className="form-section">
<label
htmlFor="name"
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
style={{ display: 'inline' }}
>
Name: <span style={{ color: 'red' }}>*</span>
Expand All @@ -144,10 +151,11 @@ function StepOne() {
onChange={handleChange}
placeholder="John Doe"
required
className={`${dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`${
dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
/>
{errors.frontend.name && (
<span className="error">{errors.frontend.name}</span>
Expand All @@ -157,10 +165,11 @@ function StepOne() {
<div className="form-section">
<label
htmlFor="phone"
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
style={{ display: 'inline' }}
>
Phone: <span style={{ color: 'red' }}>*</span>
Expand All @@ -173,10 +182,11 @@ function StepOne() {
value={basicDetails.phone}
onChange={handleChange}
required
className={`${dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`${
dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
/>
{errors.frontend.phone && (
<span className="error">{errors.frontend.phone}</span>
Expand All @@ -186,10 +196,11 @@ function StepOne() {
<div className="form-section">
<label
htmlFor="email"
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
style={{ display: 'inline' }}
>
Email: <span style={{ color: 'red' }}>*</span>
Expand All @@ -202,10 +213,11 @@ function StepOne() {
value={basicDetails.email}
onChange={handleChange}
required
className={`${dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`${
dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
/>
{errors.frontend.email && (
<span className="error">{errors.frontend.email}</span>
Expand All @@ -214,10 +226,11 @@ function StepOne() {

<div className="form-section">
<label
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
style={{ display: 'inline' }}
>
Password: <span style={{ color: 'red' }}>*</span>
Expand All @@ -230,10 +243,11 @@ function StepOne() {
value={basicDetails.password}
onChange={handleChange}
required
className={`${dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`${
dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
/>
<button
type="button"
Expand All @@ -250,10 +264,11 @@ function StepOne() {

<div className="form-section">
<label
className={`auth-form ${dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`auth-form ${
dark === 'dark'
? 'bg-gray-900 text-yellow-400'
: 'bg-white text-gray-700'
}`}
style={{ display: 'inline' }}
>
Confirm Password: <span style={{ color: 'red' }}>*</span>
Expand All @@ -266,10 +281,11 @@ function StepOne() {
value={basicDetails.confirmPassword}
onChange={handleChange}
required
className={`${dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
className={`${
dark === 'dark'
? 'bg-gray-800 text-yellow-400'
: 'bg-white text-gray-700'
}`}
/>
<button
type="button"
Expand All @@ -287,10 +303,11 @@ function StepOne() {
<div className="register-button">
<button
type="submit"
className={`auth-button ${dark === 'dark'
? 'bg-yellow-400 text-gray-900 hover:bg-yellow-500'
: 'bg-blue-600 text-white hover:bg-blue-700'
}`}
className={`auth-button ${
dark === 'dark'
? 'bg-yellow-400 text-gray-900 hover:bg-yellow-500'
: 'bg-blue-600 text-white hover:bg-blue-700'
}`}
onClick={handleContinue}
>
Continue
Expand All @@ -299,8 +316,11 @@ function StepOne() {

<Link
to="/login"
className={`toggle-auth-button text-center ${dark === 'dark' ? 'text-white' : 'text-black'
}`}

className={`toggle-auth-button text-center ${
dark === 'dark' ? 'text-yellow-400' : 'text-gray-700'
}`}

>
Already have an account? Login
</Link>
Expand Down