sendou.ink/pages/admin.tsx
Kalle 1589b84c4b
New layout (#427) closes #405
* side layout initial

* add elements to side nav

* side buttons links

* remove clog

* calendar page initial

* position sticky working

* x trends page initial

* new table

* same mode selector

* mobile friendly table

* no underline for nav links

* xsearch

* x trends page outlined

* sr initial

* relocate calendar components

* calendar fix flex

* topnav fancier look

* layout looking good edition

* relocate xtrends

* xtrends remove linecharts

* x trends new

* calender page new

* delete headbanner, new login

* remove calendar stuff from api

* rename stuff in utils

* fix user item margin

* new home page initial

* remove page concept

* no pointer xtrends

* remove xrank from app

* xtrends service

* move fa from app

* move plus

* maps tweaks

* new table for plus history

* navigational sidebar flex tweaks

* builds page

* analyzer

* user page

* free agents

* plans

* remove mx

* tweaks

* change layout to grid

* home page finalized

* mobile nav

* restrict main content width

* tweaks style

* language switcher

* container in css

* sticky nav

* use duplicate icons for now

* change mapsketch width to old

* chara tour vid

* borzoic icons
2021-04-21 17:26:50 +03:00

86 lines
2.2 KiB
TypeScript

import { Box, Button, Flex, Heading, Input, useToast } from "@chakra-ui/react";
import SubText from "components/common/SubText";
import { useUser } from "hooks/common";
import { useState } from "react";
import { ADMIN_DISCORD_ID } from "utils/constants";
import { getToastOptions } from "utils/objects";
import { sendData } from "utils/postData";
import { trpc } from "utils/trpc";
const AdminPage = () => {
const toast = useToast();
const [user] = useUser();
const [sending, setSending] = useState(false);
const [{ switchAccountId, discordId }, setUpdatePlayerIdForms] = useState({
switchAccountId: "",
discordId: "",
});
const endVoting = trpc.useMutation("plus.endVoting");
const handleEndVoting = () => {
if (!window.confirm("End voting?")) return;
endVoting.mutate(null);
};
if (!user || user.discordId !== ADMIN_DISCORD_ID) return null;
return (
<>
<Heading>Update player ID</Heading>
<Flex mb="1em">
<Box mr="1em">
<SubText>Switch account ID</SubText>
<Input
value={switchAccountId}
onChange={(e) =>
setUpdatePlayerIdForms({
discordId,
switchAccountId: e.target.value,
})
}
/>
</Box>
<Box>
<SubText>Discord ID</SubText>
<Input
value={discordId}
onChange={(e) =>
setUpdatePlayerIdForms({
switchAccountId,
discordId: e.target.value,
})
}
/>
</Box>
</Flex>
<Button isLoading={sending} onClick={updateUser}>
Submit
</Button>
<Heading my={4}>End voting</Heading>
<Button
isLoading={endVoting.status === "loading"}
onClick={handleEndVoting}
>
End
</Button>
</>
);
async function updateUser() {
if (!switchAccountId || !discordId) return;
setSending(true);
const success = await sendData("PATCH", `/api/users/${discordId}/player`, {
switchAccountId,
});
setSending(false);
if (!success) return;
toast(getToastOptions("User updated", "success"));
}
};
export default AdminPage;