@@ -5,13 +5,76 @@ import { initialState, arrayOnChange, filterEmptyValue } from './helper'
5
5
import Header from './header'
6
6
import Inputs from './inputs'
7
7
import Acknowledgement from './Acknowledgement'
8
+ import axios from 'axios'
9
+ import { domain , appPath } from '../../config'
8
10
import './index.css'
11
+
12
+ const path = `${ domain ( ) } ${ appPath } `
9
13
class Forms extends Component {
10
14
state = initialState
11
15
16
+ handleMagicLinkRequest = async e => {
17
+ e . preventDefault ( )
18
+ const { email, userId } = this . state
19
+ if ( email ) {
20
+ this . setState ( { loading : true , err : '' } )
21
+ try {
22
+ const magicLinkRequest = await axios . post (
23
+ `${ path } /email/verification` ,
24
+ {
25
+ email,
26
+ userId
27
+ }
28
+ )
29
+ if ( magicLinkRequest . status === 200 ) {
30
+ this . setState ( {
31
+ loading : false ,
32
+ msg :
33
+ 'We have sent you a verification email, Please check your emails.'
34
+ } )
35
+ }
36
+ } catch ( err ) {
37
+ if (
38
+ err . response &&
39
+ err . response . data &&
40
+ err . response . data . err === 'EMAIL_EMPTY'
41
+ ) {
42
+ return this . setState ( {
43
+ loading : false ,
44
+ err : 'Email cannot be empty.'
45
+ } )
46
+ }
47
+ console . log ( err . response . data )
48
+ if ( err . response && err . response . data === 'NO_ACCOUNT' ) {
49
+ return this . setState ( {
50
+ loading : false ,
51
+ err : 'No account was found.'
52
+ } )
53
+ }
54
+ return this . setState ( {
55
+ err :
56
+ 'Sorry, we are currently experiencing technical issues, please try again later.' ,
57
+ loading : false
58
+ } )
59
+ }
60
+ }
61
+ }
62
+
12
63
UNSAFE_componentWillMount ( ) {
13
64
const dashboardUrl = this . props . location . search
14
- const { userId } = this . props . match . params
65
+ const { userId, code } = this . props . match . params
66
+ if ( code === 'failed' ) {
67
+ this . setState ( {
68
+ showEmailBox : true ,
69
+ err :
70
+ 'Failed to verify your email address, due to expire token or server failure. Please use the box below and try again.'
71
+ } )
72
+ }
73
+ if ( code === 'success' ) {
74
+ this . setState ( {
75
+ msg : `Thank you for your patient, we will review your application and contact you via email, within 10 days.`
76
+ } )
77
+ }
15
78
if ( userId ) {
16
79
this . setState ( { userId, dashboardUrl : dashboardUrl . slice ( 1 ) } )
17
80
}
@@ -33,7 +96,8 @@ class Forms extends Component {
33
96
[ name ] : type === 'checkbox' ? checked : value ,
34
97
submitted : false ,
35
98
errors,
36
- formInComplete : false
99
+ formInComplete : false ,
100
+ err : null
37
101
} )
38
102
}
39
103
}
@@ -167,8 +231,27 @@ class Forms extends Component {
167
231
formInComplete,
168
232
userId,
169
233
dashboardUrl,
170
- agreeToReceiveCommunication
234
+ agreeToReceiveCommunication,
235
+ showEmailBox,
236
+ msg,
237
+ loading
171
238
} = this . state
239
+ if ( loading ) {
240
+ return (
241
+ < div className = "d-flex justify-content-center mt-5" >
242
+ < div className = "loader" />
243
+ </ div >
244
+ )
245
+ }
246
+ if ( msg ) {
247
+ return (
248
+ < div style = { { padding : '5%' } } >
249
+ < p className = "success" style = { { fontSize : '24px' } } >
250
+ { msg }
251
+ </ p >
252
+ </ div >
253
+ )
254
+ }
172
255
if ( volunteer && volunteer . _id ) {
173
256
return (
174
257
< div className = "form-container container p-4" >
@@ -195,24 +278,74 @@ class Forms extends Component {
195
278
}
196
279
return (
197
280
< div className = "form-container container" >
198
- < Header err = { err } formInComplete = { formInComplete } userId = { userId } />
199
- < form className = "mb-4" onSubmit = { this . handleSubmit } method = "post" >
200
- < Inputs
201
- onChange = { this . onChange }
202
- telOnChange = { this . telOnChange }
203
- onChangeCheckList = { this . onChangeCheckList }
204
- { ...this . props }
205
- { ...this . state }
206
- />
207
- < Acknowledgement onChange = { this . onChange } { ...this . state } />
208
- < button
209
- disabled = { disabled || ! agreeToTOU || ! agreeToReceiveCommunication }
210
- className = "btn volunteer-submit-btn"
211
- type = "submit"
212
- >
213
- Submit
214
- </ button >
215
- </ form >
281
+ < Header
282
+ err = { err || this . state . err }
283
+ formInComplete = { formInComplete }
284
+ userId = { userId }
285
+ />
286
+ { userId && (
287
+ < div className = "forms-important-box" >
288
+ < span >
289
+ < strong > Important:</ strong > If you already completed this form in
290
+ some point please click{ ' ' }
291
+ < span
292
+ style = { { cursor : 'pointer' , color : '#0053ff' } }
293
+ onMouseDown = { ( ) => this . setState ( { showEmailBox : true } ) }
294
+ >
295
+ here
296
+ </ span >
297
+ .
298
+ </ span >
299
+ { showEmailBox && (
300
+ < div >
301
+ < span >
302
+ Please entre the email you used for volunteer application form
303
+ and click submit.
304
+ </ span >
305
+ < form
306
+ className = "forms-important-box-form"
307
+ onSubmit = { this . handleMagicLinkRequest }
308
+ >
309
+ < input
310
+ onChange = { this . onChange }
311
+ value = { this . state . email }
312
+ name = "email"
313
+
314
+ type = "email"
315
+ />
316
+ < button disabled = { ! this . state . email } type = "submit" >
317
+ Submit
318
+ </ button >
319
+ </ form >
320
+ < span
321
+ style = { { cursor : 'pointer' , color : '#0053ff' } }
322
+ onMouseDown = { ( ) => this . setState ( { showEmailBox : false } ) }
323
+ >
324
+ Cancel
325
+ </ span >
326
+ </ div >
327
+ ) }
328
+ </ div >
329
+ ) }
330
+ { ! showEmailBox && (
331
+ < form className = "mb-4" onSubmit = { this . handleSubmit } method = "post" >
332
+ < Inputs
333
+ onChange = { this . onChange }
334
+ telOnChange = { this . telOnChange }
335
+ onChangeCheckList = { this . onChangeCheckList }
336
+ { ...this . props }
337
+ { ...this . state }
338
+ />
339
+ < Acknowledgement onChange = { this . onChange } { ...this . state } />
340
+ < button
341
+ disabled = { disabled || ! agreeToTOU || ! agreeToReceiveCommunication }
342
+ className = "btn volunteer-submit-btn"
343
+ type = "submit"
344
+ >
345
+ Submit
346
+ </ button >
347
+ </ form >
348
+ ) }
216
349
</ div >
217
350
)
218
351
}
0 commit comments