Skip to content

Commit 6c0f192

Browse files
committed
Protect Organization creation route
1 parent 8f9d87e commit 6c0f192

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
import { useSelector, useDispatch } from "react-redux";
3+
import { Route, Redirect } from "react-router-dom";
4+
import CreateOrganization from "../../pages/createOrganization/createOrganization";
5+
import { getOrg } from "../../reducers/orgSlice";
6+
function OrganizationSetupRoute() {
7+
const dispatch = useDispatch();
8+
const orgExists = useSelector(state => state.org.get.org);
9+
if(Object.keys(orgExists).length == 0) {
10+
dispatch(getOrg());
11+
return null;
12+
}
13+
return (
14+
<Route
15+
render={() =>
16+
orgExists.exists ? <Redirect to="/" /> : <CreateOrganization />
17+
}
18+
/>
19+
);
20+
}
21+
22+
export default OrganizationSetupRoute;

src/reducers/orgSlice.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const getOrg = createAsyncThunk(
6161
isArchived
6262
isUnderMaintenance
6363
totalUsers
64+
exists
6465
}}`,
6566
},
6667
{

src/router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from "react";
22
import { BrowserRouter, Route, Switch } from "react-router-dom";
3-
import Dashboard from "./pages/dashboard/dashboard"
4-
import CreateOrganization from "./pages/createOrganization/createOrganization";
3+
import Dashboard from "./pages/dashboard/dashboard";
4+
import OrganizationSetupRoute from "./components/common/organizationSetupRoute";
55

66
const Router = () => (
77
<BrowserRouter>
88
<Switch>
99
<Route exact path="/" component={ Dashboard } />
10-
<Route path="/setup" component={ CreateOrganization } />
10+
<OrganizationSetupRoute path="/setup" />
1111
</Switch>
1212
</BrowserRouter>
1313
);

0 commit comments

Comments
 (0)