mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-02 11:16:24 -05:00
71 lines
1.8 KiB
TypeScript
71 lines
1.8 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";
|
|
|
|
const AdminPage = () => {
|
|
const toast = useToast();
|
|
const [user] = useUser();
|
|
const [sending, setSending] = useState(false);
|
|
const [{ switchAccountId, discordId }, setUpdatePlayerIdForms] = useState({
|
|
switchAccountId: "",
|
|
discordId: "",
|
|
});
|
|
|
|
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>
|
|
</>
|
|
);
|
|
|
|
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;
|