1
- import React from " react" ;
2
- import Form from " react-jsonschema-form" ;
3
- import API from " @aws-amplify/api" ;
4
- import Loading from " ./loading" ;
5
- import { Redirect } from " react-router" ;
1
+ import React from ' react' ;
2
+ import Form from ' react-jsonschema-form' ;
3
+ import API from ' @aws-amplify/api' ;
4
+ import Loading from ' ./loading' ;
5
+ import { Redirect } from ' react-router' ;
6
6
7
7
const schema = {
8
- title : " Tell us about yourself!" ,
9
- type : " object" ,
8
+ title : ' Tell us about yourself!' ,
9
+ type : ' object' ,
10
10
required : [ ] ,
11
11
properties : {
12
- profileDesc : { type : " string" , title : " Profile Description" } ,
13
- idea : { type : " string" , title : " Challenge ideas" } ,
12
+ profileDesc : { type : ' string' , title : ' Profile Description' } ,
13
+ idea : { type : ' string' , title : ' Challenge ideas' } ,
14
14
verticals : {
15
15
title : "Challenges I'm interested in" ,
16
- type : " array" ,
16
+ type : ' array' ,
17
17
uniqueItems : true ,
18
18
items : {
19
- type : " string" ,
19
+ type : ' string' ,
20
20
enum : [
21
- " Healthcare" ,
22
- " New Froniers" ,
23
- " Web 3.0 and Fintech" ,
24
- " Sustainability" ,
25
- " Education" ,
26
- " Privacy and Safety"
27
- ]
28
- }
21
+ ' Healthcare' ,
22
+ ' New Froniers' ,
23
+ ' Web 3.0 and Fintech' ,
24
+ ' Sustainability' ,
25
+ ' Education' ,
26
+ ' Privacy and Safety' ,
27
+ ] ,
28
+ } ,
29
29
} ,
30
- pronouns : { type : " string" , title : " Pronouns" } ,
30
+ pronouns : { type : ' string' , title : ' Pronouns' } ,
31
31
skills : {
32
- title : " My Skills" ,
33
- type : " array" ,
32
+ title : ' My Skills' ,
33
+ type : ' array' ,
34
34
uniqueItems : true ,
35
35
items : {
36
- type : " string" ,
36
+ type : ' string' ,
37
37
enum : [
38
- "AI" ,
39
- " Data Mining" ,
40
- " NLP" ,
41
- " Web Development" ,
42
- " IOS" ,
43
- " Android" ,
44
- " Pitching" ,
45
- " Marketing" ,
46
- " Design" ,
47
- " AR/VR" ,
48
- " Game Development" ,
49
- " Systems"
50
- ]
51
- }
38
+ 'AI' ,
39
+ ' Data Mining' ,
40
+ ' NLP' ,
41
+ ' Web Development' ,
42
+ ' IOS' ,
43
+ ' Android' ,
44
+ ' Pitching' ,
45
+ ' Marketing' ,
46
+ ' Design' ,
47
+ ' AR/VR' ,
48
+ ' Game Development' ,
49
+ ' Systems' ,
50
+ ] ,
51
+ } ,
52
52
} ,
53
53
userType : {
54
- title : "Profile Type" ,
55
- type : "string" ,
56
- default : "Hacker" ,
57
- enumNames : [
58
- "Hacker" ,
59
- "Mentor" ,
60
- ] ,
61
- "enum" : [
62
- "Hacker" ,
63
- "Mentor" ,
64
- ]
54
+ title : 'Profile Type' ,
55
+ type : 'string' ,
56
+ default : 'Hacker' ,
57
+ enumNames : [ 'Hacker' , 'Mentor' ] ,
58
+ enum : [ 'Hacker' , 'Mentor' ] ,
65
59
} ,
66
60
commitment : {
67
- title : " Commitment Level" ,
68
- type : " string" ,
61
+ title : ' Commitment Level' ,
62
+ type : ' string' ,
69
63
enumNames : [
70
- " High - Shooting for a prize, will spend majority of time hacking" ,
71
- " Medium - Will submit a substantial project, but with long breaks (e.g lots of rest, workshops)" ,
72
- "Low - Wants to submit something, but won't spend majority of time hacking"
64
+ ' High - Shooting for a prize, will spend majority of time hacking' ,
65
+ ' Medium - Will submit a substantial project, but with long breaks (e.g lots of rest, workshops)' ,
66
+ "Low - Wants to submit something, but won't spend majority of time hacking" ,
73
67
] ,
74
- "enum" : [
75
- "High" ,
76
- "Medium" ,
77
- "Low"
78
- ]
68
+ enum : [ 'High' , 'Medium' , 'Low' ] ,
79
69
} ,
80
70
timezoneOffset : {
81
- title : " Timezone" ,
82
- type : " string" ,
83
- default : getTimezoneOffset ( )
71
+ title : ' Timezone' ,
72
+ type : ' string' ,
73
+ default : getTimezoneOffset ( ) ,
84
74
} ,
85
- githubLink : { type : " string" , title : " GitHub Link" } ,
86
- linkedinLink : { type : " string" , title : " Linkedin Link" } ,
87
- devpostLink : { type : " string" , title : " Devpost Link" } ,
88
- portfolioLink : { type : " string" , title : " Portfolio Link" } ,
75
+ githubLink : { type : ' string' , title : ' GitHub Link' } ,
76
+ linkedinLink : { type : ' string' , title : ' Linkedin Link' } ,
77
+ devpostLink : { type : ' string' , title : ' Devpost Link' } ,
78
+ portfolioLink : { type : ' string' , title : ' Portfolio Link' } ,
89
79
showProfile : {
90
- type : " boolean" ,
91
- title : " Yes! Show my profile and allow other hackers to contact me." ,
92
- default : true
93
- }
94
- }
80
+ type : ' boolean' ,
81
+ title : ' Yes! Show my profile and allow other hackers to contact me.' ,
82
+ default : true ,
83
+ } ,
84
+ } ,
95
85
} ;
96
86
97
87
const uiSchema = {
98
88
profileDesc : {
99
- "ui:widget" : "textarea" ,
100
- "ui:placeholder" :
101
- "Tell other hackers about yourself!"
89
+ 'ui:widget' : 'textarea' ,
90
+ 'ui:placeholder' : 'Tell other hackers about yourself!' ,
102
91
} ,
103
92
idea : {
104
- " ui:widget" : " textarea" ,
105
- " ui:placeholder" :
106
- " Pitch an idea that interests you! This will be shared on the ideas page."
93
+ ' ui:widget' : ' textarea' ,
94
+ ' ui:placeholder' :
95
+ ' Pitch an idea that interests you! This will be shared on the ideas page.' ,
107
96
} ,
108
97
pronouns : {
109
- "ui:placeholder" :
110
- "Gender pronouns (optional)"
98
+ 'ui:placeholder' : 'Gender pronouns (optional)' ,
111
99
} ,
112
100
verticals : {
113
- " ui:widget" : " checkboxes"
101
+ ' ui:widget' : ' checkboxes' ,
114
102
} ,
115
103
skills : {
116
- " ui:widget" : " checkboxes"
104
+ ' ui:widget' : ' checkboxes' ,
117
105
} ,
118
106
timezoneOffset : {
119
- " ui:description" : " Enter your timezone in GMT e.g GMT +0230, GMT -1100"
107
+ ' ui:description' : ' Enter your timezone in GMT e.g GMT +0230, GMT -1100' ,
120
108
} ,
121
109
userType : {
122
- " ui:description" : " Are you a hacker vs mentor?" ,
110
+ ' ui:description' : ' Are you a hacker vs mentor?' ,
123
111
} ,
124
112
commitment : {
125
- " ui:description" : " What is your commitment level for TreeHacks 2023?"
113
+ ' ui:description' : ' What is your commitment level for TreeHacks 2023?' ,
126
114
} ,
127
115
githubLink : {
128
- "ui:description" : "Social Media Links:" ,
129
- "ui:placeholder" :
130
- "GitHub Profile"
116
+ 'ui:description' : 'Social Media Links:' ,
117
+ 'ui:placeholder' : 'GitHub Profile' ,
131
118
} ,
132
119
linkedinLink : {
133
- "ui:placeholder" :
134
- "Linkedin Profile"
120
+ 'ui:placeholder' : 'Linkedin Profile' ,
135
121
} ,
136
122
devpostLink : {
137
- "ui:placeholder" :
138
- "Devpost Profile"
123
+ 'ui:placeholder' : 'Devpost Profile' ,
139
124
} ,
140
125
portfolioLink : {
141
- "ui:placeholder" :
142
- "Portfolio Link"
126
+ 'ui:placeholder' : 'Portfolio Link' ,
143
127
} ,
144
128
} ;
145
129
146
- const log = type => console . log . bind ( console , type ) ;
130
+ const log = ( type ) => console . log . bind ( console , type ) ;
147
131
148
132
// // Automatically calculate GMT timezone
149
133
function getTimezoneOffset ( ) {
150
- function z ( n ) { return ( n < 10 ? '0' : '' ) + n }
134
+ function z ( n ) {
135
+ return ( n < 10 ? '0' : '' ) + n ;
136
+ }
151
137
var offset = new Date ( ) . getTimezoneOffset ( ) ;
152
- var sign = offset < 0 ? '+' : '-' ;
138
+ var sign = offset < 0 ? '+' : '-' ;
153
139
offset = Math . abs ( offset ) ;
154
- return " GMT " + sign + z ( offset / 60 | 0 ) + z ( offset % 60 ) ;
140
+ return ' GMT ' + sign + z ( ( offset / 60 ) | 0 ) + z ( offset % 60 ) ;
155
141
}
156
142
157
143
function isValidGMT ( userInp ) {
@@ -165,40 +151,49 @@ class MeetForm extends React.Component {
165
151
this . state = {
166
152
formSchema : schema ,
167
153
dataFetched : false ,
168
- redirect : false
154
+ redirect : false ,
169
155
} ;
170
156
}
171
157
172
158
async componentDidMount ( ) {
173
- const meet_info = await API . get (
174
- " treehacks" ,
159
+ var meet_info = await API . get (
160
+ ' treehacks' ,
175
161
`/users/${ this . props . user . username } /forms/meet_info` ,
176
162
{ }
177
163
) ;
178
- console . log ( "User: " + this . props . user . username ) ;
164
+
165
+ meet_info = {
166
+ ...meet_info ,
167
+ userType : meet_info . isMentor ? 'Mentor' : 'Hacker' ,
168
+ } ;
169
+
179
170
if ( meet_info ) {
180
171
for ( const index in meet_info ) {
181
- if ( ! ( index in this . state . formSchema [ " properties" ] ) ) continue ;
182
- this . state . formSchema [ " properties" ] [ index ] [ " default" ] =
172
+ if ( ! ( index in this . state . formSchema [ ' properties' ] ) ) continue ;
173
+ this . state . formSchema [ ' properties' ] [ index ] [ ' default' ] =
183
174
meet_info [ index ] ;
184
175
}
185
176
186
177
this . setState ( {
187
178
formSchema : this . state . formSchema ,
188
- dataFetched : true
179
+ dataFetched : true ,
189
180
} ) ;
190
181
}
191
182
}
192
183
193
184
async submitForm ( e ) {
194
- const payload = { body : { ...e . formData , isMentor : e . formData . userType === "Mentor" } }
195
- delete payload [ "body" ] [ "userType" ] ;
185
+ const payload = {
186
+ body : { ...e . formData , isMentor : e . formData . userType === 'Mentor' } ,
187
+ } ;
188
+ delete payload [ 'body' ] [ 'userType' ] ;
196
189
197
- if ( isValidGMT ( payload [ "body" ] [ "timezoneOffset" ] ) == null ) {
198
- alert ( "Please enter your GMT timezone in a valid format (e.g GMT +0800, GMT -1130)" ) ;
190
+ if ( isValidGMT ( payload [ 'body' ] [ 'timezoneOffset' ] ) == null ) {
191
+ alert (
192
+ 'Please enter your GMT timezone in a valid format (e.g GMT +0800, GMT -1130)'
193
+ ) ;
199
194
} else {
200
195
const resp = await API . put (
201
- " treehacks" ,
196
+ ' treehacks' ,
202
197
`/users/${ this . props . user . username } /forms/meet_info` ,
203
198
payload
204
199
) ;
@@ -211,18 +206,17 @@ class MeetForm extends React.Component {
211
206
//if (false) {
212
207
if ( ! this . state . dataFetched ) {
213
208
return < Loading /> ;
214
- }
215
- else {
209
+ } else {
216
210
return (
217
- < div id = " form" >
211
+ < div id = ' form' >
218
212
< Form
219
213
schema = { this . state . formSchema }
220
214
uiSchema = { uiSchema }
221
- onChange = { log ( " changed" ) }
222
- onSubmit = { e => this . submitForm ( e ) }
223
- onError = { log ( " errors" ) }
215
+ onChange = { log ( ' changed' ) }
216
+ onSubmit = { ( e ) => this . submitForm ( e ) }
217
+ onError = { log ( ' errors' ) }
224
218
/>
225
- { this . state . redirect && < Redirect to = "/" /> }
219
+ { this . state . redirect && < Redirect to = '/' /> }
226
220
</ div >
227
221
) ;
228
222
}
0 commit comments