Skip to content

Commit

Permalink
start using routes for team
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrees committed Jun 18, 2020
1 parent 42164b2 commit 76b0bb2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 28 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Hampton Council Planning</title>
<title>RIPA</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const InnerApp = () => {

const App = () => {
const currentUser = useStore(state => state.data.currentUser);
const team = getTeam("southwark");
localStorage.setItem("team", window.location.pathname.split("/")[1]);
const team = getTeam(localStorage.getItem("team"));

return (
<ApolloProvider client={gqlClient}>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ const Dashboard = ({ applications = [] }) => {
))}
<Grid item xs={12} sm={"auto"}>
<Box height={"100%"}>
<ButtonBase href="/start" className={classes.start}>
<ButtonBase
href={`/${localStorage.getItem("team")}/start`}
className={classes.start}
>
<Plus size={40} />
<Box pt={2} fontSize="h6.fontSize" px={3}>
Start a new application
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MyApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const MyApplication = ({ sections = [] }) => {
py={1.5}
>
<Link
href={`/start/${id}`}
href={`/${localStorage.getItem("team")}/start/${id}`}
prefetch={false}
className={classes.link}
>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ const Section = ({ id }) => {

return (
<HVCenterContainer light disableScroll>
<Link href="/start" className={classes.backLink}>
<Link
href={`${localStorage.getItem("team")}/start`}
className={classes.backLink}
>
<ArrowLeft /> Back
</Link>
<Typography variant="h3" component="h1" gutterBottom>
Expand Down
68 changes: 45 additions & 23 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { compose, lazy, map, mount, redirect, route, withView } from "navi";
import {
compose,
lazy,
map,
mount,
redirect,
route,
withData,
withView
} from "navi";
import * as React from "react";
import { NotFoundBoundary, View } from "react-navi";

Expand Down Expand Up @@ -33,40 +42,53 @@ const Layout = ({ currentUser, team }) => {
};

export default compose(
withView((req, context: IContext) => (
withView((_req, context: IContext) => (
<Layout currentUser={context.currentUser} team={context.team} />
)),

mount({
"/login": map(async (req, context: IContext) =>
context.currentUser
? redirect(
req.params.redirectTo
? decodeURIComponent(req.params.redirectTo)
: "/"
)
: route({
title: "Login",
view: <Login />
})
),
"/": redirect(`/${localStorage.getItem("team") || "opensystemslab"}`),

"/logout": map(async (req, context: IContext) => {
"/logout": map(() => {
// context.gqlClient.resetStore();
// localStorage.removeItem("token");
api.getState().set(state => {
state.data = {};
});
return redirect("/login");
return redirect(`/${localStorage.getItem("team")}/login`);
}),

"*": map(async (req, context: IContext) =>
context.currentUser
? lazy(() => import("./authenticated"))
: redirect(
`/login/?redirectTo=${encodeURIComponent(req.originalUrl)}`,
{ exact: false }
)
"/:team": compose(
withData(req => ({
team: req.params.team
})),

mount({
"/login": map(async (req, context: IContext) =>
context.currentUser
? redirect(
req.params.redirectTo
? decodeURIComponent(req.params.redirectTo)
: `/${req.params.team}`
)
: route({
title: "Login",
view: <Login />
})
),

"*": map(async (req, context: IContext) => {
console.log({ req });
return context.currentUser
? lazy(() => import("./authenticated"))
: (redirect(
`/${req.params.team}/login/?redirectTo=${encodeURIComponent(
req.originalUrl
)}`,
{ exact: false }
) as any);
})
})
)
})
);
7 changes: 7 additions & 0 deletions src/themes/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import ScotlandLogo from "./logos/Scotland.svg";
import SouthwarkLogo from "./logos/Southwark.svg";

const teams = {
opensystemslab: {
name: "Open Systems Lab",
logo: SouthwarkLogo,
theme: {
primary: "#000"
}
},
southwark: {
name: "Southwark",
logo: SouthwarkLogo,
Expand Down

0 comments on commit 76b0bb2

Please sign in to comment.