Add inactivity notices to mod queue dropdown

This commit is contained in:
regalijan 2023-10-19 16:50:50 -04:00
parent db7e9326ac
commit 8435cbdcb2
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -14,7 +14,7 @@ import {
useBreakpointValue, useBreakpointValue,
useDisclosure, useDisclosure,
useToast, useToast,
VStack, VStack
} from "@chakra-ui/react"; } from "@chakra-ui/react";
import { type ReactElement, useEffect, useState } from "react"; import { type ReactElement, useEffect, useState } from "react";
import AppealCard from "../../components/AppealCard.js"; import AppealCard from "../../components/AppealCard.js";
@ -31,38 +31,40 @@ export async function loader({ context }: { context: RequestContext }) {
if (!currentUser) if (!currentUser)
throw new Response(null, { throw new Response(null, {
status: 401, status: 401
}); });
const departments = { const departments = {
DM: 1 << 2, DM: 1 << 2,
ET: 1 << 3, ET: 1 << 3,
FM: 1 << 10, FM: 1 << 10,
WM: 1 << 9, WM: 1 << 9
}; };
const newItemPermissions = { const newItemPermissions = {
game_ban: [1 << 5], game_ban: [1 << 5],
inactivity: [1 << 2, 1 << 9, 1 << 10], inactivity: [1 << 2, 1 << 9, 1 << 10],
infraction: [1 << 0, 1 << 2, 1 << 6, 1 << 7], infraction: [1 << 0, 1 << 2, 1 << 6, 1 << 7]
}; };
const newItemNames: { [k: string]: string } = { const newItemNames: { [k: string]: string } = {
game_ban: "Game Ban", game_ban: "Game Ban",
inactivity: "Inactivity Notice", inactivity: "Inactivity Notice",
infraction: "Infraction", infraction: "Infraction"
}; };
const typePermissions = { const typePermissions = {
appeal: [1 << 0, 1 << 1], appeal: [1 << 0, 1 << 1],
gma: [1 << 5], gma: [1 << 5],
report: [1 << 5], inactivity: [1 << 4, 1 << 6, 1 << 7, 1 << 11, 1 << 12],
report: [1 << 5]
}; };
const typeNames: { [k: string]: string } = { const typeNames: { [k: string]: string } = {
appeal: "Discord Appeals", appeal: "Discord Appeals",
gma: "Game Appeals", gma: "Game Appeals",
report: "Game Reports", inactivity: "Inactivity Notices",
report: "Game Reports"
}; };
const allowedNewItems = []; const allowedNewItems = [];
@ -80,32 +82,32 @@ export async function loader({ context }: { context: RequestContext }) {
if (!allowedTypes.length) if (!allowedTypes.length)
throw new Response(null, { throw new Response(null, {
status: 403, status: 403
}); });
return { return {
can_edit_ban_users: [ can_edit_ban_users: [
"165594923586945025", "165594923586945025",
"289372404541554689", "289372404541554689",
"396347223736057866", "396347223736057866"
].includes(currentUser.id), ].includes(currentUser.id),
departments: Object.entries(departments) departments: Object.entries(departments)
.filter((d) => d[1] & currentUser.permissions) .filter((d) => d[1] & currentUser.permissions)
.map((arr) => arr[0]), .map((arr) => arr[0]),
entry_types: allowedTypes, entry_types: allowedTypes,
item_types: allowedNewItems, item_types: allowedNewItems
}; };
} }
export function meta() { export function meta() {
return [ return [
{ {
title: "Moderation Queue - Car Crushers", title: "Moderation Queue - Car Crushers"
}, }
]; ];
} }
export default function () { export default function() {
const pageProps = useLoaderData<typeof loader>(); const pageProps = useLoaderData<typeof loader>();
const isDesktop = useBreakpointValue({ base: false, lg: true }); const isDesktop = useBreakpointValue({ base: false, lg: true });
const entryTypes = []; const entryTypes = [];
@ -117,17 +119,17 @@ export default function () {
entryTypes.push( entryTypes.push(
<option key={type.value} value={type.value}> <option key={type.value} value={type.value}>
{type.name} {type.name}
</option>, </option>
); );
async function updateQueue( async function updateQueue(
queue_type: string, queue_type: string,
before: number, before: number,
show_closed = false, show_closed = false,
jump_item_to_top = false, jump_item_to_top = false
): Promise<void> { ): Promise<void> {
const queueReq = await fetch( const queueReq = await fetch(
`/api/mod-queue/list?before=${before}&showClosed=${show_closed}&type=${queue_type}`, `/api/mod-queue/list?before=${before}&showClosed=${show_closed}&type=${queue_type}`
); );
if (!queueReq.ok) { if (!queueReq.ok) {
@ -138,7 +140,7 @@ export default function () {
duration: 10000, duration: 10000,
isClosable: true, isClosable: true,
status: "error", status: "error",
title: "Failed to load queue", title: "Failed to load queue"
}); });
return; return;
@ -171,7 +173,7 @@ export default function () {
duration: 10000, duration: 10000,
isClosable: true, isClosable: true,
status: "error", status: "error",
title: ((await itemReq.json()) as { error: string }).error, title: ((await itemReq.json()) as { error: string }).error
}); });
} else { } else {
const itemData: { [k: string]: any } = await itemReq.json(); const itemData: { [k: string]: any } = await itemReq.json();
@ -213,7 +215,7 @@ export default function () {
case "inactivity": case "inactivity":
newEntries.push( newEntries.push(
<InactivityNoticeCard {...(entry as InactivityNoticeProps)} />, <InactivityNoticeCard {...(entry as InactivityNoticeProps)} />
); );
break; break;
@ -239,11 +241,11 @@ export default function () {
} = { } = {
game_ban: useDisclosure(), game_ban: useDisclosure(),
inactivity: useDisclosure(), inactivity: useDisclosure(),
infraction: useDisclosure(), infraction: useDisclosure()
}; };
useEffect(() => { useEffect(() => {
(async function () { (async function() {
await updateQueue(pageProps.entry_types[0].value, before, false, true); await updateQueue(pageProps.entry_types[0].value, before, false, true);
})(); })();
@ -284,7 +286,7 @@ export default function () {
await updateQueue( await updateQueue(
target.options[target.selectedIndex].value, target.options[target.selectedIndex].value,
Date.now(), Date.now()
); );
}} }}
> >
@ -309,7 +311,8 @@ export default function () {
fill="currentColor" fill="currentColor"
viewBox="0 0 16 16" viewBox="0 0 16 16"
> >
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z" /> <path
d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z" />
</svg> </svg>
</Button> </Button>
</PopoverTrigger> </PopoverTrigger>