diff --git a/ui/src/components/AppSwitchRoutes.tsx b/ui/src/components/AppSwitchRoutes.tsx index 4a27da32b..250ca108b 100644 --- a/ui/src/components/AppSwitchRoutes.tsx +++ b/ui/src/components/AppSwitchRoutes.tsx @@ -1,5 +1,5 @@ import React, {useCallback, useEffect, useState} from "react"; -import {Route, Routes, useNavigate} from "react-router-dom"; +import {Route, Routes, useLocation, useNavigate, useParams, useSearchParams} from "react-router-dom"; import {RouterRoutes} from "../helpers/routes"; import {useRecoilState} from "recoil"; import entPageAtom, {Page} from "../recoil/entPage"; @@ -22,6 +22,10 @@ const AppSwitchRoutes = () => { const [isLoading, setIsLoading] = useState(true); const [entPage, setEntPage] = useRecoilState(entPageAtom); const [isFirstLogin, setIsFirstLogin] = useState(false); + let {inviteToken} = useParams() + const location = useLocation(); + + const determinePage = useCallback(async () => { try { @@ -30,9 +34,11 @@ const AppSwitchRoutes = () => { setEntPage(Page.Setup); } else { const isAuthNeeded = await api.isAuthenticationNeeded(); - if(isAuthNeeded) { - setEntPage(Page.Login); + if(isAuthNeeded && inviteToken) { + setEntPage(Page.Setup) } + else if(isAuthNeeded) + setEntPage(Page.Login); } } catch (e) { toast.error("Error occured while checking Mizu API status, see console for mode details"); @@ -47,6 +53,10 @@ const AppSwitchRoutes = () => { }, [determinePage]); useEffect(() => { + if(!location.pathname || location.pathname !== '/') { + return; + } + switch (entPage) { case Page.Traffic: navigate("/"); @@ -60,8 +70,8 @@ const AppSwitchRoutes = () => { default: navigate(RouterRoutes.LOGIN); } - // eslint-disable-next-line - },[entPage]) + // eslint-disable-next-line + },[entPage, location]) if (isLoading) { @@ -71,11 +81,12 @@ const AppSwitchRoutes = () => { return }> } /> {/*todo: set settings component*/} - } /> + }/> + setIsFirstLogin(true)}/>}/> }/> - setIsFirstLogin(true)}/>}/> + } diff --git a/ui/src/components/Pages/AuthPage/InstallPage.tsx b/ui/src/components/Pages/AuthPage/InstallPage.tsx index f4936e401..e4fa7e82d 100644 --- a/ui/src/components/Pages/AuthPage/InstallPage.tsx +++ b/ui/src/components/Pages/AuthPage/InstallPage.tsx @@ -9,6 +9,8 @@ import {useSetRecoilState} from "recoil"; import entPageAtom, {Page} from "../../../recoil/entPage"; import useKeyPress from "../../../hooks/useKeyPress" import shortcutsKeyboard from "../../../configs/shortcutsKeyboard" +import { useNavigate, useParams } from "react-router-dom"; + const api = Api.getInstance(); @@ -24,7 +26,10 @@ export const InstallPage: React.FC = ({onFirstLogin}) => { const [isLoading, setIsLoading] = useState(false); const [password, setPassword] = useState(""); const [passwordConfirm, setPasswordConfirm] = useState(""); - + const {inviteToken} = useParams() + const navigate = useNavigate(); + + console.log("inviteToken : ",inviteToken) const setEntPage = useSetRecoilState(entPageAtom); const onFormSubmit = async () => { @@ -36,10 +41,22 @@ export const InstallPage: React.FC = ({onFirstLogin}) => { return; } + if(inviteToken){ + registerUser(async ()=> await api.recoverUser({password: password, inviteToken: inviteToken})) + } + else{ + registerUser(async () => await api.setupAdminUser(adminUsername, password)) + } + } + + const registerUser = async(registerFunc) => { try { - setIsLoading(true); - await api.setupAdminUser(adminUsername, password); + + setIsLoading(true); + await registerFunc(); + setEntPage(Page.Traffic); if (!await api.isAuthenticationNeeded()) { + navigate('/'); setEntPage(Page.Traffic); onFirstLogin(); } @@ -55,7 +72,6 @@ export const InstallPage: React.FC = ({onFirstLogin}) => { } finally { setIsLoading(false); } - } useKeyPress(shortcutsKeyboard.enter, onFormSubmit, formRef.current); @@ -63,11 +79,12 @@ export const InstallPage: React.FC = ({onFirstLogin}) => { return
{isLoading && }
Setup
- Welcome to Mizu, please set up the admin user to continue -
+ {inviteToken && you have been invited to join Mizu, please set password in order to complete the registration process} + {!inviteToken && Welcome to Mizu, please set up the admin user to continue} + {!inviteToken &&
-
+
}
setPassword(event.target.value)}/>