From 538c75b13a4e6b445a2cb2bc3d0a63c464273f08 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 14 Jun 2026 14:40:26 +0300 Subject: [PATCH] Fix saving team on tournament page not working --- app/components/StreamListItems.tsx | 4 +- .../tournament/actions/to.$id.info.server.ts | 50 +++++++++++++++++++ .../actions/to.$id.register.server.ts | 18 ------- .../components/TournamentHeader.tsx | 2 +- .../tournament/routes/to.$id.info.tsx | 3 +- .../tournament/tournament-schemas.server.ts | 15 +++--- 6 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 app/features/tournament/actions/to.$id.info.server.ts diff --git a/app/components/StreamListItems.tsx b/app/components/StreamListItems.tsx index 3bbe9a584..4fc3957d5 100644 --- a/app/components/StreamListItems.tsx +++ b/app/components/StreamListItems.tsx @@ -8,7 +8,7 @@ import { useDateTimeFormat } from "~/hooks/intl/useDateTimeFormat"; import { useFormatDistanceToNow } from "~/hooks/intl/useFormatDistanceToNow"; import { useHydrated } from "~/hooks/useHydrated"; import { databaseTimestampToDate } from "~/utils/dates"; -import { navIconUrl, tournamentRegisterPage } from "~/utils/urls"; +import { navIconUrl, tournamentInfoPage } from "~/utils/urls"; import { Image } from "./Image"; import { ListLink } from "./SideNav"; import styles from "./StreamListItems.module.css"; @@ -157,7 +157,7 @@ function SaveTournamentStreamButton({ return ( e.stopPropagation()} > { + const user = requireUser(); + const { id: tournamentId } = parseParams({ + params, + schema: idObject, + }); + + const data = await parseRequestPayload({ + request, + schema: saveTournamentSchema, + }); + + switch (data._action) { + case "SAVE_TOURNAMENT": { + const count = await SavedCalendarEventRepository.countByUserId(user.id); + errorToastIfFalsy( + count < TOURNAMENT.MAX_SAVED_COUNT, + "Maximum saved tournaments reached", + ); + + await SavedCalendarEventRepository.saveOwn(tournamentId); + break; + } + case "UNSAVE_TOURNAMENT": { + await SavedCalendarEventRepository.unsave({ + userId: user.id, + tournamentId, + }); + break; + } + default: { + assertUnreachable(data); + } + } + + return null; +}; diff --git a/app/features/tournament/actions/to.$id.register.server.ts b/app/features/tournament/actions/to.$id.register.server.ts index 2d065720d..6b45d7c47 100644 --- a/app/features/tournament/actions/to.$id.register.server.ts +++ b/app/features/tournament/actions/to.$id.register.server.ts @@ -18,7 +18,6 @@ import { logger } from "~/utils/logger"; import { errorToastIfFalsy, parseParams } from "~/utils/remix.server"; import { assertUnreachable } from "~/utils/types"; import { idObject } from "~/utils/zod"; -import { TOURNAMENT } from "../tournament-constants"; import { registerSchema } from "../tournament-schemas.server"; import { isOneModeTournamentOf, @@ -344,23 +343,6 @@ export const action: ActionFunction = async ({ request, params }) => { break; } - case "SAVE_TOURNAMENT": { - const count = await SavedCalendarEventRepository.countByUserId(user.id); - errorToastIfFalsy( - count < TOURNAMENT.MAX_SAVED_COUNT, - "Maximum saved tournaments reached", - ); - - await SavedCalendarEventRepository.saveOwn(tournamentId); - break; - } - case "UNSAVE_TOURNAMENT": { - await SavedCalendarEventRepository.unsave({ - userId: user.id, - tournamentId, - }); - break; - } default: { assertUnreachable(data); } diff --git a/app/features/tournament/components/TournamentHeader.tsx b/app/features/tournament/components/TournamentHeader.tsx index d9d5ba288..b427315e3 100644 --- a/app/features/tournament/components/TournamentHeader.tsx +++ b/app/features/tournament/components/TournamentHeader.tsx @@ -121,7 +121,7 @@ function SaveTournamentButton({ : isSaved; return ( - + = (args) => { const tournamentData = JSON.parse(args.matches[1].data as any)?.tournament as diff --git a/app/features/tournament/tournament-schemas.server.ts b/app/features/tournament/tournament-schemas.server.ts index dc4599627..cd191d0b2 100644 --- a/app/features/tournament/tournament-schemas.server.ts +++ b/app/features/tournament/tournament-schemas.server.ts @@ -36,15 +36,18 @@ export function registerSchema({ z.object({ _action: _action("UNREGISTER"), }), - z.object({ - _action: _action("SAVE_TOURNAMENT"), - }), - z.object({ - _action: _action("UNSAVE_TOURNAMENT"), - }), ]); } +export const saveTournamentSchema = z.union([ + z.object({ + _action: _action("SAVE_TOURNAMENT"), + }), + z.object({ + _action: _action("UNSAVE_TOURNAMENT"), + }), +]); + export const tournamentSearchSearchParamsSchema = z.object({ q: z.string().max(100), limit: z.coerce.number().int().min(1).max(25).catch(25),