@hellotext/hellotext 1.7.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/__tests__/models/form_collection_test.js +1 -1
- package/dist/hellotext.js +1 -1
- package/docs/forms.md +17 -4
- package/lib/controllers/form_controller.js +19 -14
- package/lib/hellotext.js +3 -8
- package/lib/index.js +0 -2
- package/lib/locales/en.js +4 -10
- package/lib/locales/es.js +4 -10
- package/lib/models/form.js +0 -3
- package/package.json +1 -1
- package/src/controllers/form_controller.js +21 -17
- package/src/hellotext.js +4 -4
- package/src/index.js +0 -2
- package/src/locales/en.js +4 -10
- package/src/locales/es.js +4 -10
- package/src/models/form.js +0 -4
- package/styles/index.css +2 -0
- package/alpha.html +0 -23
- package/lib/builders/otp_builder.js +0 -39
- package/lib/controllers/otp_controller.js +0 -139
- package/src/builders/otp_builder.js +0 -46
- package/src/controllers/otp_controller.js +0 -101
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Controller } from '@hotwired/stimulus'
|
|
2
|
-
|
|
3
|
-
import Hellotext from '../hellotext'
|
|
4
|
-
import SubmissionsAPI from '../api/submissions'
|
|
5
|
-
|
|
6
|
-
export default class extends Controller {
|
|
7
|
-
static values = {
|
|
8
|
-
submissionId: String,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static targets = ['input', 'submitButton', 'resendButton']
|
|
12
|
-
|
|
13
|
-
initialize() {
|
|
14
|
-
super.initialize()
|
|
15
|
-
|
|
16
|
-
this.attempts = 0
|
|
17
|
-
this.onInputChange = this.onInputChange.bind(this)
|
|
18
|
-
|
|
19
|
-
this.throttleInterval = setInterval(() => {
|
|
20
|
-
this.attempts = 0
|
|
21
|
-
}, 60000)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
connect() {
|
|
25
|
-
this.inputTarget.addEventListener('input', this.onInputChange)
|
|
26
|
-
this.inputTarget.focus()
|
|
27
|
-
|
|
28
|
-
super.connect()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
disconnect() {
|
|
32
|
-
clearInterval(this.throttleInterval)
|
|
33
|
-
this.inputTarget.removeEventListener('input', this.onInputChange)
|
|
34
|
-
|
|
35
|
-
super.disconnect()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async resend() {
|
|
39
|
-
if (this.throttled) {
|
|
40
|
-
return alert(Hellotext.business.locale.otp.throttled)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.resendButtonTarget.disabled = true
|
|
44
|
-
const response = await SubmissionsAPI.resendOTP(this.submissionIdValue)
|
|
45
|
-
|
|
46
|
-
if (response.succeeded) {
|
|
47
|
-
this.resendButtonTarget.disabled = false
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
alert(Hellotext.business.locale.otp.resend_successful)
|
|
51
|
-
this.attempts += 1
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
onInputChange() {
|
|
55
|
-
if (this.inputTarget.value.length !== 6) return
|
|
56
|
-
this.submit()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async submit() {
|
|
60
|
-
if(this.inputTarget.value.length !== 6) {
|
|
61
|
-
return alert(Hellotext.business.locale.otp.invalid)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.disable()
|
|
65
|
-
|
|
66
|
-
const response = await SubmissionsAPI.verifyOTP(this.submissionIdValue, this.inputTarget.value)
|
|
67
|
-
|
|
68
|
-
if (response.succeeded) {
|
|
69
|
-
this.dispatch('verified', {
|
|
70
|
-
detail: { submissionId: this.submissionIdValue },
|
|
71
|
-
})
|
|
72
|
-
} else {
|
|
73
|
-
alert(Hellotext.business.locale.otp.invalid)
|
|
74
|
-
|
|
75
|
-
setTimeout(() => {
|
|
76
|
-
this.inputTarget.value = ''
|
|
77
|
-
this.inputTarget.focus()
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.enable()
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// private
|
|
85
|
-
|
|
86
|
-
disable() {
|
|
87
|
-
this.inputTarget.disabled = true
|
|
88
|
-
this.resendButtonTarget.disabled = true
|
|
89
|
-
this.submitButtonTarget.disabled = true
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
enable() {
|
|
93
|
-
this.inputTarget.disabled = false
|
|
94
|
-
this.resendButtonTarget.disabled = false
|
|
95
|
-
this.submitButtonTarget.disabled = false
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get throttled() {
|
|
99
|
-
return this.attempts >= 3
|
|
100
|
-
}
|
|
101
|
-
}
|