Skip to content

Commit 2d9982a

Browse files
Beta end sign up form (#880)
## Issues connected Ref #875 Ref #876 Resolves #878 ## What has been done - Added logic for sign up form - Added message for sign up form (success, failed, invalid email) ## Testing - [x] Entering no email - "Invalid email" message is displayed - [x] Entering not valid email - "Invalid email" message is displayed - [x] Entering valid email - "Sign up successful" message is displayed - [x] If sign up successful, email input is cleared - [x] All messages (success or fail) disappears after 3 seconds - [x] After sign up, email used will be visible in customer.io -> People ## Screenshots / images / videos ![Zrzut ekranu 2023-12-12 o 15 02 53](https://github.com/tahowallet/dapp/assets/73061939/8e1cd934-c08d-44d4-81c9-372d8bbe2f2d)
2 parents cb7d393 + 20fc1a9 commit 2d9982a

File tree

5 files changed

+112
-12
lines changed

5 files changed

+112
-12
lines changed

src/env.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ declare namespace NodeJS {
4343
interface Navigator {
4444
brave?: { isBrave: () => boolean }
4545
}
46+
47+
interface Window {
48+
_cio: {
49+
identify: ({
50+
id,
51+
email,
52+
created_at,
53+
}: {
54+
id: string
55+
email: string
56+
created_at: number
57+
}) => void
58+
}
59+
}

src/public/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Subscape</title>
7+
<!-- Script for sending data to customer.io -->
8+
<script type="text/javascript">
9+
var _cio = _cio || [];
10+
(function() {
11+
var a,b,c;a=function(f){return function(){_cio.push([f].
12+
concat(Array.prototype.slice.call(arguments,0)))}};b=["load","identify",
13+
"sidentify","track","page"];for(c=0;c<b.length;c++){_cio[b[c]]=a(b[c])};
14+
var t = document.createElement('script'),
15+
s = document.getElementsByTagName('script')[0];
16+
t.async = true;
17+
t.id = 'cio-tracker';
18+
t.setAttribute('data-site-id', '27aa7555738fc28e5fe8');
19+
t.src = 'https://assets.customer.io/assets/track.js';
20+
s.parentNode.insertBefore(t, s);
21+
})();
22+
</script>
23+
<!-- Script for sending data to customer.io -->
724
<style>
825
body {
926
background: #142D2B;

src/shared/constants/regex.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
/* eslint-disable no-useless-escape */
2+
13
// Matches floating point numbers with optional thousands separators
24
export const FLOATING_POINT_REGEX = /^[^0-9]*([0-9,]+)(?:\.([0-9]*))?$/
35

46
// Matches number values and empty string
57
export const NUMBER_INPUT_REGEX = /^-?[0-9]*\.?[0-9]*$/
8+
9+
// Matches valid email
10+
export const EMAIL_REGEX = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g

src/ui/Island/Modals/BetaEndModal/GetUpdates.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export default function GetUpdates() {
77
<div className="modal_actions_column">
88
<h2 className="modal_actions_header">Get Updates</h2>
99
<p className="modal_actions_description">
10-
Sign up for updates bellow to learn
10+
Sign up for updates below to learn
1111
<br />
12-
when Season 1 is starting
12+
when Season 1 is starting.
1313
</p>{" "}
1414
<GetUpdatesForm />
1515
</div>

src/ui/Island/Modals/BetaEndModal/GetUpdatesForm.tsx

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,75 @@
1-
import React, { FormEvent, useState } from "react"
1+
import React, { ChangeEvent, FormEvent, useState } from "react"
22
import Button from "shared/components/Interface/Button"
3+
import { EMAIL_REGEX } from "shared/constants"
4+
import iconSuccess from "shared/assets/icons/m/notif-correct.svg"
5+
import iconFail from "shared/assets/icons/m/notif-wrong.svg"
6+
import Icon from "shared/components/Media/Icon"
7+
8+
enum SignUpMessage {
9+
SUCCESS = "Sign up successful",
10+
FAIL = "Invalid email address",
11+
}
312

413
export default function GetUpdatesForm() {
514
const [emailAddress, setEmailAddress] = useState("")
15+
const [signUpMessage, setSignUpMessage] = useState<string | null>(null)
616

717
const formSubmitHandler = (e: FormEvent) => {
818
e.preventDefault()
919

10-
// TODO: logic for sending form
20+
const trimmedEmailAddress = emailAddress.trim()
21+
const isEmail = EMAIL_REGEX.test(trimmedEmailAddress)
22+
23+
if (trimmedEmailAddress === "" || !isEmail) {
24+
setSignUpMessage(SignUpMessage.FAIL)
25+
return
26+
}
27+
28+
// eslint-disable-next-line no-underscore-dangle
29+
window._cio.identify({
30+
id: emailAddress,
31+
email: emailAddress,
32+
created_at: Math.floor(new Date().getTime() / 1000),
33+
})
34+
35+
setEmailAddress("")
36+
setSignUpMessage(SignUpMessage.SUCCESS)
37+
}
38+
39+
const handleEmailInputChange = (e: ChangeEvent<HTMLInputElement>) => {
40+
setEmailAddress(e.target.value)
41+
setSignUpMessage(null)
1142
}
1243

1344
return (
1445
<>
1546
<form className="row_center" onSubmit={formSubmitHandler}>
16-
<input
17-
tabIndex={0}
18-
placeholder="Email address"
19-
value={emailAddress}
20-
onChange={(e) => setEmailAddress(e.target.value)}
21-
className="modal_actions_input"
22-
/>
47+
<div style={{ position: "relative" }}>
48+
<input
49+
tabIndex={0}
50+
placeholder="Email address"
51+
value={emailAddress}
52+
onChange={handleEmailInputChange}
53+
className="modal_actions_input"
54+
/>
55+
{signUpMessage && (
56+
<div className="modal_actions_input_message row_center">
57+
<Icon
58+
src={
59+
signUpMessage === SignUpMessage.SUCCESS
60+
? iconSuccess
61+
: iconFail
62+
}
63+
color={
64+
signUpMessage === SignUpMessage.SUCCESS
65+
? "var(--trading-in)"
66+
: "var(--semantic-error)"
67+
}
68+
/>
69+
<span>{signUpMessage}</span>
70+
</div>
71+
)}
72+
</div>
2373
<Button buttonType="submit" style={{ transform: "translateX(-20px)" }}>
2474
Sign up
2575
</Button>
@@ -29,17 +79,31 @@ export default function GetUpdatesForm() {
2979
font-size: 16px;
3080
line-height: 24px;
3181
background: var(--primary-p1-100);
32-
padding: 12px 16px;
82+
padding: 12px 32px 12px 16px;
3383
outline: none;
3484
border-radius: 4px;
3585
border: 1.5px solid var(--green-60);
3686
font-family: var(--sans);
3787
color: var(--secondary-s1-100);
88+
width: 207px;
3889
}
3990
modal_actions_input:focus,
4091
modal_actions_input:active {
4192
border-color: var(--secondary-s1-100);
4293
}
94+
.modal_actions_input_message {
95+
position: absolute;
96+
left: 0;
97+
top: 100%;
98+
padding: 4px 8px;
99+
gap: 4px;
100+
color: ${signUpMessage === SignUpMessage.SUCCESS
101+
? "var(--trading-in)"
102+
: "var(--semantic-error)"};
103+
}
104+
.modal_actions_input_message > span {
105+
font-size: 14px;
106+
}
43107
`}</style>
44108
</>
45109
)

0 commit comments

Comments
 (0)