diff --git a/client/src/components/auth-verifier/index.tsx b/client/src/components/auth-verifier/index.tsx index 9a6ce63de..d0dd2e9d6 100644 --- a/client/src/components/auth-verifier/index.tsx +++ b/client/src/components/auth-verifier/index.tsx @@ -11,9 +11,10 @@ import { useEffect, useState } from "react"; import { useAppSelector } from "@/hooks/AppHooks"; import type { ReactNode } from "react"; import { get } from "@/utils/ApiClient"; -import { useLocation } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; export const AuthVerifier = ({ children }: { children: ReactNode }) => { const location = useLocation(); + const navigate = useNavigate(); const isAuthRoute = ["/login", "/register"].includes(location.pathname) || location.pathname.startsWith("/recovery") || @@ -36,6 +37,11 @@ export const AuthVerifier = ({ children }: { children: ReactNode }) => { dispatch(setAuthenticated(true)); dispatch(setUser(user)); + if (user.teams.length === 0) { + navigate("/no-team"); + return; + } + if ( !selectedTeamId || !user.teams.find((t) => t.id === selectedTeamId) diff --git a/client/src/components/protected-route/index.tsx b/client/src/components/protected-route/index.tsx index fcea31f38..f9f4f732a 100644 --- a/client/src/components/protected-route/index.tsx +++ b/client/src/components/protected-route/index.tsx @@ -5,11 +5,15 @@ export const ProtectedRoute: React.FC = ({ children, }) => { const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated); - + const user = useAppSelector((state) => state.auth.user); if (!isAuthenticated) { return ; } + if (user?.teams.length === 0) { + return ; + } + if (!isAuthenticated) { return null; } diff --git a/client/src/pages/auth/Login.tsx b/client/src/pages/auth/Login.tsx index a8653ee8b..763d95b6e 100644 --- a/client/src/pages/auth/Login.tsx +++ b/client/src/pages/auth/Login.tsx @@ -62,6 +62,12 @@ const Login = () => { dispatch(setAuthenticated(true)); dispatch(setUser(user)); dispatch(setSelectedTeamId(user.teams[0]?.id || null)); + + if (user.teams.length === 0) { + navigate("/no-team"); + return; + } + navigate("/"); }; diff --git a/client/src/pages/errors/NoTeam.tsx b/client/src/pages/errors/NoTeam.tsx new file mode 100644 index 000000000..59fe45ec8 --- /dev/null +++ b/client/src/pages/errors/NoTeam.tsx @@ -0,0 +1,59 @@ +import Box from "@mui/material/Box"; +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { BaseBox } from "@/components/design-elements"; +import { Button } from "@/components/inputs"; + +import { useTheme } from "@mui/material/styles"; +import { useNavigate } from "react-router"; +import { useAppDispatch } from "@/hooks/AppHooks"; +import { usePost } from "@/hooks/UseApi"; + +const NoTeam = () => { + const dispatch = useAppDispatch(); + const theme = useTheme(); + const navigate = useNavigate(); + const { post } = usePost(); + + return ( + + + You don't belong to a team yet + + Please contact your administrator to be added to a team. + + + + + + + ); +}; + +export default NoTeam; diff --git a/client/src/pages/errors/NotFound.tsx b/client/src/pages/errors/NotFound.tsx new file mode 100644 index 000000000..7c733284e --- /dev/null +++ b/client/src/pages/errors/NotFound.tsx @@ -0,0 +1,5 @@ +const NotFound = () => { + return "Not Found, fail"; +}; + +export default NotFound; diff --git a/client/src/pages/teams/TeamMemberConfig.tsx b/client/src/pages/teams/TeamMemberConfig.tsx index 82b231f0c..42e1cb5e9 100644 --- a/client/src/pages/teams/TeamMemberConfig.tsx +++ b/client/src/pages/teams/TeamMemberConfig.tsx @@ -35,9 +35,11 @@ const TeamMemberConfig = () => { }; const handleConfirm = async () => { - await deleteFn(`/team-members/${id}`); - mutate("/teams/joined"); - navigate(-1); + const res = await deleteFn(`/team-members/${memberId}`); + if (res) { + mutate("/teams/joined"); + navigate(-1); + } setDialogOpen(false); }; diff --git a/client/src/pages/uptime/CheckTable.tsx b/client/src/pages/uptime/CheckTable.tsx index ee705a580..51864ec3b 100644 --- a/client/src/pages/uptime/CheckTable.tsx +++ b/client/src/pages/uptime/CheckTable.tsx @@ -18,7 +18,6 @@ const getHeaders = (t: Function, uiTimezone: string) => { id: "status", content: t("status"), render: (row) => { - console.log(row); return ; }, }, diff --git a/client/src/routes/Router.tsx b/client/src/routes/Router.tsx index 6a2dadabf..202dc2b02 100644 --- a/client/src/routes/Router.tsx +++ b/client/src/routes/Router.tsx @@ -47,6 +47,9 @@ import ProfilePage from "@/pages/profile/Profile"; import ExportPage from "@/pages/export/Export"; +import NoTeam from "@/pages/errors/NoTeam"; +import NotFound from "@/pages/errors/NotFound"; + import RootLayout from "@/components/layouts/RootLayout"; import { ProtectedRoute } from "@/components/protected-route"; @@ -137,6 +140,8 @@ const Router = () => { } /> } /> + } /> + } /> ); };