blob: 9c0250e7cdeb1e2ce446e2930ace9952c0779b37 (
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
|
import React, { Fragment } from "react";
import {
Redirect,
Route,
Switch,
useRouteMatch,
useHistory,
} from "react-router";
import { Nav } from "react-bootstrap";
import { UserWithToken } from "@/services/user";
import UserAdmin from "./UserAdmin";
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}`}>
<div style={{ height: 56 }} className="flex-fix-length" />
<Nav variant="tabs">
<Nav.Item>
<Nav.Link
active={tabName === "users"}
onClick={() => {
toggle("users");
}}
>
Users
</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link
active={tabName === "more"}
onClick={() => {
toggle("more");
}}
>
More
</Nav.Link>
</Nav.Item>
</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;
|