1
1
// pages/index.tsx
2
2
import Head from 'next/head' ;
3
3
import Link from 'next/link' ;
4
- import Header from '../components/Header' ;
4
+ import { useEffect , useState } from 'react' ;
5
+ import { useRouter } from 'next/router' ;
6
+ import { account } from '../lib/appwrite.config' ;
5
7
6
8
export default function Home ( ) {
9
+ const router = useRouter ( ) ;
10
+ const [ userType , setUserType ] = useState < string | null > ( null ) ;
11
+
12
+ useEffect ( ( ) => {
13
+ const fetchSession = async ( ) => {
14
+ try {
15
+ const session = JSON . parse ( localStorage . getItem ( 'appwriteSession' ) || '{}' ) ;
16
+ const type = localStorage . getItem ( 'userType' ) ;
17
+
18
+ if ( session && type ) {
19
+ setUserType ( type ) ;
20
+ } else {
21
+ setUserType ( null ) ;
22
+ }
23
+ } catch ( error ) {
24
+ console . error ( 'Error fetching session:' , error ) ;
25
+ }
26
+ } ;
27
+
28
+ fetchSession ( ) ;
29
+ } , [ ] ) ;
30
+
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
+
7
42
return (
8
43
< div className = "min-h-[81vh] flex flex-col justify-center items-center homepage-background" >
9
44
< Head >
@@ -13,20 +48,44 @@ export default function Home() {
13
48
</ Head >
14
49
15
50
< main className = "relative z-10 flex flex-col md:flex-row justify-center items-center py-8 w-full flex-1" >
16
- < 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" >
17
- < h1 className = "text-4xl font-bold mb-2" > ProBooker</ h1 >
18
- < h2 className = "text-2xl mb-6" > Connect with the pros, book with confidence</ h2 >
19
- < Link href = "/customer-start" legacyBehavior >
20
- < a className = "w-full bg-blue-500 text-white py-3 px-6 rounded-lg text-center hover:bg-blue-600" >
21
- Get Started as a Customer
22
- </ a >
23
- </ Link >
24
- < Link href = "/provider-start" legacyBehavior >
25
- < a className = "w-full bg-green-500 text-white py-3 px-6 rounded-lg text-center hover:bg-green-600" >
26
- Join as a Pro
27
- </ a >
28
- </ Link >
29
- </ div >
51
+ { userType ? (
52
+ < 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' && (
55
+ < >
56
+ < p > Customer-specific content here.</ p >
57
+ { /* Add other customer-specific components or content */ }
58
+ </ >
59
+ ) }
60
+ { userType === 'Provider' && (
61
+ < >
62
+ < p > Provider-specific content here.</ p >
63
+ { /* Add other provider-specific components or content */ }
64
+ </ >
65
+ ) }
66
+ < button
67
+ onClick = { handleLogout }
68
+ className = "mt-4 bg-red-500 text-white py-2 px-4 rounded"
69
+ >
70
+ Logout
71
+ </ button >
72
+ </ div >
73
+ ) : (
74
+ < 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" >
75
+ < h1 className = "text-4xl font-bold mb-2" > ProBooker</ h1 >
76
+ < h2 className = "text-2xl mb-6" > Connect with the pros, book with confidence</ h2 >
77
+ < Link href = "/customer-start" legacyBehavior >
78
+ < a className = "w-full bg-blue-500 text-white py-3 px-6 rounded-lg text-center hover:bg-blue-600" >
79
+ Get Started as a Customer
80
+ </ a >
81
+ </ Link >
82
+ < Link href = "/provider-start" legacyBehavior >
83
+ < a className = "w-full bg-green-500 text-white py-3 px-6 rounded-lg text-center hover:bg-green-600" >
84
+ Join as a Pro
85
+ </ a >
86
+ </ Link >
87
+ </ div >
88
+ ) }
30
89
</ main >
31
90
</ div >
32
91
) ;
0 commit comments