-
Notifications
You must be signed in to change notification settings - Fork 897
refactor(site): SignInForm without wrapper component #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b3bdf83
d2741c3
918dd80
73df2da
e1e12d8
108c77e
50e6e0c
17bc113
c5619f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ import React from "react" | |
import * as Yup from "yup" | ||
|
||
import { Welcome } from "./Welcome" | ||
import { FormTextField } from "../Form" | ||
import FormHelperText from "@material-ui/core/FormHelperText" | ||
import { LoadingButton } from "./../Button" | ||
import TextField from "@material-ui/core/TextField" | ||
|
||
/** | ||
* BuiltInAuthFormValues describes a form using built-in (email/password) | ||
|
@@ -18,8 +18,14 @@ interface BuiltInAuthFormValues { | |
password: string | ||
} | ||
|
||
export const LANGUAGE = { | ||
emailInvalid: "Please enter a valid email address.", | ||
emailRequired: "Please enter an email address.", | ||
authErrorMessage: "Incorrect email or password." | ||
} | ||
|
||
const validationSchema = Yup.object({ | ||
email: Yup.string().required("Email is required."), | ||
email: Yup.string().trim().email(LANGUAGE.emailInvalid).required(LANGUAGE.emailRequired), | ||
password: Yup.string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vapurrmaid @kylecarbs do we want validation on the password? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same as it is in V1, I'm inclined to circle back to it later since it's separate from this change and would need some tests. I think that overhead warrants it as a separate concern. There's also potentially the desire to have the validation regex come from the backend so that it's centralized. We can brainstorm more on that over gap week next week. cc @f0ssel @deansheather @johnstcn @coadler --> we've all spoken about centralizing things in the backend at some point in a recent breakout session, would love to noodle on moving validation/regexes into the BE as well, to see if it's a worthwhile idea to explore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in this case if we just make it so the backend does the validation and then returns a per-field error that the frontend can parse then it's the same effect without having to do weird stuff like returning regexes from the backend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth considering, but we should also think about the user experience of having to submit your form before you find out that it's invalid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
|
||
|
@@ -59,52 +65,38 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess | |
<> | ||
<Welcome /> | ||
<form onSubmit={form.handleSubmit}> | ||
<div> | ||
<FormTextField | ||
label="Email" | ||
autoComplete="email" | ||
autoFocus | ||
className={styles.loginTextField} | ||
eventTransform={(email: string) => email.trim()} | ||
form={form} | ||
formFieldName="email" | ||
fullWidth | ||
inputProps={{ | ||
id: "signin-form-inpt-email", | ||
}} | ||
variant="outlined" | ||
/> | ||
<FormTextField | ||
label="Password" | ||
autoComplete="current-password" | ||
className={styles.loginTextField} | ||
form={form} | ||
formFieldName="password" | ||
fullWidth | ||
inputProps={{ | ||
id: "signin-form-inpt-password", | ||
}} | ||
isPassword | ||
variant="outlined" | ||
/> | ||
{authErrorMessage && ( | ||
<FormHelperText data-testid="sign-in-error" error> | ||
{authErrorMessage} | ||
</FormHelperText> | ||
)} | ||
</div> | ||
<div className={styles.submitBtn}> | ||
<LoadingButton | ||
color="primary" | ||
loading={isLoading} | ||
fullWidth | ||
id="signin-form-submit" | ||
type="submit" | ||
variant="contained" | ||
> | ||
{isLoading ? "" : "Sign In"} | ||
</LoadingButton> | ||
</div> | ||
<TextField | ||
{...form.getFieldProps("email")} | ||
autoFocus | ||
autoComplete="email" | ||
className={styles.loginTextField} | ||
error={form.touched.email && Boolean(form.errors.email)} | ||
fullWidth | ||
helperText={form.touched.email && form.errors.email} | ||
id="email" | ||
label="Email" | ||
variant="outlined" | ||
/> | ||
<TextField | ||
{...form.getFieldProps("password")} | ||
autoComplete="current-password" | ||
className={styles.loginTextField} | ||
fullWidth | ||
id="password" | ||
label="Password" | ||
type="password" | ||
variant="outlined" | ||
/> | ||
{authErrorMessage && ( | ||
<FormHelperText data-testid="sign-in-error" error> | ||
{LANGUAGE.authErrorMessage} | ||
</FormHelperText> | ||
)} | ||
<div className={styles.submitBtn}> | ||
<LoadingButton color="primary" loading={isLoading} fullWidth type="submit" variant="contained"> | ||
{isLoading ? "" : "Sign In"} | ||
</LoadingButton> | ||
</div> | ||
</form> | ||
</> | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.