This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
/
index.vue
319 lines (308 loc) · 8.51 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<template>
<div class="welcome-page centralize">
<div class="visible-content">
<div class="hero-content">
<!-- left/top: text and cards -->
<section>
<h1 class="heading-top text-center mt-5 mb-5">SleepRescue.org</h1>
<h2 class="heading-sub text-center">
Let's get your sleep back on track
</h2>
<div class="hero-text">
Sleep is not a privilege, yet so many of us are struggling with
insomnia. Sleep Rescue offers resources for self-guided Cognitive
Behavioural Therapy for insomnia (CBT-i).
</div>
<div class="text-center text-sm pt-2 pb-2">
<p>
Feel free to explore our
<span
class="font-bold text-dark bg-secondary rounded-2xl p-2 shadow-md"
><NuxtLink :to="learningCenterPath"
>Learning Center</NuxtLink
></span
>
</p>
</div>
</section>
<section class="welcome-cards">
<HeroCard
text="Learn to use CBT-i"
card-type="card-group-secondary"
img-path="images/cbti_book.svg"
/>
<HeroCard
text="Track your progress"
card-type="card-group-primary"
img-path="images/track_progress.svg"
/>
<HeroCard
text="Improve your sleep"
card-type="card-group-secondary"
img-path="images/improve_sleep.svg"
/>
</section>
</div>
<div class="focus-card card-background">
<section class="signup-text">
<div class="title-text text-center !text-dark">Sign Up For Free</div>
<div class="signup-subheader">Your recovery begins today</div>
</section>
<form
action=""
name="signup"
method="post"
class="form-entry"
@submit.prevent="registerUser"
>
<FormEntry icon="at">
<input
v-model="registration.user.email"
type="text"
placeholder="Email..."
class="form-input"
required
:pattern="emailPattern"
oninput="setCustomValidity('')"
oninvalid="setCustomValidity('Please provide a valid email address')"
/>
</FormEntry>
<FormEntry icon="key">
<input
v-model="registration.user.password"
type="password"
placeholder="Password..."
class="form-input"
required
pattern="[A-Za-z\d@$!%*?&]{8,}"
oninput="setCustomValidity('')"
oninvalid="setCustomValidity('Your password must contain at least 8 alphanumeric characters')"
/>
</FormEntry>
<FormEntry icon="lock">
<input
id="password_confirmation"
ref="password_confirmation"
v-model="registration.user.password_confirmation"
type="password"
placeholder="Repeat password..."
class="form-input"
oninput="setCustomValidity('')"
required
@change="checkPasswordEquality"
/>
</FormEntry>
<input
class="dark-btn"
type="submit"
name="sign up"
:value="buttonLabel"
:class="isLoading ? 'animate-pulse' : ''"
/>
</form>
<section class="existing-users">
<div>
Already have an account?
<span class="highlight-text-white" @click="toggleSignInModal"
><u><strong>Sign in</strong></u></span
>
</div>
</section>
<div class="line-divider" />
<div class="signup-disclaimer">
By signing up, you confirm that you agree to our
<strong>Terms of Service</strong> and <strong>Privacy Policy</strong>
</div>
</div>
</div>
<p class="disclaimer-text">
This website was created by CBT-i practitioners, not by medical
professionals, check with your doctor if CBT-i is right for you
</p>
<!-- Revealable content -->
<SigninModal v-if="showSignInModal" />
<CookiesNotice />
</div>
</template>
<script>
import { mapMutations } from 'vuex'
import { minLength, sameAs, email, required } from 'vuelidate/lib/validators'
import { EMAIL_PATTERN } from '~/assets/js/constants'
import HeroCard from '~/components/signup/HeroCard'
import SigninModal from '~/components/signup/SigninModal'
import FormEntry from '~/components/layout/FormEntry'
import CookiesNotice from '~/components/signup/CookiesNotice'
export default {
components: {
CookiesNotice,
HeroCard,
FormEntry,
SigninModal,
},
data() {
return {
emailPattern: EMAIL_PATTERN,
isLoading: false,
registration: {
user: {
email: null,
password: null,
password_confirmation: null,
},
},
}
},
validations: {
registration: {
user: {
email: {
email,
},
password: {
minLength: minLength(8),
required,
},
password_confirmation: {
sameAsPassword: sameAs('password'),
},
},
},
},
head: {
title: 'Signup',
meta: [
{
hid: 'description',
name: 'description',
content:
'Sign up for SleepRescue.org and start fixing your insomnia today',
},
{
hid: 'keywords',
name: 'keywords',
keywords:
'insomnia, sleeplessness, cbti, cognitive behavioural therapy',
},
{ charset: 'utf-8' },
],
},
computed: {
buttonLabel() {
return this.isLoading ? 'Processing...' : 'Continue'
},
showSignInModal() {
return this.$store.state.showSignInModal
},
passwordsMatch() {
const form = this.registration.user
return form.password === form.password_confirmation
},
learningCenterPath() {
const fallback = '/learning/foreword'
try {
return localStorage.getItem('learningCenterPath') ?? fallback
} catch {
return fallback
}
},
},
beforeCreate() {
if (this.$auth.loggedIn) {
this.$auth.redirect('home')
}
},
mounted() {
this.$store.commit('clearSignUpState')
},
methods: {
...mapMutations({
setError: 'setError',
toggleSignInModal: 'toggleSignInModal',
}),
async registerUser() {
this.$ga.event({
eventCategory: 'engagement',
eventAction: 'sign_up',
eventLabel: 'method',
eventValue: 1,
})
this.$v.$touch()
if (this.$v.$invalid) {
this.flashError(
'Please provide a valid email with matching passwords containing at least 8 alphanumeric characters'
)
} else {
try {
this.isLoading = true
await this.$axios.post('v1/user/create', this.registration)
await this.$auth.loginWith('local', { data: this.registration })
this.$nuxt.context.redirect('/confirm')
} catch (error) {
const errorMessage =
error?.response?.data?.error?.message ??
'Our server seems to be down'
this.flashError(errorMessage)
} finally {
this.isLoading = false
}
}
},
checkPasswordEquality() {
const validity = this.passwordsMatch ? '' : 'passwords do not match'
this.$refs.password_confirmation.setCustomValidity(validity)
},
flashError(message) {
this.$store.commit('setError', message)
setTimeout(() => {
this.$store.commit('setError', null)
}, 5000)
},
},
}
</script>
<style lang="scss">
.welcome-page {
@apply relative flex flex-col justify-between;
}
.visible-content {
@apply flex flex-col justify-center items-center;
@screen lg {
@apply flex-row items-baseline;
}
@screen xl {
@apply items-start;
}
}
.hero-content {
@apply flex flex-col justify-between
max-w-md
mb-5
lg:mr-6 xl:mr-36;
}
.hero-text {
@apply text-center text-base xl:text-xl
mt-3 mb-3;
}
.disclaimer-text {
@apply text-center text-xs 2xl:text-sm
pb-5 pt-5 2xl:pt-16 3xl:pb-16;
}
.signup-disclaimer {
@apply text-center
pb-5 ml-5 mr-5;
}
.welcome-cards {
@apply flex flex-row justify-between
max-w-xs;
}
.signup-text {
@apply pb-5;
}
.signup-subheader {
@apply text-center;
}
.existing-users {
@apply text-center
mb-2.5 mt-2.5;
}
</style>