refactor: avoid repetition of the protected routes component

This commit is contained in:
Caio Cabral committed 2024-12-12 08:24:10 -05:00
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 authState = useSelector((state) => state.auth);
console.log("Protected");
return authState.authToken ? (
<Component {...rest} />
) : (
+1
View File
@@ -367,6 +367,7 @@ StepTwo.propTypes = {
};
const Login = () => {
console.log("login");
const dispatch = useDispatch();
const navigate = useNavigate();
const theme = useTheme();
+24 -31
View File
@@ -44,7 +44,7 @@ const Routes = () => {
<LibRoutes>
<Route
path="/"
element={<HomeLayout />}
element={<ProtectedRoute Component={HomeLayout} />}
>
<Route
path="/"
@@ -52,65 +52,65 @@ const Routes = () => {
/>
<Route
path="/monitors"
element={<ProtectedRoute Component={MonitorsWithAdminProp} />}
element={<MonitorsWithAdminProp />}
/>
<Route
path="/monitors/create/:monitorId?"
element={<ProtectedRoute Component={CreateMonitor} />}
element={<CreateMonitor />}
/>
<Route
path="/monitors/:monitorId/"
element={<ProtectedRoute Component={MonitorDetailsWithAdminProp} />}
element={<MonitorDetailsWithAdminProp />}
/>
<Route
path="/monitors/configure/:monitorId/"
element={<ProtectedRoute Component={Configure} />}
element={<Configure />}
/>
<Route
path="pagespeed"
element={<ProtectedRoute Component={PageSpeedWithAdminProp} />}
element={<PageSpeedWithAdminProp />}
/>
<Route
path="pagespeed/create"
element={<ProtectedRoute Component={CreatePageSpeed} />}
element={<CreatePageSpeed />}
/>
<Route
path="pagespeed/:monitorId"
element={<ProtectedRoute Component={PageSpeedDetailsWithAdminProp} />}
element={<PageSpeedDetailsWithAdminProp />}
/>
<Route
path="pagespeed/configure/:monitorId"
element={<ProtectedRoute Component={PageSpeedConfigure} />}
element={<PageSpeedConfigure />}
/>
<Route
path="infrastructure"
element={<ProtectedRoute Component={Infrastructure} />}
element={<Infrastructure />}
/>
<Route
path="infrastructure/create"
element={<ProtectedRoute Component={CreateInfrastructureMonitor} />}
element={<CreateInfrastructureMonitor />}
/>
<Route
path="infrastructure/:monitorId"
element={<ProtectedRoute Component={InfrastructureDetailsWithAdminProp} />}
element={<InfrastructureDetailsWithAdminProp />}
/>
<Route
path="incidents/:monitorId?"
element={<ProtectedRoute Component={Incidents} />}
element={<Incidents />}
/>
<Route
path="status"
element={<ProtectedRoute Component={Status} />}
element={<Status />}
/>
<Route
path="integrations"
element={<ProtectedRoute Component={Integrations} />}
element={<Integrations />}
/>
<Route
path="maintenance"
element={<ProtectedRoute Component={MaintenanceWithAdminProp} />}
element={<MaintenanceWithAdminProp />}
/>
<Route
path="/maintenance/create/:maintenanceWindowId?"
@@ -118,20 +118,15 @@ const Routes = () => {
/>
<Route
path="settings"
element={<ProtectedRoute Component={SettingsWithAdminProp} />}
element={<SettingsWithAdminProp />}
/>
<Route
path="advanced-settings"
element={<ProtectedRoute Component={AdvancedSettingsWithAdminProp} />}
element={<AdvancedSettingsWithAdminProp />}
/>
<Route
path="account/profile"
element={
<ProtectedRoute
Component={Account}
open="profile"
/>
}
element={<Account open={"profile"} />}
/>
<Route
path="account/password"
@@ -154,13 +149,11 @@ const Routes = () => {
</Route>
<Route
exact
path="/login"
element={<Login />}
/>
<Route
exact
path="/register"
element={<AdminCheckedRegister />}
/>
@@ -171,11 +164,6 @@ const Routes = () => {
element={<Register />}
/>
<Route
path="*"
element={<NotFound />}
/>
<Route
path="/forgot-password"
element={<ForgotPassword />}
@@ -192,6 +180,11 @@ const Routes = () => {
path="/new-password-confirmed"
element={<NewPasswordConfirmed />}
/>
<Route
path="*"
element={<NotFound />}
/>
</LibRoutes>
);
};