From 69dcd53b9f1b81457ae6daa0df04e5a7d7fb1e02 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 3 Nov 2023 09:27:25 -0400 Subject: [PATCH] Tidy --- src/components/Login/Login.tsx | 21 ++++++++-------- src/components/Login/Signup.tsx | 43 ++++++++++++--------------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/components/Login/Login.tsx b/src/components/Login/Login.tsx index f40da23f77..7de3530dc4 100644 --- a/src/components/Login/Login.tsx +++ b/src/components/Login/Login.tsx @@ -6,6 +6,7 @@ import { Grid, Link, TextField, + TextFieldProps, Typography, } from "@mui/material"; import { @@ -84,6 +85,14 @@ export default function Login(): ReactElement { } }; + const defaultTextFieldProps: TextFieldProps = { + inputProps: { maxLength: 100 }, + margin: "normal", + required: true, + style: { width: "100%" }, + variant: "outlined", + }; + return ( @@ -96,36 +105,28 @@ export default function Login(): ReactElement { {/* Username field */} {/* Password field */} {/* "Forgot password?" link to reset password */} diff --git a/src/components/Login/Signup.tsx b/src/components/Login/Signup.tsx index 1db29ebff0..46dc3d582a 100644 --- a/src/components/Login/Signup.tsx +++ b/src/components/Login/Signup.tsx @@ -4,6 +4,7 @@ import { CardContent, Grid, TextField, + TextFieldProps, Typography, } from "@mui/material"; import { @@ -115,8 +116,7 @@ export default function Signup(props: SignupProps): ReactElement { e: ChangeEvent, field: SignupField ): void => { - const partialRecord = { [field]: e.target.value }; - setFieldText((prev) => ({ ...prev, ...partialRecord })); + setFieldText((prev) => ({ ...prev, [field]: e.target.value })); }; const signUp = async (e: FormEvent): Promise => { @@ -132,10 +132,10 @@ export default function Signup(props: SignupProps): ReactElement { // Check for bad field values. const err: SignupError = { [SignupField.Name]: !name, + [SignupField.Username]: !meetsUsernameRequirements(username), [SignupField.Email]: !email, [SignupField.Password1]: !meetsPasswordRequirements(password1), [SignupField.Password2]: password1 !== password2!, - [SignupField.Username]: !meetsUsernameRequirements(username), }; if (Object.values(err).some((e) => e)) { @@ -147,6 +147,14 @@ export default function Signup(props: SignupProps): ReactElement { } }; + const defaultTextFieldProps: TextFieldProps = { + inputProps: { maxLength: 100 }, + margin: "normal", + required: true, + style: { width: "100%" }, + variant: "outlined", + }; + return ( @@ -159,6 +167,7 @@ export default function Signup(props: SignupProps): ReactElement { {/* Name field */} updateField(e, SignupField.Name)} - required - style={{ width: "100%" }} value={fieldText[SignupField.Name]} - variant="outlined" /> {/* Username field */} checkUsername()} onChange={(e) => updateField(e, SignupField.Username)} - required - style={{ width: "100%" }} value={fieldText[SignupField.Username]} - variant="outlined" /> {/* Email field */} updateField(e, SignupField.Email)} - required - style={{ width: "100%" }} type="email" value={fieldText[SignupField.Email]} - variant="outlined" /> {/* Password field */} updateField(e, SignupField.Password1)} - required - style={{ width: "100%" }} type="password" value={fieldText[SignupField.Password1]} - variant="outlined" /> {/* Confirm Password field */} updateField(e, SignupField.Password2)} - style={{ width: "100%" }} type="password" value={fieldText[SignupField.Password2]} - variant="outlined" /> {/* "Failed to sign up" */}