revite/src/pages/settings/ServerSettings.tsx

151 lines
5.4 KiB
TypeScript
Raw Normal View History

import { ListUl } from "@styled-icons/boxicons-regular";
import {
InfoCircle,
Group,
FlagAlt,
Envelope,
UserX,
Trash,
} from "@styled-icons/boxicons-solid";
import { observer } from "mobx-react-lite";
2021-08-05 09:47:00 -04:00
import { Route, Switch, useHistory, useParams } from "react-router-dom";
2021-07-05 06:23:23 -04:00
import styles from "./Settings.module.scss";
2021-07-05 06:23:23 -04:00
import { Text } from "preact-i18n";
import { useIntermediate } from "../../context/intermediate/Intermediate";
2021-06-19 17:37:12 -04:00
import RequiresOnline from "../../context/revoltjs/RequiresOnline";
import { useClient } from "../../context/revoltjs/RevoltClient";
2021-06-19 17:37:12 -04:00
2021-07-05 06:23:23 -04:00
import Category from "../../components/ui/Category";
import LineDivider from "../../components/ui/LineDivider";
2021-07-05 06:23:23 -04:00
import ButtonItem from "../../components/navigation/items/ButtonItem";
2021-07-05 06:23:23 -04:00
import { GenericSettings } from "./GenericSettings";
2021-06-19 17:37:12 -04:00
import { Bans } from "./server/Bans";
2021-07-24 14:39:41 -04:00
import { Categories } from "./server/Categories";
2021-07-05 06:23:23 -04:00
import { Invites } from "./server/Invites";
import { Members } from "./server/Members";
import { Overview } from "./server/Overview";
2021-06-30 16:28:56 -04:00
import { Roles } from "./server/Roles";
2021-06-19 17:37:12 -04:00
export default observer(() => {
const { openScreen } = useIntermediate();
2021-07-05 06:25:20 -04:00
const { server: sid } = useParams<{ server: string }>();
const client = useClient();
const server = client.servers.get(sid);
2021-07-05 06:25:20 -04:00
if (!server) return null;
2021-06-19 17:37:12 -04:00
const owner = server.owner === client.user?._id;
2021-07-05 06:25:20 -04:00
const history = useHistory();
function switchPage(to?: string) {
if (to) {
history.replace(`/server/${sid}/settings/${to}`);
} else {
history.replace(`/server/${sid}/settings`);
}
}
2021-06-19 17:37:12 -04:00
2021-07-05 06:25:20 -04:00
return (
<GenericSettings
pages={[
{
category: <Category variant="uniform" text={server.name} />,
2021-07-05 06:25:20 -04:00
id: "overview",
icon: <InfoCircle size={20} />,
2021-07-05 06:25:20 -04:00
title: (
<Text id="app.settings.server_pages.overview.title" />
),
},
2021-07-24 14:39:41 -04:00
{
id: "categories",
icon: <ListUl size={20} />,
2021-07-24 14:39:41 -04:00
title: (
<Text id="app.settings.server_pages.categories.title" />
),
hideTitle: true,
2021-07-24 14:39:41 -04:00
},
2021-07-05 06:25:20 -04:00
{
id: "members",
icon: <Group size={20} />,
title: (
<Text id="app.settings.server_pages.members.title" />
),
},
{
id: "invites",
icon: <Envelope size={20} />,
2021-07-05 06:25:20 -04:00
title: (
<Text id="app.settings.server_pages.invites.title" />
),
},
{
id: "bans",
icon: <UserX size={20} />,
2021-07-05 06:25:20 -04:00
title: <Text id="app.settings.server_pages.bans.title" />,
},
{
id: "roles",
icon: <FlagAlt size={20} />,
2021-07-05 06:25:20 -04:00
title: <Text id="app.settings.server_pages.roles.title" />,
hideTitle: true,
},
]}
2021-08-05 09:47:00 -04:00
children={
<Switch>
<Route path="/server/:server/settings/categories">
<Categories server={server} />
</Route>
<Route path="/server/:server/settings/members">
<RequiresOnline>
<Members server={server} />
</RequiresOnline>
</Route>
<Route path="/server/:server/settings/invites">
<RequiresOnline>
<Invites server={server} />
</RequiresOnline>
</Route>
<Route path="/server/:server/settings/bans">
<RequiresOnline>
<Bans server={server} />
</RequiresOnline>
</Route>
<Route path="/server/:server/settings/roles">
<RequiresOnline>
<Roles server={server} />
</RequiresOnline>
</Route>
<Route>
<Overview server={server} />
</Route>
</Switch>
}
2021-07-05 06:25:20 -04:00
category="server_pages"
switchPage={switchPage}
defaultPage="overview"
custom={
owner ? (
<>
<LineDivider />
<ButtonItem
onClick={() =>
openScreen({
id: "special_prompt",
type: "delete_server",
target: server,
})
}
className={styles.deleteServer}
compact>
<Trash size={20} />
<Text id="app.context_menu.delete_server" />
</ButtonItem>
</>
) : undefined
}
2021-07-05 06:25:20 -04:00
showExitButton
/>
);
});