Skip to content

Commit e7e39a3

Browse files
authored
Merge pull request #70 from CodeYourFuture/volunteer/email/vitrifaction
email vitrifaction
2 parents f36341e + b16dbd9 commit e7e39a3

File tree

5 files changed

+216
-22
lines changed

5 files changed

+216
-22
lines changed

src/Components/forms/helper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const initialState = {
2323
dashboardUrl: '',
2424
agreeToTOU: false,
2525
agreeToReceiveCommunication: false,
26+
showEmailBox: false,
27+
loading: false,
2628
errors: {
2729
firstName: false,
2830
lastName: false,

src/Components/forms/index.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,56 @@
146146
width: 100%;
147147
text-align: left;
148148
}
149+
.forms-important-box {
150+
font-family: Verdana, sans-serif;
151+
font-size: 15px;
152+
line-height: 1.5;
153+
color: #000 !important;
154+
box-sizing: inherit;
155+
background-color: #fcf6e5;
156+
border-left: none;
157+
margin-top: 24px;
158+
margin-bottom: 24px;
159+
padding: 16px;
160+
border: 1px solid rgb(218, 218, 218);
161+
}
162+
.forms-important-box-form {
163+
height: 30px;
164+
display: flex;
165+
width: 100%;
166+
margin: 10px 0;
167+
}
168+
.forms-important-box-form input {
169+
outline: none !important;
170+
border-radius: 2px 0 0 2px;
171+
height: 30px;
172+
border: 1px solid rgb(218, 218, 218);
173+
padding: 0 6px;
174+
width: 250px;
175+
}
176+
.forms-important-box-form button {
177+
outline: none !important;
178+
border-radius: 0 2px 2px 0;
179+
height: 30px;
180+
border: 1px solid rgb(218, 218, 218);
181+
cursor: pointer;
182+
background-color: #4daf50;
183+
color: #ffffff;
184+
}
185+
.forms-important-box-form button:hover {
186+
background-color: #4ac24e;
187+
color: #ffffff;
188+
}
189+
.forms-important-box-form button:disabled {
190+
color: #575757;
191+
background-color: #dadada;
192+
}
193+
.success {
194+
color: green;
195+
text-align: center;
196+
padding: 10px;
197+
font-size: 20px;
198+
}
149199
@media screen and (max-width: 1000px) {
150200
.media {
151201
display: block;

src/Components/forms/index.js

Lines changed: 154 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,76 @@ import { initialState, arrayOnChange, filterEmptyValue } from './helper'
55
import Header from './header'
66
import Inputs from './inputs'
77
import Acknowledgement from './Acknowledgement'
8+
import axios from 'axios'
9+
import { domain, appPath } from '../../config'
810
import './index.css'
11+
12+
const path = `${domain()}${appPath}`
913
class Forms extends Component {
1014
state = initialState
1115

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+
1263
UNSAFE_componentWillMount() {
1364
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+
}
1578
if (userId) {
1679
this.setState({ userId, dashboardUrl: dashboardUrl.slice(1) })
1780
}
@@ -33,7 +96,8 @@ class Forms extends Component {
3396
[name]: type === 'checkbox' ? checked : value,
3497
submitted: false,
3598
errors,
36-
formInComplete: false
99+
formInComplete: false,
100+
err: null
37101
})
38102
}
39103
}
@@ -167,8 +231,27 @@ class Forms extends Component {
167231
formInComplete,
168232
userId,
169233
dashboardUrl,
170-
agreeToReceiveCommunication
234+
agreeToReceiveCommunication,
235+
showEmailBox,
236+
msg,
237+
loading
171238
} = 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+
}
172255
if (volunteer && volunteer._id) {
173256
return (
174257
<div className="form-container container p-4">
@@ -195,24 +278,74 @@ class Forms extends Component {
195278
}
196279
return (
197280
<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+
placeholder="[email protected]"
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+
)}
216349
</div>
217350
)
218351
}

src/Redux/action/volunteersActions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ export const createVolunteer = async volunteer => {
88
const response = await axios.post(`${path}`, volunteer)
99
return response.data
1010
} catch (err) {
11+
if (
12+
err.response &&
13+
err.response.data &&
14+
err.response.data.error === 'EMAIL_EXIST'
15+
) {
16+
return {
17+
err: 'Volunteer account with this email address already exist.'
18+
}
19+
}
1120
return {
1221
err: 'Something went wrong, please try again later.'
1322
}

src/Routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import NotFound from '../Components/NotFound'
77
export default () => (
88
<Switch>
99
<Public exact path="/" component={Forms} />
10-
<Public exact path="/code/:userId" component={Forms} />
10+
<Public exact path="/code/:userId/:code?" component={Forms} />
1111
<Route path="*" component={NotFound} />
1212
</Switch>
1313
)

0 commit comments

Comments
 (0)