forked from bahmutov/cypress-email-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm.js
73 lines (64 loc) · 1.98 KB
/
confirm.js
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
import { useState } from 'react'
import 'tailwindcss/tailwind.css'
export default function Confirm() {
// I wish I could build a state machine here ;)
const [code, setCode] = useState('unknown')
const checkConfirmationCode = (event) => {
event.preventDefault()
if (event.target.confirmation_code.value === '654agc') {
setCode('confirmed')
} else {
setCode('wrong')
}
}
const IncorrectCode = () => (
<div
data-cy="incorrect-code"
className="text-center py-3 px-12 bg-red-400 mt-5 mr-5 rounded-md text-white text-lg focus:outline-none w-full"
>
Incorrect confirmation code
</div>
)
const ConfirmedCode = () => (
<div
data-cy="confirmed-code"
className="text-center py-3 px-12 bg-blue-400 mt-5 mr-5 rounded-md text-white text-lg focus:outline-none w-full"
>
Valid confirmation code 🎉
</div>
)
return (
<main className="mt-12 lg:mt-32">
<section className="container w-full max-w-md m-auto items-center">
<form
onSubmit={checkConfirmationCode}
className="bg-gray-100 shadow-sm rounded-md p-8"
>
<div className="mb-6">
<label
htmlFor="confirmation_code"
className="mb-3 block text-gray-700"
>
Enter the emailed confirmation code:
</label>
<input
type="text"
id="confirmation_code"
className="bg-white rounded-md border border-gray-200 p-3 focus:outline-none w-full"
placeholder="abc123"
required
/>
</div>
<button
type="submit"
className="py-3 px-12 bg-green-300 hover:bg-green-600 mr-5 rounded-md text-white text-lg focus:outline-none w-full"
>
Confirm
</button>
</form>
{code === 'confirmed' && <ConfirmedCode />}
{code === 'wrong' && <IncorrectCode />}
</section>
</main>
)
}