Skip to content

Commit 7a5fd80

Browse files
committed
- Added a Dashboard button on the header for authenticated users, to enable them to navigate back to their profile.
1 parent 0f5d497 commit 7a5fd80

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

components/Header.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ import { logout } from '../lib/authUtils';
1111
const Header: React.FC = () => {
1212
const router = useRouter();
1313
const [isLoggedIn, setIsLoggedIn] = useState(false);
14+
const [userType, setUserType] = useState<string | null>(null);
1415

1516
const checkAuth = async () => {
1617
try {
1718
// Retrieve session info from local storage
1819
const session = JSON.parse(localStorage.getItem('appwriteSession') || '{}');
19-
if (session && session.userId) {
20+
const type = localStorage.getItem('userType');
21+
if (session && session.userId && type) {
2022
setIsLoggedIn(true);
23+
setUserType(type);
2124
console.log('Logged in.');
2225
} else {
2326
setIsLoggedIn(false);
27+
setUserType(null);
2428
console.log('Not logged in.');
2529
}
2630
} catch (error) {
2731
console.error('Error checking login status', error);
2832
setIsLoggedIn(false);
33+
setUserType(null);
2934
}
3035
};
3136

@@ -46,12 +51,15 @@ const Header: React.FC = () => {
4651
try {
4752
await logout();
4853
setIsLoggedIn(false);
54+
setUserType(null);
4955
router.push('/');
5056
} catch (error) {
5157
console.error('Error logging out', error);
5258
}
5359
};
5460

61+
const dashboardLink = userType === 'Customer' ? '/customerProfile' : '/serviceProfile';
62+
5563
return (
5664
<header className="flex justify-between items-center bg-blue-500 p-4 w-full">
5765
<h1 className="text-xl font-bold text-white">ProBooker</h1>
@@ -73,6 +81,9 @@ const Header: React.FC = () => {
7381
</>
7482
) : (
7583
<>
84+
<Link href={dashboardLink} legacyBehavior>
85+
<a className="bg-white text-blue-500 py-2 px-4 rounded hover:bg-blue-100">Dashboard</a>
86+
</Link>
7687
<button
7788
className="bg-white text-blue-500 py-2 px-4 rounded hover:bg-blue-100"
7889
onClick={handleLogout}

pages/index.tsx

+7-28
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import Head from 'next/head';
33
import Link from 'next/link';
44
import { useEffect, useState } from 'react';
5-
import { useRouter } from 'next/router';
6-
import { account } from '../lib/appwrite.config';
75

86
export default function Home() {
9-
const router = useRouter();
7+
108
const [userType, setUserType] = useState<string | null>(null);
119

1210
useEffect(() => {
@@ -28,17 +26,6 @@ export default function Home() {
2826
fetchSession();
2927
}, []);
3028

31-
const handleLogout = async () => {
32-
try {
33-
await account.deleteSession('current');
34-
localStorage.removeItem('appwriteSession');
35-
localStorage.removeItem('userType');
36-
router.push('/customer-login');
37-
} catch (error) {
38-
console.error('Error logging out:', error);
39-
}
40-
};
41-
4229
return (
4330
<div className="min-h-[81vh] flex flex-col justify-center items-center homepage-background">
4431
<Head>
@@ -50,25 +37,17 @@ export default function Home() {
5037
<main className="relative z-10 flex flex-col md:flex-row justify-center items-center py-8 w-full flex-1">
5138
{userType ? (
5239
<div className="flex flex-col items-center space-y-4 p-8 bg-white bg-opacity-80 rounded-md shadow-lg md:w-3/2">
53-
<h1 className="text-4xl font-bold mb-2">Welcome, {userType}</h1>
54-
{userType === 'Customer' && (
40+
{userType === 'Customer' ? (
5541
<>
56-
<p>Customer-specific content here.</p>
57-
{/* Add other customer-specific components or content */}
42+
<h1 className="text-4xl font-bold mb-2">Looking for inspirations?!</h1>
43+
<p className="text-lg">Check out our latest services and offers tailored just for you.</p>
5844
</>
59-
)}
60-
{userType === 'Provider' && (
45+
) : (
6146
<>
62-
<p>Provider-specific content here.</p>
63-
{/* Add other provider-specific components or content */}
47+
<h1 className="text-4xl font-bold mb-2">Hey there, Pro!</h1>
48+
<p className="text-lg">Wanna check out some tips and resources to help grow your business?</p>
6449
</>
6550
)}
66-
<button
67-
onClick={handleLogout}
68-
className="mt-4 bg-red-500 text-white py-2 px-4 rounded"
69-
>
70-
Logout
71-
</button>
7251
</div>
7352
) : (
7453
<div className="flex flex-col items-center space-y-4 p-8 bg-white bg-opacity-80 rounded-md shadow-lg md:w-3/2">

0 commit comments

Comments
 (0)