Skip to content

Commit

Permalink
admin actions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed Feb 7, 2024
1 parent 21fb8bf commit 3f396be
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/admin/ban-account.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation BanAccount($id: ID!) {
banAccount(id: $id) {
success
account {
id
banned
}
}
}
37 changes: 37 additions & 0 deletions src/admin/ban-toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";

import FormGroup from "@mui/material/FormGroup";
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";

import {
useBanAccountMutation,
useUnbanAccountMutation,
BaseAccount,
} from "src/generated/graphql";

export function BanToggle({
account,
}: {
account: Omit<BaseAccount, "password">;
}): JSX.Element {
const [banAccount] = useBanAccountMutation();
const [unbanAccount] = useUnbanAccountMutation();

function toggleBan() {
if (account.banned) {
unbanAccount({ variables: { id: account.id } });
} else {
banAccount({ variables: { id: account.id } });
}
}

return (
<FormGroup>
<FormControlLabel
control={<Switch checked={account.banned} onChange={toggleBan} />}
label={account.banned ? "Currently Banned" : "Not Banned"}
/>
</FormGroup>
);
}
5 changes: 5 additions & 0 deletions src/admin/delete-account.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation DeleteAccount($id: ID!) {
deleteAccount(id: $id) {
success
}
}
44 changes: 44 additions & 0 deletions src/admin/delete-account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState } from "react";

import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import FormGroup from "@mui/material/FormGroup";
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";

import { useDeleteAccountMutation, BaseAccount } from "src/generated/graphql";

export function DeleteAccount({
account,
}: {
account: Omit<BaseAccount, "password">;
}): JSX.Element {
const [deleteAccountMutation] = useDeleteAccountMutation();
const [isArmed, setIsArmed] = useState<boolean>(false);

function deleteAccount() {
deleteAccountMutation({ variables: { id: account.id } });
}

return (
<Box>
<br />
<FormGroup>
<FormControlLabel
disabled={!account.banned}
control={
<Switch checked={isArmed} onChange={() => setIsArmed(!isArmed)} />
}
label={
account.banned
? "Allow Account Deletion"
: "Must Be Banned to Delete"
}
/>
</FormGroup>
<Button disabled={!isArmed} onClick={deleteAccount}>
Delete This Account
</Button>
</Box>
);
}
4 changes: 4 additions & 0 deletions src/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { CreateItem } from "./create-item";
import { GiveGold } from "./give-gold";
import { SetSkill } from "./set-skill";
import { AddLevels } from "./add-levels";
import { BanToggle } from "./ban-toggle";
import { DeleteAccount } from "./delete-account";

export default function AdminPage(): JSX.Element {
const [showData, setShowData] = useState<boolean>(false);
Expand Down Expand Up @@ -65,6 +67,8 @@ export default function AdminPage(): JSX.Element {
{account && <GiveGold account={account} />}
{account?.hero && <SetSkill hero={account.hero} />}
{account && <AddLevels account={account} />}
{account && <BanToggle account={account} />}
{account && <DeleteAccount account={account} />}
<br />
<br />
<br />
Expand Down
9 changes: 9 additions & 0 deletions src/admin/unban-account.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation UnbanAccount($id: ID!) {
unbanAccount(id: $id) {
success
account {
id
banned
}
}
}

0 comments on commit 3f396be

Please sign in to comment.