refactor: avoid repetition of the protected routes component
This commit is contained in:
1 parent
66dc6dbc1a
commit
a70e96f1f3
3 files changed
+26
-32
No files matched your search
@@ -15,7 +15,7 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
const ProtectedRoute = ({ Component, ...rest }) => {
|
const ProtectedRoute = ({ Component, ...rest }) => {
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
|
console.log("Protected");
|
||||||
return authState.authToken ? (
|
return authState.authToken ? (
|
||||||
<Component {...rest} />
|
<Component {...rest} />
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -367,6 +367,7 @@ StepTwo.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
|
console.log("login");
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
+24
-31
@@ -44,7 +44,7 @@ const Routes = () => {
|
|||||||
<LibRoutes>
|
<LibRoutes>
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/"
|
||||||
element={<HomeLayout />}
|
element={<ProtectedRoute Component={HomeLayout} />}
|
||||||
>
|
>
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/"
|
||||||
@@ -52,65 +52,65 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors"
|
path="/monitors"
|
||||||
element={<ProtectedRoute Component={MonitorsWithAdminProp} />}
|
element={<MonitorsWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors/create/:monitorId?"
|
path="/monitors/create/:monitorId?"
|
||||||
element={<ProtectedRoute Component={CreateMonitor} />}
|
element={<CreateMonitor />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors/:monitorId/"
|
path="/monitors/:monitorId/"
|
||||||
element={<ProtectedRoute Component={MonitorDetailsWithAdminProp} />}
|
element={<MonitorDetailsWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors/configure/:monitorId/"
|
path="/monitors/configure/:monitorId/"
|
||||||
element={<ProtectedRoute Component={Configure} />}
|
element={<Configure />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="pagespeed"
|
path="pagespeed"
|
||||||
element={<ProtectedRoute Component={PageSpeedWithAdminProp} />}
|
element={<PageSpeedWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="pagespeed/create"
|
path="pagespeed/create"
|
||||||
element={<ProtectedRoute Component={CreatePageSpeed} />}
|
element={<CreatePageSpeed />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="pagespeed/:monitorId"
|
path="pagespeed/:monitorId"
|
||||||
element={<ProtectedRoute Component={PageSpeedDetailsWithAdminProp} />}
|
element={<PageSpeedDetailsWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="pagespeed/configure/:monitorId"
|
path="pagespeed/configure/:monitorId"
|
||||||
element={<ProtectedRoute Component={PageSpeedConfigure} />}
|
element={<PageSpeedConfigure />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="infrastructure"
|
path="infrastructure"
|
||||||
element={<ProtectedRoute Component={Infrastructure} />}
|
element={<Infrastructure />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="infrastructure/create"
|
path="infrastructure/create"
|
||||||
element={<ProtectedRoute Component={CreateInfrastructureMonitor} />}
|
element={<CreateInfrastructureMonitor />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="infrastructure/:monitorId"
|
path="infrastructure/:monitorId"
|
||||||
element={<ProtectedRoute Component={InfrastructureDetailsWithAdminProp} />}
|
element={<InfrastructureDetailsWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="incidents/:monitorId?"
|
path="incidents/:monitorId?"
|
||||||
element={<ProtectedRoute Component={Incidents} />}
|
element={<Incidents />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="status"
|
path="status"
|
||||||
element={<ProtectedRoute Component={Status} />}
|
element={<Status />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="integrations"
|
path="integrations"
|
||||||
element={<ProtectedRoute Component={Integrations} />}
|
element={<Integrations />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="maintenance"
|
path="maintenance"
|
||||||
element={<ProtectedRoute Component={MaintenanceWithAdminProp} />}
|
element={<MaintenanceWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/maintenance/create/:maintenanceWindowId?"
|
path="/maintenance/create/:maintenanceWindowId?"
|
||||||
@@ -118,20 +118,15 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="settings"
|
path="settings"
|
||||||
element={<ProtectedRoute Component={SettingsWithAdminProp} />}
|
element={<SettingsWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="advanced-settings"
|
path="advanced-settings"
|
||||||
element={<ProtectedRoute Component={AdvancedSettingsWithAdminProp} />}
|
element={<AdvancedSettingsWithAdminProp />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="account/profile"
|
path="account/profile"
|
||||||
element={
|
element={<Account open={"profile"} />}
|
||||||
<ProtectedRoute
|
|
||||||
Component={Account}
|
|
||||||
open="profile"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="account/password"
|
path="account/password"
|
||||||
@@ -154,13 +149,11 @@ const Routes = () => {
|
|||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
exact
|
|
||||||
path="/login"
|
path="/login"
|
||||||
element={<Login />}
|
element={<Login />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
exact
|
|
||||||
path="/register"
|
path="/register"
|
||||||
element={<AdminCheckedRegister />}
|
element={<AdminCheckedRegister />}
|
||||||
/>
|
/>
|
||||||
@@ -171,11 +164,6 @@ const Routes = () => {
|
|||||||
element={<Register />}
|
element={<Register />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
|
||||||
path="*"
|
|
||||||
element={<NotFound />}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="/forgot-password"
|
path="/forgot-password"
|
||||||
element={<ForgotPassword />}
|
element={<ForgotPassword />}
|
||||||
@@ -192,6 +180,11 @@ const Routes = () => {
|
|||||||
path="/new-password-confirmed"
|
path="/new-password-confirmed"
|
||||||
element={<NewPasswordConfirmed />}
|
element={<NewPasswordConfirmed />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Route
|
||||||
|
path="*"
|
||||||
|
element={<NotFound />}
|
||||||
|
/>
|
||||||
</LibRoutes>
|
</LibRoutes>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user