Skip to content

Commit

Permalink
SemesterAdministration separate errors for each series
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmasrna1 committed Nov 24, 2024
1 parent f370462 commit 3034a7b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/SemesterAdministration/SemesterAdministration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const SemesterAdministration: FC = () => {
}

const [semesterFreezeError, setSemesterFreezeError] = useState<string>()
const [seriesFreezeError, setSeriesFreezeError] = useState<string>()
const [seriesFreezeErrors, setSeriesFreezeErrors] = useState<Map<number, string>>()

const {mutate: freezeSemester} = useMutation({
mutationFn: (semester: SemesterWithProblems) =>
Expand All @@ -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.'))
}
},
})
Expand Down Expand Up @@ -155,7 +155,9 @@ export const SemesterAdministration: FC = () => {
Uzavrieť sériu
</Button>
)}
{seriesFreezeError && <Typography variant="body1">{seriesFreezeError}</Typography>}
{seriesFreezeErrors?.get(series.id) && (
<Typography variant="body1">{seriesFreezeErrors?.get(series.id)}</Typography>
)}
</Stack>
<Stack direction="row" justifyContent="space-between" alignItems="center">
<Typography variant="body1" component="div">
Expand Down

0 comments on commit 3034a7b

Please sign in to comment.