Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3bdf83

Browse files
committed
Remove wrapper from SignInForm
1 parent d665263 commit b3bdf83

File tree

1 file changed

+40
-48
lines changed

1 file changed

+40
-48
lines changed

site/src/components/SignIn/SignInForm.tsx

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import React from "react"
44
import * as Yup from "yup"
55

66
import { Welcome } from "./Welcome"
7-
import { FormTextField } from "../Form"
87
import FormHelperText from "@material-ui/core/FormHelperText"
98
import { LoadingButton } from "./../Button"
9+
import TextField from "@material-ui/core/TextField"
1010

1111
/**
1212
* BuiltInAuthFormValues describes a form using built-in (email/password)
@@ -18,8 +18,14 @@ interface BuiltInAuthFormValues {
1818
password: string
1919
}
2020

21+
export const LANGUAGE = {
22+
emailInvalid: "Please enter a valid email address.",
23+
emailRequired: "Please enter an email address.",
24+
authErrorMessage: "Incorrect email or password."
25+
}
26+
2127
const validationSchema = Yup.object({
22-
email: Yup.string().required("Email is required."),
28+
email: Yup.string().trim().email(LANGUAGE.emailInvalid).required(LANGUAGE.emailRequired),
2329
password: Yup.string(),
2430
})
2531

@@ -59,52 +65,38 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
5965
<>
6066
<Welcome />
6167
<form onSubmit={form.handleSubmit}>
62-
<div>
63-
<FormTextField
64-
label="Email"
65-
autoComplete="email"
66-
autoFocus
67-
className={styles.loginTextField}
68-
eventTransform={(email: string) => email.trim()}
69-
form={form}
70-
formFieldName="email"
71-
fullWidth
72-
inputProps={{
73-
id: "signin-form-inpt-email",
74-
}}
75-
variant="outlined"
76-
/>
77-
<FormTextField
78-
label="Password"
79-
autoComplete="current-password"
80-
className={styles.loginTextField}
81-
form={form}
82-
formFieldName="password"
83-
fullWidth
84-
inputProps={{
85-
id: "signin-form-inpt-password",
86-
}}
87-
isPassword
88-
variant="outlined"
89-
/>
90-
{authErrorMessage && (
91-
<FormHelperText data-testid="sign-in-error" error>
92-
{authErrorMessage}
93-
</FormHelperText>
94-
)}
95-
</div>
96-
<div className={styles.submitBtn}>
97-
<LoadingButton
98-
color="primary"
99-
loading={isLoading}
100-
fullWidth
101-
id="signin-form-submit"
102-
type="submit"
103-
variant="contained"
104-
>
105-
{isLoading ? "" : "Sign In"}
106-
</LoadingButton>
107-
</div>
68+
<TextField
69+
{...form.getFieldProps("email")}
70+
autoFocus
71+
autoComplete="email"
72+
className={styles.loginTextField}
73+
error={form.touched.email && Boolean(form.errors.email)}
74+
fullWidth
75+
helperText={form.touched.email && form.errors.email}
76+
id="email"
77+
label="Email"
78+
variant="outlined"
79+
/>
80+
<TextField
81+
{...form.getFieldProps("password")}
82+
autoComplete="current-password"
83+
className={styles.loginTextField}
84+
fullWidth
85+
id="password"
86+
label="Password"
87+
type="password"
88+
variant="outlined"
89+
/>
90+
{authErrorMessage && (
91+
<FormHelperText data-testid="sign-in-error" error>
92+
{LANGUAGE.authErrorMessage}
93+
</FormHelperText>
94+
)}
95+
<div className={styles.submitBtn}>
96+
<LoadingButton color="primary" loading={isLoading} fullWidth type="submit" variant="contained">
97+
{isLoading ? "" : "Sign In"}
98+
</LoadingButton>
99+
</div>
108100
</form>
109101
</>
110102
)

0 commit comments

Comments
 (0)