1
- const CustomerAccountDetails = ( ) => {
2
- return (
3
- < div >
4
- < h2 className = "text-2xl font-bold mb-4" > Account Details</ h2 >
5
- < p > This is a placeholder for the customer account details section.</ p >
6
- </ div >
7
- ) ;
8
- } ;
1
+ import { useEffect , useState } from 'react' ;
2
+ import { databases , DATABASE_ID , CONSUMER_COLLECTION_ID } from '../lib/appwrite.config' ;
3
+ import * as sdk from 'node-appwrite' ;
4
+
5
+ // const CustomerAccountDetails = () => {
6
+ // return (
7
+ // <div>
8
+ // <h2 className="text-2xl font-bold mb-4">Account Details</h2>
9
+ // <p>This is a placeholder for the customer account details section.</p>
10
+ // </div>
11
+ // );
12
+ // };
9
13
10
- export default CustomerAccountDetails ;
14
+
15
+
16
+
17
+
18
+ const CustomerAccountDetails : React . FC = ( ) => {
19
+ const [ profile , setProfile ] = useState < any > ( null ) ;
20
+ const [ message , setMessage ] = useState ( '' ) ;
21
+
22
+ useEffect ( ( ) => {
23
+ const fetchProfile = async ( ) => {
24
+ try {
25
+ // Retrieve the session information from local storage
26
+ const session = JSON . parse ( localStorage . getItem ( 'appwriteSession' ) || '{}' ) ;
27
+
28
+ if ( ! session || ! session . userId ) {
29
+ setMessage ( 'No active session found. Please log in.' ) ;
30
+ return ;
31
+ }
32
+
33
+ // Fetch user profile from the collection
34
+ const response = await databases . listDocuments (
35
+ process . env . DATABASE_ID ! ,
36
+ process . env . CONSUMER_COLLECTION_ID ! ,
37
+ [
38
+ sdk . Query . equal ( 'userId' , session . userId )
39
+ ]
40
+ ) ;
41
+
42
+ if ( response . documents . length > 0 ) {
43
+ setProfile ( response . documents [ 0 ] ) ;
44
+ } else {
45
+ setMessage ( 'Profile not found.' ) ;
46
+ }
47
+ } catch ( error ) {
48
+ console . error ( 'Error fetching profile:' , error ) ;
49
+ setMessage ( 'Error fetching profile.' ) ;
50
+ }
51
+ } ;
52
+
53
+ fetchProfile ( ) ;
54
+ } , [ ] ) ;
55
+
56
+ return (
57
+ < div >
58
+ < h2 className = "text-2xl font-bold mb-4" > Account Details</ h2 >
59
+ { message && < p > { message } </ p > }
60
+ { profile ? (
61
+ < div >
62
+ < div >
63
+ < h2 > { profile . name } </ h2 >
64
+ < p > Email: { profile . email } </ p >
65
+ < p > Phone: { profile . phone } </ p >
66
+ < p > Address: { profile . address } </ p >
67
+ < p > City: { profile . city } </ p >
68
+ < p > State: { profile . state } </ p >
69
+ < p > Zipcode: { profile . zipcode } </ p >
70
+ < p > Create On: { profile . createon } </ p >
71
+ < p > User Type: { profile . userType } </ p >
72
+ < p > Profile Image: < img src = { profile . profileImg } alt = "Profile" /> </ p >
73
+ < p > Bookings: { profile . bookings . join ( ', ' ) } </ p >
74
+ < p > User ID: { profile . userId } </ p >
75
+ { /* Add other profile fields as needed */ }
76
+ </ div >
77
+ </ div >
78
+ ) : (
79
+ < p > Loading profile...</ p >
80
+ ) }
81
+ </ div >
82
+ ) ;
83
+ } ;
84
+ export default CustomerAccountDetails ;
85
+
11
86
0 commit comments