diff --git a/app/components/FormWithConfirm.tsx b/app/components/FormWithConfirm.tsx index c3317473b..2249e04df 100644 --- a/app/components/FormWithConfirm.tsx +++ b/app/components/FormWithConfirm.tsx @@ -1,4 +1,4 @@ -import { Form } from "@remix-run/react"; +import { Form, useFetcher } from "@remix-run/react"; import React from "react"; import invariant from "tiny-invariant"; import { useTranslation } from "~/hooks/useTranslation"; @@ -11,12 +11,15 @@ export function FormWithConfirm({ children, dialogHeading, deleteButtonText, + action, }: { fields?: [name: string, value: string | number][]; children: React.ReactNode; dialogHeading: string; deleteButtonText?: string; + action?: string; }) { + const fetcher = useFetcher(); const { t } = useTranslation(["common"]); const [dialogOpen, setDialogOpen] = React.useState(false); const formRef = React.useRef(null); @@ -29,11 +32,17 @@ export function FormWithConfirm({ return ( <> -
+ {fields?.map(([name, value]) => ( ))} - +

{dialogHeading}

diff --git a/app/db/models/calendar/deleteTournamentById.sql b/app/db/models/calendar/deleteTournamentById.sql new file mode 100644 index 000000000..9e626e78b --- /dev/null +++ b/app/db/models/calendar/deleteTournamentById.sql @@ -0,0 +1,4 @@ +delete from + "Tournament" +where + id = @id diff --git a/app/db/models/calendar/queries.server.ts b/app/db/models/calendar/queries.server.ts index ddf101b4f..8300dae01 100644 --- a/app/db/models/calendar/queries.server.ts +++ b/app/db/models/calendar/queries.server.ts @@ -41,6 +41,7 @@ import findAllEventsWithMapPoolsSql from "./findAllEventsWithMapPools.sql"; import findTieBreakerMapPoolByEventIdSql from "./findTieBreakerMapPoolByEventId.sql"; import deleteByIdSql from "./deleteById.sql"; import createTournamentSql from "./createTournament.sql"; +import deleteTournamentByIdSql from "./deleteTournamentById.sql"; const createStm = sql.prepare(createSql); const updateStm = sql.prepare(updateSql); @@ -58,6 +59,7 @@ const findTieBreakerMapPoolByEventIdtm = sql.prepare( findTieBreakerMapPoolByEventIdSql ); const deleteByIdStm = sql.prepare(deleteByIdSql); +const deleteTournamentByIdStm = sql.prepare(deleteTournamentByIdSql); const createTournamentStm = sql.prepare(createTournamentSql); const createTournament = ( @@ -512,6 +514,15 @@ export function findTieBreakerMapPoolByEventId( >; } -export function deleteById(id: CalendarEvent["id"]) { - return deleteByIdStm.run({ id }); -} +export const deleteById = sql.transaction( + ({ + eventId, + tournamentId, + }: { + eventId: number; + tournamentId: number | null; + }) => { + deleteByIdStm.run({ id: eventId }); + if (tournamentId) deleteTournamentByIdStm.run({ id: tournamentId }); + } +); diff --git a/app/features/tournament/routes/to.$id.admin.tsx b/app/features/tournament/routes/to.$id.admin.tsx index f6bda7e6e..cb4f765ae 100644 --- a/app/features/tournament/routes/to.$id.admin.tsx +++ b/app/features/tournament/routes/to.$id.admin.tsx @@ -30,8 +30,13 @@ import { joinTeam, leaveTeam } from "../queries/joinLeaveTeam.server"; import { TOURNAMENT } from "../tournament-constants"; import { deleteTeam } from "../queries/deleteTeam.server"; import { useUser } from "~/modules/auth"; -import { calendarEditPage, tournamentPage } from "~/utils/urls"; +import { + calendarEditPage, + calendarEventPage, + tournamentPage, +} from "~/utils/urls"; import { Redirect } from "~/components/Redirect"; +import { FormWithConfirm } from "~/components/FormWithConfirm"; export const action: ActionFunction = async ({ request, params }) => { const user = await requireUserId(request); @@ -138,7 +143,9 @@ export const action: ActionFunction = async ({ request, params }) => { return null; }; +// xxx: seed order for challonge download export default function TournamentAdminPage() { + const { t } = useTranslation(["calendar"]); const data = useOutletContext(); const user = useUser(); @@ -151,7 +158,7 @@ export default function TournamentAdminPage() { {isAdmin(user) ? : null} -
+
Edit event info + {!data.hasStarted ? ( + + + + ) : null}
); diff --git a/app/features/tournament/routes/to.$id.tsx b/app/features/tournament/routes/to.$id.tsx index 894032cbe..af34a2fcb 100644 --- a/app/features/tournament/routes/to.$id.tsx +++ b/app/features/tournament/routes/to.$id.tsx @@ -58,7 +58,7 @@ export const links: LinksFunction = () => { }; export const handle: SendouRouteHandle = { - i18n: ["tournament"], + i18n: ["tournament", "calendar"], }; export type TournamentLoaderTeam = Unpacked; diff --git a/app/routes/calendar/$id/index.tsx b/app/routes/calendar/$id/index.tsx index 940d47627..4069af5c5 100644 --- a/app/routes/calendar/$id/index.tsx +++ b/app/routes/calendar/$id/index.tsx @@ -69,7 +69,10 @@ export const action: ActionFunction = async ({ params, request }) => { }) ); - db.calendarEvents.deleteById(event.eventId); + db.calendarEvents.deleteById({ + eventId: event.eventId, + tournamentId: event.tournamentId, + }); return redirect(CALENDAR_PAGE); };