1
1
import { useEffect , useState } from 'react' ;
2
2
import { databases } from '../lib/appwrite.config' ;
3
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
- // };
13
-
14
-
15
-
16
-
4
+ import ChangePasswordForm from './UpdatePassword' ;
5
+ import UpdateProfileForm from './UpdateProfileForm' ;
17
6
18
7
const CustomerAccountDetails : React . FC = ( ) => {
19
- const [ profile , setProfile ] = useState < any > ( null ) ;
20
- const [ message , setMessage ] = useState ( '' ) ;
8
+ const [ profile , setProfile ] = useState < any > ( null ) ;
9
+ const [ message , setMessage ] = useState ( '' ) ;
10
+ const [ expandedSection , setExpandedSection ] = useState < string | null > ( null ) ;
11
+ const [ activeSetting , setActiveSetting ] = useState < string | null > ( null ) ;
21
12
22
13
useEffect ( ( ) => {
23
14
const fetchProfile = async ( ) => {
@@ -34,9 +25,7 @@ useEffect(() => {
34
25
const response = await databases . listDocuments (
35
26
process . env . DATABASE_ID ! ,
36
27
process . env . CONSUMER_COLLECTION_ID ! ,
37
- [
38
- sdk . Query . equal ( 'userId' , session . userId )
39
- ]
28
+ [ sdk . Query . equal ( 'userId' , session . userId ) ]
40
29
) ;
41
30
42
31
if ( response . documents . length > 0 ) {
@@ -53,31 +42,76 @@ useEffect(() => {
53
42
fetchProfile ( ) ;
54
43
} , [ ] ) ;
55
44
45
+ const toggleSection = ( section : string ) => {
46
+ setExpandedSection ( expandedSection === section ? null : section ) ;
47
+ setActiveSetting ( null ) ;
48
+ } ;
49
+
50
+ const handleSettingClick = ( setting : string ) => {
51
+ setActiveSetting ( setting ) ;
52
+ } ;
53
+
56
54
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 */ }
55
+ < div className = "bg-gray-100 rounded-lg p-6" >
56
+ < div className = "flex justify-between items-start mb-4 border-b border-gray-300 pb-4" >
57
+ < div className = "flex items-center" >
58
+ < div className = "w-40 h-40 flex items-center justify-center rounded-full" >
59
+ < img className = "w-32 h-32 rounded-full" src = { profile ?. profileImg } alt = { profile ?. name } />
60
+ </ div >
61
+ < div className = "mx-6" >
62
+ < h2 className = "font-bold text-lg" > { profile ?. name } </ h2 >
63
+ < p > { profile ?. city } , { profile ?. state } </ p >
64
+ < p > Stars (Rating): { profile ?. rating } </ p >
65
+ < p > Joined On: { profile ?. createdAt ?. substring ( 0 , 10 ) } </ p >
66
+ < p > User Type: { profile ?. userType } </ p >
67
+ </ div >
68
+ </ div >
69
+ < div className = "w-5/12 items-center justify-center mt-10" >
70
+ < h3 className = "" > < span className = "label mt-1" > Phone:</ span > { profile ?. phone } </ h3 >
71
+ < h3 className = "" > < span className = "label" > e-mail:</ span > { profile ?. email } </ h3 >
72
+ < h3 className = "" > < span className = "label" > Address:</ span > { profile ?. address } </ h3 >
76
73
</ div >
74
+ </ div >
75
+ < div className = "flex" >
76
+ < div className = "w-full p-4" >
77
+ < h3 className = "my-4 cursor-pointer" onClick = { ( ) => toggleSection ( 'accountSettings' ) } >
78
+ Account Settings
79
+ </ h3 >
80
+ { expandedSection === 'accountSettings' && (
81
+ < div className = "p-4 bg-white rounded shadow" >
82
+ < p className = "cursor-pointer my-2 font-bold" onClick = { ( ) => handleSettingClick ( 'changePassword' ) } > Change Password</ p >
83
+ { activeSetting === 'changePassword' && profile && (
84
+ < div className = "mt-4" >
85
+ < ChangePasswordForm userId = { profile . userId } />
86
+ </ div >
87
+ ) }
88
+ < p className = "cursor-pointer my-2 font-bold" onClick = { ( ) => handleSettingClick ( 'updateAccountInfo' ) } > Update Account Info</ p >
89
+ { activeSetting === 'updateAccountInfo' && profile && (
90
+ < div className = "mt-4" >
91
+ < UpdateProfileForm profile = { profile } />
92
+ </ div >
93
+ ) }
94
+ { console . log ( profile . $id ) }
95
+ </ div >
96
+ ) }
97
+ < h3 className = "my-4 cursor-pointer" onClick = { ( ) => toggleSection ( 'currentBookings' ) } >
98
+ Current Bookings
99
+ </ h3 >
100
+ { expandedSection === 'currentBookings' && (
101
+ < div className = "p-4 bg-white rounded shadow" >
102
+ < p > Current bookings content...</ p >
103
+ </ div >
104
+ ) }
105
+ < h3 className = "my-4 cursor-pointer" onClick = { ( ) => toggleSection ( 'myReviews' ) } >
106
+ My Reviews
107
+ </ h3 >
108
+ { expandedSection === 'myReviews' && (
109
+ < div className = "p-4 bg-white rounded shadow" >
110
+ < p > My reviews content...</ p >
111
+ </ div >
112
+ ) }
77
113
</ div >
78
- ) : (
79
- < p > Loading profile...</ p >
80
- ) }
114
+ </ div >
81
115
</ div >
82
116
) ;
83
117
} ;
0 commit comments