Return user-facing name for queue types in page prop

This commit is contained in:
regalijan 2023-10-19 16:49:06 -04:00
parent 5d90d0b1b1
commit 1f7335f031
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -14,6 +14,13 @@ export async function onBeforeRender(pageContext: PageContext) {
gma: [1 << 5], gma: [1 << 5],
report: [1 << 5], report: [1 << 5],
}; };
const typeNames: { [k: string]: string } = {
appeal: "Discord Appeals",
gma: "Game Appeals",
report: "Game Reports",
};
const { searchParams } = new URL( const { searchParams } = new URL(
pageContext.urlOriginal, pageContext.urlOriginal,
"http://localhost:8788" "http://localhost:8788"
@ -22,13 +29,14 @@ export async function onBeforeRender(pageContext: PageContext) {
const allowedTypes = []; const allowedTypes = [];
for (const [type, ints] of Object.entries(typePermissions)) { for (const [type, ints] of Object.entries(typePermissions)) {
if (ints.find((i) => currentUser.permissions & i)) allowedTypes.push(type); if (ints.find((i) => currentUser.permissions & i))
allowedTypes.push({ name: typeNames[type], value: type });
} }
if (!allowedTypes.length) if (!allowedTypes.length)
return { return {
pageContext: { pageContext: {
allowedTypes, entry_types: [],
}, },
status: 403, status: 403,
}; };
@ -40,7 +48,7 @@ export async function onBeforeRender(pageContext: PageContext) {
return { return {
pageContext: { pageContext: {
pageProps: { pageProps: {
allowedTypes, entry_types: allowedTypes,
}, },
}, },
}; };