Skip to content

Commit 114f27d

Browse files
feat: add loading overlay with CircularProgress to sign-in page
Agent-Logs-Url: https://github.com/MobilityData/mobilitydatabase-web/sessions/34ee6340-1784-42b7-9c5b-b1d4d4113e00 Co-authored-by: Alessandro100 <18631060+Alessandro100@users.noreply.github.com>
1 parent fb2a01a commit 114f27d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/app/[locale]/sign-in/SignIn.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { useFormik } from 'formik';
3030
import * as Yup from 'yup';
3131
import {
3232
Alert,
33+
Backdrop,
34+
CircularProgress,
3335
Divider,
3436
IconButton,
3537
InputAdornment,
@@ -59,8 +61,11 @@ export default function SignIn(): React.ReactElement {
5961
const [isSubmitted, setIsSubmitted] = React.useState(false);
6062
const [showPassword, setShowPassword] = React.useState(false);
6163
const [showNoEmailSnackbar, setShowNoEmailSnackbar] = React.useState(false);
64+
const [isOAuthLoading, setIsOAuthLoading] = React.useState(false);
6265
const searchParams = useSearchParams();
6366

67+
const isLoading = userProfileStatus === 'login_in' || isOAuthLoading;
68+
6469
const SignInSchema = Yup.object().shape({
6570
email: Yup.string()
6671
.email('Email format is invalid.')
@@ -111,18 +116,22 @@ export default function SignIn(): React.ReactElement {
111116
const signInWithProvider = (oauthProvider: OauthProvider): void => {
112117
const auth = getAuth();
113118
const provider = oathProviders[oauthProvider];
119+
setIsOAuthLoading(true);
114120
signInWithPopup(auth, provider)
115121
.then((userCredential: UserCredential) => {
116122
if (!userCredential.user.emailVerified) {
117123
dispatch(verifyEmail());
118124
}
119125
if (userCredential.user.email == null) {
126+
setIsOAuthLoading(false);
120127
setShowNoEmailSnackbar(true);
121128
} else {
129+
setIsOAuthLoading(false);
122130
dispatch(loginWithProvider({ oauthProvider, userCredential }));
123131
}
124132
})
125133
.catch((error) => {
134+
setIsOAuthLoading(false);
126135
dispatch(
127136
loginFail({
128137
code: error.code,
@@ -135,6 +144,13 @@ export default function SignIn(): React.ReactElement {
135144

136145
return (
137146
<Container component='main' maxWidth='xs'>
147+
<Backdrop
148+
open={isLoading}
149+
sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }}
150+
data-testid='signin-loading-overlay'
151+
>
152+
<CircularProgress aria-label='Signing in...' />
153+
</Backdrop>
138154
<Snackbar
139155
open={showNoEmailSnackbar}
140156
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}

0 commit comments

Comments
 (0)