From e4c8d716f0f4189eb17ac5c6ffd826f07cfd3acc Mon Sep 17 00:00:00 2001 From: Erik Vroon Date: Fri, 19 May 2023 15:44:14 +0200 Subject: [PATCH] Add stages modal (#217) --- backend/bracket/routes/stages.py | 2 +- .../src/components/modals/stage_modal.tsx | 73 +++++++ .../components/modals/tournament_modal.tsx | 190 +++++++++++------- frontend/src/components/tables/stages.tsx | 54 +++++ frontend/src/components/tables/table.tsx | 8 +- frontend/src/components/utils/util.tsx | 4 + frontend/src/interfaces/stage.tsx | 1 - frontend/src/pages/tournaments/[id].tsx | 7 + frontend/src/services/stage.tsx | 13 ++ 9 files changed, 270 insertions(+), 82 deletions(-) create mode 100644 frontend/src/components/modals/stage_modal.tsx create mode 100644 frontend/src/components/tables/stages.tsx create mode 100644 frontend/src/services/stage.tsx diff --git a/backend/bracket/routes/stages.py b/backend/bracket/routes/stages.py index 85d4701e..e8a83f97 100644 --- a/backend/bracket/routes/stages.py +++ b/backend/bracket/routes/stages.py @@ -49,7 +49,7 @@ async def delete_stage( if len(stage.rounds) > 0: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail="Round contains matches, delete those first", + detail="Stage contains rounds, please delete those first", ) await sql_delete_stage(tournament_id, stage_id) diff --git a/frontend/src/components/modals/stage_modal.tsx b/frontend/src/components/modals/stage_modal.tsx new file mode 100644 index 00000000..0e1cf36d --- /dev/null +++ b/frontend/src/components/modals/stage_modal.tsx @@ -0,0 +1,73 @@ +import { Button, Divider, Modal, Select } from '@mantine/core'; +import { useForm } from '@mantine/form'; +import { BiTrophy } from '@react-icons/all-files/bi/BiTrophy'; +import { useState } from 'react'; +import { SWRResponse } from 'swr'; + +import { Tournament } from '../../interfaces/tournament'; +import { createStage } from '../../services/stage'; +import StagesTable from '../tables/stages'; + +function CreateStageForm( + tournament: Tournament, + swrClubsResponse: SWRResponse, + setOpened: (value: ((prevState: boolean) => boolean) | boolean) => void +) { + const form = useForm({ + initialValues: { type: 'ROUND_ROBIN' }, + validate: {}, + }); + + return ( +
{ + await createStage(tournament.id, values.type); + await swrClubsResponse.mutate(null); + })} + > + +
Add Stage
+ ({ value: `${p.id}`, label: p.name }))} + label="Club" + placeholder="Pick a club for this tournament" + searchable + limit={20} + style={{ marginTop: 10 }} + {...form.getInputProps('club_id')} + /> + + + + {tournament != null ? : null} + + + + + {tournament != null ? ( + + {({ copied, copy }) => ( + + )} + + ) : null} + + ); +} + export default function TournamentModal({ tournament, swrTournamentsResponse, @@ -53,82 +162,17 @@ export default function TournamentModal({ const swrClubsResponse: SWRResponse = getClubs(); const clubs: Club[] = swrClubsResponse.data != null ? swrClubsResponse.data.data : []; - const form = useForm({ - initialValues: { - name: tournament == null ? '' : tournament.name, - club_id: tournament == null ? null : `${tournament.club_id}`, - dashboard_public: tournament == null ? true : tournament.dashboard_public, - players_can_be_in_multiple_teams: - tournament == null ? true : tournament.players_can_be_in_multiple_teams, - }, - - validate: { - name: (value) => (value.length > 0 ? null : 'Name too short'), - club_id: (value) => (value != null ? null : 'Please choose a club'), - }, - }); - return ( <> setOpened(false)} title={operation_text}> -
{ - assert(values.club_id != null); - if (is_create_form) { - await createTournament( - parseInt(values.club_id, 10), - values.name, - values.dashboard_public, - values.players_can_be_in_multiple_teams - ); - } else { - await updateTournament( - tournament.id, - values.name, - values.dashboard_public, - values.players_can_be_in_multiple_teams - ); - } - await swrTournamentsResponse.mutate(null); - setOpened(false); - })} - > - - -