From d0fe4a7e5aee444aedf8e10f41268b4927d6102d Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:53:09 +0200 Subject: [PATCH] fix: registration success message and redirect logic --- api/server/controllers/AuthController.js | 3 --- client/src/components/Auth/Registration.tsx | 27 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api/server/controllers/AuthController.js b/api/server/controllers/AuthController.js index 4edf19eae18..881376453a4 100644 --- a/api/server/controllers/AuthController.js +++ b/api/server/controllers/AuthController.js @@ -135,9 +135,6 @@ module.exports = { refreshController, registrationController, resetPasswordController, -<<<<<<< HEAD resetPasswordRequestController, -======= verifyEmailController, ->>>>>>> ff99c713 (feat: verification email) }; diff --git a/client/src/components/Auth/Registration.tsx b/client/src/components/Auth/Registration.tsx index a69acd663a7..3a9238bcfb2 100644 --- a/client/src/components/Auth/Registration.tsx +++ b/client/src/components/Auth/Registration.tsx @@ -11,6 +11,7 @@ const Registration: React.FC = () => { const navigate = useNavigate(); const localize = useLocalize(); const { startupConfig, startupConfigError, isFetching } = useOutletContext(); + const [registrationSuccess, setRegistrationSuccess] = useState(false); const { register, @@ -21,13 +22,26 @@ const Registration: React.FC = () => { const [error, setError] = useState(false); const [errorMessage, setErrorMessage] = useState(''); + const [countdown, setCountdown] = useState(5); const registerUser = useRegisterUserMutation(); const password = watch('password'); const onRegisterUserFormSubmit = async (data: TRegisterUser) => { try { await registerUser.mutateAsync(data); - navigate('/c/new'); + if (startupConfig?.emailEnabled) { + setRegistrationSuccess(true); + + const timer = setInterval(() => { + setCountdown((prevCountdown) => prevCountdown - 1); + }, 1000); + setTimeout(() => { + clearInterval(timer); + navigate('/login', { replace: true }); + }, 5000); + } else { + navigate('/c/new'); + } } catch (error) { setError(true); if ((error as TError).response?.data?.message) { @@ -81,7 +95,16 @@ const Registration: React.FC = () => { {localize('com_auth_error_create')} {errorMessage} )} - + {registrationSuccess && countdown > 0 && ( +
+ {localize('com_auth_registration_success') + + ' ' + + localize('com_auth_email_verification_redirecting', countdown.toString())} +
+ )} {!startupConfigError && !isFetching && ( <>