blob: 2f8b2c05d8e9d06ba518c8931f7620732ba3f63c (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
import React, { Fragment } from "react";
import { Nav, NavItem, NavLink } from "reactstrap";
import {
Redirect,
Route,
Switch,
useRouteMatch,
useHistory,
} from "react-router";
import classnames from "classnames";
import AppBar from "../common/AppBar";
import UserAdmin from "./UserAdmin";
import { UserWithToken } from "../data/user";
interface AdminProps {
user: UserWithToken;
}
const Admin: React.FC<AdminProps> = (props) => {
const match = useRouteMatch();
const history = useHistory();
type TabNames = "users" | "more";
const tabName = history.location.pathname.replace(match.path + "/", "");
function toggle(newTab: TabNames): void {
history.push(`${match.url}/${newTab}`);
}
const createRoute = (
name: string,
body: React.ReactNode
): React.ReactNode => {
return (
<Route path={`${match.path}/${name}`}>
<AppBar />
<div style={{ height: 56 }} className="flex-fix-length" />
<Nav tabs>
<NavItem>
<NavLink
className={classnames({ active: tabName === "users" })}
onClick={() => {
toggle("users");
}}
>
Users
</NavLink>
</NavItem>
<NavItem>
<NavLink
className={classnames({ active: tabName === "more" })}
onClick={() => {
toggle("more");
}}
>
More
</NavLink>
</NavItem>
</Nav>
{body}
</Route>
);
};
return (
<Fragment>
<Switch>
<Redirect from={match.path} to={`${match.path}/users`} exact />
{createRoute("users", <UserAdmin user={props.user} />)}
{createRoute("more", <div>More Page Works</div>)}
</Switch>
</Fragment>
);
};
export default Admin;
|