From f3abbfedf74a1c271ca8405c47b8848677b526fe Mon Sep 17 00:00:00 2001 From: Lee Wei Jie Date: Sun, 25 Aug 2024 20:13:33 +0800 Subject: [PATCH] Updated: -Logout Behaviour -PW reset popup message -Text for pw reset button --- src/main/resources/.h2.server.properties | 2 +- .../finish/password-reset-finish.tsx | 2 +- .../password-reset/password-reset.reducer.ts | 7 ++- src/main/webapp/app/modules/login/logout.tsx | 48 +++++++++++++++---- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/main/resources/.h2.server.properties b/src/main/resources/.h2.server.properties index ab7b519..5722fe4 100644 --- a/src/main/resources/.h2.server.properties +++ b/src/main/resources/.h2.server.properties @@ -1,5 +1,5 @@ #H2 Server Properties -#Sun Aug 18 23:12:35 SGT 2024 +#Sun Aug 25 19:54:40 SGT 2024 0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/scaleup|scaleup webAllowOthers=true webPort=8092 diff --git a/src/main/webapp/app/modules/account/password-reset/finish/password-reset-finish.tsx b/src/main/webapp/app/modules/account/password-reset/finish/password-reset-finish.tsx index 55d2ce7..fe08bd2 100644 --- a/src/main/webapp/app/modules/account/password-reset/finish/password-reset-finish.tsx +++ b/src/main/webapp/app/modules/account/password-reset/finish/password-reset-finish.tsx @@ -58,7 +58,7 @@ export const PasswordResetFinishPage = () => { data-cy="confirmResetPassword" /> ); diff --git a/src/main/webapp/app/modules/account/password-reset/password-reset.reducer.ts b/src/main/webapp/app/modules/account/password-reset/password-reset.reducer.ts index 5d44601..d7374b0 100644 --- a/src/main/webapp/app/modules/account/password-reset/password-reset.reducer.ts +++ b/src/main/webapp/app/modules/account/password-reset/password-reset.reducer.ts @@ -47,12 +47,17 @@ export const PasswordResetSlice = createSlice({ .addCase(handlePasswordResetFinish.fulfilled, () => ({ ...initialState, loading: false, + //password reset state set to success resetPasswordSuccess: true, - successMessage: "Your password couldn't be reset. Remember a password request is only valid for 24 hours.", + //successMessage: "Your password couldn't be reset. Remember a password request is only valid for 24 hours.", + //scrape 24h thinggy? since cant demo + successMessage: 'Your password reset have been completed successfully', })) .addMatcher(isPending(handlePasswordResetInit, handlePasswordResetFinish), state => { state.loading = true; }) + //A matcher function to handle actions that have been rejected + //resets the state to initialState, sets loading to false, and marks the operation as failed with a relevant flag (resetPasswordFailure) .addMatcher(isRejected(handlePasswordResetInit, handlePasswordResetFinish), () => ({ ...initialState, loading: false, diff --git a/src/main/webapp/app/modules/login/logout.tsx b/src/main/webapp/app/modules/login/logout.tsx index 750add9..a388a12 100644 --- a/src/main/webapp/app/modules/login/logout.tsx +++ b/src/main/webapp/app/modules/login/logout.tsx @@ -1,20 +1,50 @@ -import React, { useLayoutEffect } from 'react'; +import React, { useLayoutEffect, useState, useEffect } from 'react'; import { useAppDispatch, useAppSelector } from 'app/config/store'; import { logout } from 'app/shared/reducers/authentication'; +// export const Logout = () => { +// const authentication = useAppSelector(state => state.authentication); +// const dispatch = useAppDispatch(); + +// useLayoutEffect(() => { +// dispatch(logout()); +// if (authentication.logoutUrl) { +// window.location.href = authentication.logoutUrl; +// } else if (!authentication.isAuthenticated) { +// window.location.href = '/'; +// } +// }); + +// return ( +//
+//

Logged out successfully!

+//
+// ); +// }; + export const Logout = () => { + const [isRedirecting, setIsRedirecting] = useState(false); const authentication = useAppSelector(state => state.authentication); const dispatch = useAppDispatch(); - useLayoutEffect(() => { - dispatch(logout()); - if (authentication.logoutUrl) { - window.location.href = authentication.logoutUrl; - } else if (!authentication.isAuthenticated) { - window.location.href = '/'; - } - }); + useEffect(() => { + const performLogout = async () => { + dispatch(logout()); + setIsRedirecting(true); // Set flag to indicate redirection in progress + + // Introduce a delay to handle the error boundary clean-up + await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay as needed + + if (authentication.logoutUrl) { + window.location.href = authentication.logoutUrl; + } else if (!authentication.isAuthenticated) { + window.location.href = '/'; + } + }; + + performLogout(); + }, [dispatch, authentication]); return (