Skip to content

Commit

Permalink
[frontend] chore: Added spinner for registration (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsdave authored May 16, 2024
1 parent ca3f4d8 commit f960cc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
15 changes: 14 additions & 1 deletion frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ body {
background-image: url('../public/hero.jpg');
background-size: cover;
background-position: center;
background-attachment: fixed ;
background-attachment: fixed;
}

body::before {
content: "";
position: fixed; /* This makes it stay in place on scroll */
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1; /* Keep it behind the content */
background-image: url('../public/hero.jpg');
background-size: cover;
background-position: center;
}

@media (min-width: 600px) {
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/components/RegistrationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from "react";
import { AxiosError } from "axios";
import { createUser } from "../api/apiService";
import Spinner from "./Spinner";

export interface RegistrationFormProps {
onRegister: () => void;
Expand All @@ -14,6 +15,7 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
confirmPassword: "",
errorText: "",
});
const [isDataLoading, setIsDataLoading] = useState(false);

const [registered, setRegistered] = useState(false);

Expand All @@ -36,16 +38,20 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
}

try {
setIsDataLoading(true);
await createUser({
username: form.username,
email: form.email,
password: form.password,
});
setRegistered(true);
setIsDataLoading(false);
onRegister();
} catch (error) {
const errors = error as Error | AxiosError;
// Check if the error is an AxiosError
setIsDataLoading(false);

if (errors instanceof AxiosError) {
const axiosError = errors as AxiosError;
if (axiosError.response?.status === 400) {
Expand Down Expand Up @@ -108,9 +114,14 @@ const RegistrationForm: React.FC<RegistrationFormProps> = ({ onRegister }) => {
placeholder="Confirm Password"
required
/>
<button type="submit">Register</button>

<div className='registration-form-buttons'>
{isDataLoading ? (
<Spinner />
) : (
<button type="submit">Register</button>
)}

<div className="registration-form-buttons">
<a className="nav-link" href="/">
Close
</a>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Spinner = () => {
return (
<div className="spinner-container" data-testid='spinner-container'>
<RotatingLines
strokeColor="green"
strokeColor="white"
strokeWidth="5"
animationDuration="0.75"
width="40"
Expand Down

1 comment on commit f960cc5

@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

97.96%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   App.tsx87.50%75%96%30–31, 40–41
   NoteApp.tsx94.44%100%96.99%70–74
src/api
   apiService.ts100%85.71%96.67%88–90
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.tsx86.67%100%97.04%57, 57–61
   RegistrationLink.tsx100%100%100%
   Spinner.tsx100%100%100%

Please sign in to comment.