From 045cb5ce83bbdca4e5f5e9e7bc6c394597889a55 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 19 Nov 2022 17:14:12 +0200 Subject: [PATCH] Preview maplist generator toggle for admins --- app/routes/to.$identifier.tsx | 5 ++++- app/routes/to.$identifier/index.tsx | 21 ++++++++++++++++++--- public/locales/en/tournament.json | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/routes/to.$identifier.tsx b/app/routes/to.$identifier.tsx index 9579481a5..3d91c2d57 100644 --- a/app/routes/to.$identifier.tsx +++ b/app/routes/to.$identifier.tsx @@ -53,7 +53,10 @@ export const loader = async ({ params, request }: LoaderArgs) => { event, tieBreakerMapPool: db.calendarEvents.findTieBreakerMapPoolByEventId(eventId), - teams: event.isBeforeStart ? censorMapPools({ teams }) : teams, + teams: + event.isBeforeStart && !canAdminCalendarTOTools({ user, event }) + ? censorMapPools({ teams }) + : teams, ownTeam: findOwnedTeam({ userId: user?.id, teams }), }; }; diff --git a/app/routes/to.$identifier/index.tsx b/app/routes/to.$identifier/index.tsx index 7fe7b54b1..de39dda57 100644 --- a/app/routes/to.$identifier/index.tsx +++ b/app/routes/to.$identifier/index.tsx @@ -15,7 +15,7 @@ import { MapPoolSelector } from "~/components/MapPoolSelector"; import { RequiredHiddenInput } from "~/components/RequiredHiddenInput"; import { TOURNAMENT } from "~/constants"; import { db } from "~/db"; -import { requireUser } from "~/modules/auth"; +import { requireUser, useUser } from "~/modules/auth"; import type { StageId } from "~/modules/in-game-lists"; import { rankedModesShort } from "~/modules/in-game-lists/modes"; import { MapPool } from "~/modules/map-pool-serializer"; @@ -44,6 +44,9 @@ import { UserCombobox } from "~/components/Combobox"; import { TeamWithRoster } from "./components/TeamWithRoster"; import { actualNumber } from "~/utils/zod"; import { useSearchParamState } from "~/hooks/useSearchParamState"; +import { canAdminCalendarTOTools } from "~/permissions"; +import { Toggle } from "~/components/Toggle"; +import { Label } from "~/components/Label"; export const links: LinksFunction = () => { return [{ rel: "stylesheet", href: mapsStyles }]; @@ -151,11 +154,23 @@ export const action: ActionFunction = async ({ request, params }) => { }; export default function TournamentToolsPage() { + const { t } = useTranslation(["tournament"]); + const user = useUser(); const data = useOutletContext(); + const [showGenerator, setShowGenerator] = React.useState( + !data.event.isBeforeStart + ); return ( -
- {data.event.isBeforeStart ? : } +
+ {canAdminCalendarTOTools({ user, event: data.event }) && + data.event.isBeforeStart ? ( +
+ + +
+ ) : null} +
{showGenerator ? : }
); } diff --git a/public/locales/en/tournament.json b/public/locales/en/tournament.json index 650e880cd..ac7560770 100644 --- a/public/locales/en/tournament.json +++ b/public/locales/en/tournament.json @@ -6,6 +6,7 @@ "pre.footerNote": "Note: you can change your map pool and roster as many times as you want before the tournament starts.", "pre.deleteTeam": "Delete team", + "preview": "Preview maplist generator (admin only)", "pre.steps.register": "1. Register on", "pre.steps.register.summary": "Enter team name you register with", "pre.steps.mapPool": "2. Map pool",