Skip to content

Commit 42a9f9b

Browse files
committed
Copied over changes, nuked old Signup page
1 parent b7ef41d commit 42a9f9b

File tree

3 files changed

+79
-197
lines changed

3 files changed

+79
-197
lines changed

frontend/src/components/auth/Signup.tsx

-122
This file was deleted.

frontend/src/components/forms/Signup.tsx

+76-75
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import React, { useContext } from "react";
22
import { Redirect, useHistory } from "react-router-dom";
3-
import { Box, Button, Flex, Input, Text } from "@chakra-ui/react";
3+
import {
4+
Box,
5+
Button,
6+
Flex,
7+
FormControl,
8+
FormErrorMessage,
9+
Input,
10+
Text
11+
} from "@chakra-ui/react";
412
import authAPIClient from "../../APIClients/AuthAPIClient";
513
import { HOME_PAGE, LOGIN_PAGE } from "../../constants/Routes";
614
import AuthContext from "../../contexts/AuthContext";
@@ -18,6 +26,8 @@ type SignupProps = {
1826
setPassword: (password: string) => void;
1927
toggle: boolean;
2028
setToggle: (toggle: boolean) => void;
29+
emailError: boolean;
30+
setEmailError: (emailError: boolean) => void;
2131
};
2232

2333
const Signup = ({
@@ -31,10 +41,28 @@ const Signup = ({
3141
setPassword,
3242
toggle,
3343
setToggle,
44+
emailError,
45+
setEmailError
3446
}: SignupProps): React.ReactElement => {
3547
const { authenticatedUser, setAuthenticatedUser } = useContext(AuthContext);
3648
const history = useHistory();
3749

50+
const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
51+
const inputValue = e.target.value as string;
52+
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
53+
if (emailRegex.test(inputValue)) {
54+
setEmailError(false)
55+
} else {
56+
setEmailError(true)
57+
}
58+
setEmail(inputValue)
59+
};
60+
61+
const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
62+
const inputValue = e.target.value as string;
63+
setPassword(inputValue)
64+
}
65+
3866
const onSignupClick = async () => {
3967
const isInvited = await commonApiClient.isUserInvited(email);
4068
if (isInvited) {
@@ -56,14 +84,11 @@ const Signup = ({
5684
setAuthenticatedUser(authUser);
5785
}
5886
}
59-
} else {
60-
// TODO: make this alert better and also differentiate between
61-
// when a user is not invited and when a user's account already exists
62-
// eslint-disable-next-line no-alert
63-
window.alert("user not invited");
6487
}
6588
};
6689

90+
const isCreateAccountBtnDisabled = () => emailError || email === '' || password === '' || firstName === '' || lastName === ''
91+
6792
const onLogInClick = () => {
6893
history.push(LOGIN_PAGE);
6994
};
@@ -76,74 +101,54 @@ const Signup = ({
76101
return (
77102
<Flex h="100vh">
78103
<Box w="47%">
79-
<Flex
80-
display="flex"
81-
alignItems="flex-start"
82-
position="absolute"
83-
top="17.5%"
84-
left="6%"
85-
w="100%"
86-
>
87-
<Text variant="login" position="absolute">
88-
Sign Up
89-
</Text>
90-
</Flex>
91-
<Flex
92-
h="40%"
93-
w="36%"
94-
top="28%"
95-
left="6%"
96-
direction="column"
97-
position="absolute"
98-
justifyContent="space-between"
104+
<Flex
105+
marginTop="172px"
106+
display="flex"
107+
align="center"
108+
justify="center"
99109
>
100-
<Box>
110+
<Flex
111+
width="76%"
112+
align="flex-start"
113+
direction="column"
114+
gap="28px"
115+
>
116+
<Text variant="login" paddingBottom="12px">
117+
Sign Up
118+
</Text>
101119
<Input
102120
variant="login"
103-
position="absolute"
104121
placeholder="Your first name"
105122
value={firstName}
106123
onChange={(event) => setFirstName(event.target.value)}
107124
/>
108-
</Box>
109-
<Box>
110125
<Input
111126
variant="login"
112-
position="absolute"
113127
placeholder="Your last name"
114128
value={lastName}
115129
onChange={(event) => setLastName(event.target.value)}
116130
/>
117-
</Box>
118-
<Box>
119-
<Input
120-
variant="login"
121-
position="absolute"
122-
placeholder="Your email"
123-
value={email}
124-
onChange={(event) => setEmail(event.target.value)}
125-
/>
126-
</Box>
127-
<Box>
128-
<Input
129-
variant="login"
130-
type="password"
131-
position="absolute"
132-
placeholder="Your password"
133-
value={password}
134-
onChange={(event) => setPassword(event.target.value)}
135-
/>
136-
</Box>
137-
<Box>
131+
<FormControl isRequired isInvalid={emailError}>
132+
<Input
133+
variant="login"
134+
placeholder="Your email"
135+
value={email}
136+
onChange={handleEmailChange}
137+
/>
138+
<FormErrorMessage>Please enter a valid email.</FormErrorMessage>
139+
</FormControl>
140+
<FormControl isRequired>
141+
<Input
142+
variant="login"
143+
type="password"
144+
placeholder="Your password"
145+
value={password}
146+
onChange={handlePasswordChange}
147+
/>
148+
</FormControl>
138149
<Button
139150
variant="login"
140-
position="absolute"
141-
disabled={
142-
email === "" ||
143-
password === "" ||
144-
firstName === "" ||
145-
lastName === ""
146-
}
151+
disabled={isCreateAccountBtnDisabled()}
147152
_hover={
148153
email && password && firstName && lastName
149154
? {
@@ -157,22 +162,18 @@ const Signup = ({
157162
>
158163
Create Account
159164
</Button>
160-
</Box>
161-
</Flex>
162-
<Flex
163-
top="80%"
164-
left="6%"
165-
width="100%"
166-
direction="row"
167-
position="absolute"
168-
alignContent="center"
169-
>
170-
<Text variant="loginSecondary" paddingRight="1.1%">
171-
Already have an account?
172-
</Text>
173-
<Text variant="loginTertiary" onClick={onLogInClick}>
174-
Log In Now
175-
</Text>
165+
<Flex
166+
paddingTop="29px"
167+
alignContent="center"
168+
>
169+
<Text variant="loginSecondary" paddingRight="17px">
170+
Already have an account?
171+
</Text>
172+
<Text variant="loginTertiary" onClick={onLogInClick}>
173+
Log In Now
174+
</Text>
175+
</Flex>
176+
</Flex>
176177
</Flex>
177178
</Box>
178179
<Box flex="1" bg="teal.400">

frontend/src/components/pages/SignupPage.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const SignupPage = (): React.ReactElement => {
88
const [lastName, setLastName] = useState("");
99
const [email, setEmail] = useState("");
1010
const [password, setPassword] = useState("");
11+
const [emailError, setEmailError] = useState(false);
1112

1213
return (
1314
<>
@@ -22,6 +23,8 @@ const SignupPage = (): React.ReactElement => {
2223
setPassword={setPassword}
2324
toggle={toggle}
2425
setToggle={setToggle}
26+
emailError={emailError}
27+
setEmailError={setEmailError}
2528
/>
2629
<Authy email={email} password={password} token="" toggle={!toggle} />
2730
</>

0 commit comments

Comments
 (0)