aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/app/views/admin/Admin.tsx
blob: ac640700ddc4ca301508d6fc73cc10d71fcf5009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { Fragment } from "react";
import { Redirect, Route, Switch, useRouteMatch, match } from "react-router";
import { Container } from "react-bootstrap";

import { AuthUser } from "@/services/user";

import AdminNav from "./AdminNav";
import UserAdmin from "./UserAdmin";
import HighlightTimelineAdmin from "./HighlightTimelineAdmin";

interface AdminProps {
  user: AuthUser;
}

const Admin: React.FC<AdminProps> = ({ user }) => {
  const match = useRouteMatch();

  return (
    <Fragment>
      <Switch>
        <Redirect from={match.path} to={`${match.path}/users`} exact />
        <Route path={`${match.path}/:name`}>
          {(p) => {
            const match = p.match as match<{ name: string }>;
            const name = match.params["name"];
            return (
              <Container>
                <AdminNav />
                {(() => {
                  if (name === "users") {
                    return <UserAdmin user={user} />;
                  } else if (name === "highlighttimelines") {
                    return <HighlightTimelineAdmin user={user} />;
                  }
                })()}
              </Container>
            );
          }}
        </Route>
      </Switch>
    </Fragment>
  );
};

export default Admin;