Skip to content

Commit

Permalink
[frontend] chore: lowercase input
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsdave committed May 10, 2024
1 parent 2c15325 commit ee22cc6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
14 changes: 10 additions & 4 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
body {
font-family: Arial, sans-serif;
font-family: Arial, Helvetica, sans-serif;
}

body {
Expand All @@ -9,6 +9,7 @@ body {
margin: 0px;
background: linear-gradient(100deg, #83a4d4, #b6fbff);
background-attachment: fixed;

}

@media (min-width: 600px) {
Expand Down Expand Up @@ -59,7 +60,7 @@ body {
border: 2px solid white;
border-radius: 20px;
width: 260px;
height: 260px;
height: 350px;
padding: 10px;
}

Expand Down Expand Up @@ -170,6 +171,11 @@ input {
font-size: 16px;
}

.registration-form-buttons {
display: flex;
justify-content: center;
}

textarea {
height: 100px;
}
Expand Down Expand Up @@ -209,7 +215,7 @@ textarea {
color: white;
text-decoration: none;
margin: 10px;

max-width: 100px;
}

.note-form button {
Expand Down Expand Up @@ -294,7 +300,7 @@ textarea {
.registration-form {
display: flex;
flex-direction: column;
gap: 20px;
gap: 20px;
}

.registration-form button {
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
<div className="login-page-form">
<form onSubmit={handleSubmit}>
<h3>Existing users</h3>
{errorText !== "" && <span>{errorText}</span>}
<input
type="text"
placeholder="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
onChange={(e) => setUsername(e.target.value.toLowerCase())}
data-testid="username"
required
/>
Expand All @@ -60,9 +61,7 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
data-testid="password"
required
/>
<button type="submit">Login</button>
{isDataLoading && <Spinner />}
{errorText !== "" && <span>{errorText}</span>}
{isDataLoading ? <Spinner /> : <button type="submit">Login</button>}
</form>
</div>
</div>
Expand Down
27 changes: 20 additions & 7 deletions frontend/src/components/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
setForm({ ...form, [e.target.name]: e.target.value });
};

const handleChangeUsername = (e: React.ChangeEvent<HTMLInputElement>) => {
setForm({ ...form, username: e.target.value.toLowerCase() });
};

const handleSubmit = async (e: React.FormEvent) => {
setForm({ ...form, errorText: "" });
e.preventDefault();
Expand All @@ -45,9 +49,15 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
if (errors instanceof AxiosError) {
const axiosError = errors as AxiosError;
if (axiosError.response?.status === 400) {
setForm({ ...form, errorText: "Error: Invalid username or password" });
setForm({
...form,
errorText: "Error: Invalid username or password",
});
} else {
setForm({ ...form, errorText: "Error: An error occurred. Please retry" });
setForm({
...form,
errorText: "Error: An error occurred. Please retry",
});
}
}
}
Expand All @@ -70,7 +80,7 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
type="text"
name="username"
value={form.username}
onChange={handleChange}
onChange={handleChangeUsername}
placeholder="Username"
required
/>
Expand Down Expand Up @@ -98,10 +108,13 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
placeholder="Confirm Password"
required
/>
<button type="submit">Register</button>
<a className="nav-link" href="/">
Close
</a>
<button type="submit">Register</button>

<div className='registration-form-buttons'>
<a className="nav-link" href="/">
Close
</a>
</div>
</form>
)}
</div>
Expand Down

1 comment on commit ee22cc6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

98.32%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   App.tsx87.50%75%95.95%29–30, 39–40
   NoteApp.tsx94.44%100%96.99%70–74
src/api
   apiService.ts100%100%100%
src/components
   Header.tsx100%100%100%
   Login.tsx81.82%100%98.59%32, 32–33
   Note.tsx100%100%100%
   NoteForm.tsx100%100%100%
   NoteFormModal.tsx100%100%100%
   NoteGrid.tsx100%100%100%
   RegistrationForm.tsx84.62%100%96.77%51, 51–55
   RegistrationLink.tsx100%100%100%
   Spinner.tsx100%100%100%

Please sign in to comment.