From 722bbccc211b8d21158096ad4af091b9238b4029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vikt=C3=B3ria=20Brezinov=C3=A1?= <52294703+vikibrezinova@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:08:31 +0100 Subject: [PATCH] Buttons for freezing series and semester (#393) * add button for freezing series and semester * fix eslint * Freeze semester and series error handling --------- Co-authored-by: Michal Masrna --- .../SemesterAdministration.tsx | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 73c68af8..c4f27e57 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -1,11 +1,11 @@ import {Stack, Typography} from '@mui/material' import {useQuery} from '@tanstack/react-query' -import axios from 'axios' +import axios, {AxiosError} from 'axios' import {FC, useState} from 'react' import {Button} from '@/components/Clickable/Button' import {Link} from '@/components/Clickable/Link' -import {SemesterWithProblems} from '@/types/api/generated/competition' +import {SemesterWithProblems, SeriesWithProblems} from '@/types/api/generated/competition' import {formatDateTime} from '@/utils/formatDate' import {useDataFromURL} from '@/utils/useDataFromURL' import {useHasPermissions} from '@/utils/useHasPermissions' @@ -84,6 +84,35 @@ export const SemesterAdministration: FC = () => { ) } + const [semesterFreezeError, setSemesterFreezeError] = useState() + const [seriesFreezeError, setSeriesFreezeError] = useState() + + const freezeSemester = async (semester: SemesterWithProblems) => { + setSemesterFreezeError('') + try { + await axios.post(`/api/competition/semester/${semester.id}/results/freeze`) + } catch (error: unknown) { + if (error instanceof AxiosError) { + setSemesterFreezeError(error.response?.data.detail) + } else { + setSemesterFreezeError('Nastala neznáma chyba.') + } + } + } + + const freezeSeries = async (series: SeriesWithProblems) => { + setSeriesFreezeError('') + try { + await axios.post(`/api/competition/series/${series.id}/results/freeze`) + } catch (error: unknown) { + if (error instanceof AxiosError) { + setSeriesFreezeError(error.response?.data.detail) + } else { + setSeriesFreezeError('Nastala neznáma chyba.') + } + } + } + if ( urlDataLoading.currentSeriesIsLoading || urlDataLoading.semesterListIsLoading || @@ -102,9 +131,21 @@ export const SemesterAdministration: FC = () => { return ( <> Administrácia semestra pre opravovateľov. + + + {semesterFreezeError && {semesterFreezeError}} + {semester.series_set.map((series) => ( {series.order}. séria + + + {seriesFreezeError && {seriesFreezeError}} + Opravovanie úloh: