From a32ff8555a7f053d622b7587f6218ea7e98eebb8 Mon Sep 17 00:00:00 2001 From: Michal Masrna Date: Sun, 24 Nov 2024 10:53:51 +0100 Subject: [PATCH 1/6] SemesterAdministration layout changes --- .../SemesterAdministration.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index c4f27e57..13f5d06b 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -130,8 +130,8 @@ export const SemesterAdministration: FC = () => { return ( <> - Administrácia semestra pre opravovateľov. - + + Semester @@ -139,15 +139,17 @@ export const SemesterAdministration: FC = () => { {semester.series_set.map((series) => ( - {series.order}. séria - + + {series.order}. séria {seriesFreezeError && {seriesFreezeError}} - Opravovanie úloh: + + Opravovanie úloh: + Termín série: {formatDateTime(series.deadline)} From cd1fbd56f62d70560ab729679ee20f89d5a5a125 Mon Sep 17 00:00:00 2001 From: Michal Masrna Date: Sun, 24 Nov 2024 11:16:21 +0100 Subject: [PATCH 2/6] SemesterAdministration only display Freeze buttons if the series/semester is not yet complete --- .../SemesterAdministration.tsx | 20 +++++++++++++------ src/types/api/generated/competition.ts | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 13f5d06b..604bd2f7 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -132,18 +132,26 @@ export const SemesterAdministration: FC = () => { <> Semester - + {semester.complete ? ( + Semester je uzavretý + ) : ( + + )} {semesterFreezeError && {semesterFreezeError}} {semester.series_set.map((series) => ( {series.order}. séria - + {series.complete ? ( + Séria je uzavretá + ) : ( + + )} {seriesFreezeError && {seriesFreezeError}} diff --git a/src/types/api/generated/competition.ts b/src/types/api/generated/competition.ts index 7f9d0dae..78610e60 100644 --- a/src/types/api/generated/competition.ts +++ b/src/types/api/generated/competition.ts @@ -142,6 +142,7 @@ export interface Semester { start: string end: string additional_name?: string | null + complete: boolean frozen_results?: string | null competition?: any | null late_tags?: any[] @@ -159,6 +160,7 @@ export interface SemesterWithProblems { start: string end: string additional_name?: string | null + complete: boolean frozen_results?: string | null competition?: any | null late_tags?: any[] From f370462558f59c941f8eaf46b27993ba6f615321 Mon Sep 17 00:00:00 2001 From: Michal Masrna Date: Sun, 24 Nov 2024 11:32:59 +0100 Subject: [PATCH 3/6] Refetching semester on successful freeze of semester or series --- .../SemesterAdministration.tsx | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 604bd2f7..b973077c 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -1,5 +1,5 @@ import {Stack, Typography} from '@mui/material' -import {useQuery} from '@tanstack/react-query' +import {useMutation, useQuery} from '@tanstack/react-query' import axios, {AxiosError} from 'axios' import {FC, useState} from 'react' @@ -33,7 +33,11 @@ export const SemesterAdministration: FC = () => { const {hasPermissions, permissionsIsLoading} = useHasPermissions() - const {data: semesterData, isLoading: semesterIsLoading} = useQuery({ + const { + data: semesterData, + isLoading: semesterIsLoading, + refetch, + } = useQuery({ queryKey: ['competition', 'semester', semesterId], queryFn: () => axios.get(`/api/competition/semester/${semesterId}`), // router.query.params su v prvom renderi undefined, tak pustime query az so spravnym semesterId @@ -87,31 +91,30 @@ 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) { + const {mutate: freezeSemester} = useMutation({ + mutationFn: (semester: SemesterWithProblems) => + axios.post(`/api/competition/semester/${semester.id}/results/freeze`), + onSuccess: () => refetch(), + onError: (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) { + const {mutate: freezeSeries} = useMutation({ + mutationFn: (series: SeriesWithProblems) => axios.post(`/api/competition/series/${series.id}/results/freeze`), + onSuccess: () => refetch(), + onError: (error: unknown) => { if (error instanceof AxiosError) { setSeriesFreezeError(error.response?.data.detail) } else { setSeriesFreezeError('Nastala neznáma chyba.') } - } - } + }, + }) if ( urlDataLoading.currentSeriesIsLoading || From 3034a7b5890f160c8c40921d884d90fbcae4f592 Mon Sep 17 00:00:00 2001 From: Michal Masrna Date: Sun, 24 Nov 2024 11:44:12 +0100 Subject: [PATCH 4/6] SemesterAdministration separate errors for each series --- .../SemesterAdministration.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index b973077c..111b947e 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -89,7 +89,7 @@ export const SemesterAdministration: FC = () => { } const [semesterFreezeError, setSemesterFreezeError] = useState() - const [seriesFreezeError, setSeriesFreezeError] = useState() + const [seriesFreezeErrors, setSeriesFreezeErrors] = useState>() const {mutate: freezeSemester} = useMutation({ mutationFn: (semester: SemesterWithProblems) => @@ -107,11 +107,11 @@ export const SemesterAdministration: FC = () => { const {mutate: freezeSeries} = useMutation({ mutationFn: (series: SeriesWithProblems) => axios.post(`/api/competition/series/${series.id}/results/freeze`), onSuccess: () => refetch(), - onError: (error: unknown) => { + onError: (error: unknown, variables: SeriesWithProblems) => { if (error instanceof AxiosError) { - setSeriesFreezeError(error.response?.data.detail) + setSeriesFreezeErrors((prev) => new Map(prev).set(variables.id, error.response?.data.detail)) } else { - setSeriesFreezeError('Nastala neznáma chyba.') + setSeriesFreezeErrors((prev) => new Map(prev).set(variables.id, 'Nastala neznáma chyba.')) } }, }) @@ -155,7 +155,9 @@ export const SemesterAdministration: FC = () => { Uzavrieť sériu )} - {seriesFreezeError && {seriesFreezeError}} + {seriesFreezeErrors?.get(series.id) && ( + {seriesFreezeErrors?.get(series.id)} + )} From 28f1de378d2d3ec07a8c8a5f36eb9c345116ac4c Mon Sep 17 00:00:00 2001 From: Michal Masrna Date: Sun, 24 Nov 2024 11:57:34 +0100 Subject: [PATCH 5/6] SemesterAdmin removed semester freezing. Semester freezes automatically when all series are frozen. --- .../SemesterAdministration.tsx | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 111b947e..1ffcf78d 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -88,22 +88,8 @@ export const SemesterAdministration: FC = () => { ) } - const [semesterFreezeError, setSemesterFreezeError] = useState() const [seriesFreezeErrors, setSeriesFreezeErrors] = useState>() - const {mutate: freezeSemester} = useMutation({ - mutationFn: (semester: SemesterWithProblems) => - axios.post(`/api/competition/semester/${semester.id}/results/freeze`), - onSuccess: () => refetch(), - onError: (error: unknown) => { - if (error instanceof AxiosError) { - setSemesterFreezeError(error.response?.data.detail) - } else { - setSemesterFreezeError('Nastala neznáma chyba.') - } - }, - }) - const {mutate: freezeSeries} = useMutation({ mutationFn: (series: SeriesWithProblems) => axios.post(`/api/competition/series/${series.id}/results/freeze`), onSuccess: () => refetch(), @@ -135,14 +121,7 @@ export const SemesterAdministration: FC = () => { <> Semester - {semester.complete ? ( - Semester je uzavretý - ) : ( - - )} - {semesterFreezeError && {semesterFreezeError}} + {semester.complete && Semester je uzavretý} {semester.series_set.map((series) => ( From 8c154802b56354537341f01cf2d31bfc7ab01a7e Mon Sep 17 00:00:00 2001 From: matushl Date: Sun, 24 Nov 2024 13:16:31 +0100 Subject: [PATCH 6/6] Unset error message on success --- .../SemesterAdministration/SemesterAdministration.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 1ffcf78d..43cf2b05 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -92,7 +92,10 @@ export const SemesterAdministration: FC = () => { const {mutate: freezeSeries} = useMutation({ mutationFn: (series: SeriesWithProblems) => axios.post(`/api/competition/series/${series.id}/results/freeze`), - onSuccess: () => refetch(), + onSuccess: (_, variables: SeriesWithProblems) => { + setSeriesFreezeErrors((prev) => new Map(prev).set(variables.id, '')) + refetch() + }, onError: (error: unknown, variables: SeriesWithProblems) => { if (error instanceof AxiosError) { setSeriesFreezeErrors((prev) => new Map(prev).set(variables.id, error.response?.data.detail))