Skip to content

Commit a7d34b9

Browse files
fusharclaude
andcommitted
Fix dialogs closing on mutation error instead of showing submission errors
Use mutateAsync instead of mutate and move dialog close to onSuccess, so SubmissionError propagates back to withSubmissionError in forms. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cfe6b50 commit a7d34b9

File tree

17 files changed

+56
-64
lines changed

17 files changed

+56
-64
lines changed

judgels-client/src/routes/admin/archives/ArchiveCreateDialog/ArchiveCreateDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export function ArchiveCreateDialog() {
2929
</>
3030
);
3131

32-
const createArchive = data => {
33-
createArchiveMutation.mutate(data, {
32+
const createArchive = async data => {
33+
await createArchiveMutation.mutateAsync(data, {
3434
onSuccess: () => {
35+
setIsDialogOpen(false);
3536
toastActions.showSuccessToast('Archive created.');
3637
},
3738
});
38-
setIsDialogOpen(false);
3939
};
4040

4141
return (

judgels-client/src/routes/admin/archives/ArchiveEditDialog/ArchiveEditDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export function ArchiveEditDialog({ archive, isOpen, onCloseDialog }) {
2121
</>
2222
);
2323

24-
const updateArchive = data => {
25-
updateArchiveMutation.mutate(data, {
24+
const updateArchive = async data => {
25+
await updateArchiveMutation.mutateAsync(data, {
2626
onSuccess: () => {
27+
onCloseDialog();
2728
toastActions.showSuccessToast('Archive updated.');
2829
},
2930
});
30-
onCloseDialog();
3131
};
3232

3333
const initialValues = archive && {

judgels-client/src/routes/admin/chapters/ChapterCreateDialog/ChapterCreateDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export function ChapterCreateDialog() {
2929
</>
3030
);
3131

32-
const createChapter = data => {
33-
createChapterMutation.mutate(data, {
32+
const createChapter = async data => {
33+
await createChapterMutation.mutateAsync(data, {
3434
onSuccess: () => {
35+
setIsDialogOpen(false);
3536
toastActions.showSuccessToast('Chapter created.');
3637
},
3738
});
38-
setIsDialogOpen(false);
3939
};
4040

4141
return (

judgels-client/src/routes/admin/chapters/ChapterEditDialog/ChapterEditDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export function ChapterEditDialog({ chapter, isOpen, onCloseDialog }) {
2121
</>
2222
);
2323

24-
const updateChapter = data => {
25-
updateChapterMutation.mutate(data, {
24+
const updateChapter = async data => {
25+
await updateChapterMutation.mutateAsync(data, {
2626
onSuccess: () => {
27+
onCloseDialog();
2728
toastActions.showSuccessToast('Chapter updated.');
2829
},
2930
});
30-
onCloseDialog();
3131
};
3232

3333
const initialValues = chapter && {

judgels-client/src/routes/admin/chapters/ChapterLessonEditDialog/ChapterLessonEditDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ export function ChapterLessonEditDialog({ isOpen, chapter, onCloseDialog }) {
3232
setIsEditing(prev => !prev);
3333
};
3434

35-
const updateLessons = data => {
35+
const updateLessons = async data => {
3636
const lessons = deserializeLessons(data.lessons);
37-
setLessonsMutation.mutate(lessons, {
37+
await setLessonsMutation.mutateAsync(lessons, {
3838
onSuccess: () => {
39+
setIsEditing(false);
3940
toastActions.showSuccessToast('Chapter lessons updated.');
4041
},
4142
});
42-
setIsEditing(false);
4343
};
4444

4545
const renderDialogContent = () => {

judgels-client/src/routes/admin/chapters/ChapterProblemEditDialog/ChapterProblemEditDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export function ChapterProblemEditDialog({ isOpen, chapter, onCloseDialog }) {
3333
setIsEditing(prev => !prev);
3434
};
3535

36-
const updateProblems = data => {
36+
const updateProblems = async data => {
3737
const problems = deserializeProblems(data.problems);
38-
setProblemsMutation.mutate(problems, {
38+
await setProblemsMutation.mutateAsync(problems, {
3939
onSuccess: () => {
40+
setIsEditing(false);
4041
toastActions.showSuccessToast('Chapter problems updated.');
4142
},
4243
});
43-
setIsEditing(false);
4444
};
4545

4646
const renderDialogContent = () => {

judgels-client/src/routes/admin/courses/CourseCreateDialog/CourseCreateDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export function CourseCreateDialog() {
2929
</>
3030
);
3131

32-
const createCourse = data => {
33-
createCourseMutation.mutate(data, {
32+
const createCourse = async data => {
33+
await createCourseMutation.mutateAsync(data, {
3434
onSuccess: () => {
35+
setIsDialogOpen(false);
3536
toastActions.showSuccessToast('Course created.');
3637
},
3738
});
38-
setIsDialogOpen(false);
3939
};
4040

4141
return (

judgels-client/src/routes/admin/courses/CourseEditDialog/CourseEditDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export function CourseEditDialog({ course, isOpen, onCloseDialog }) {
2121
</>
2222
);
2323

24-
const updateCourse = data => {
25-
updateCourseMutation.mutate(data, {
24+
const updateCourse = async data => {
25+
await updateCourseMutation.mutateAsync(data, {
2626
onSuccess: () => {
27+
onCloseDialog();
2728
toastActions.showSuccessToast('Course updated.');
2829
},
2930
});
30-
onCloseDialog();
3131
};
3232

3333
const initialValues = course && {

judgels-client/src/routes/admin/problemsets/ProblemSetCreateDialog/ProblemSetCreateDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export function ProblemSetCreateDialog() {
2929
</>
3030
);
3131

32-
const createProblemSet = data => {
33-
createProblemSetMutation.mutate(
32+
const createProblemSet = async data => {
33+
await createProblemSetMutation.mutateAsync(
3434
{
3535
slug: data.slug,
3636
name: data.name,
@@ -40,11 +40,11 @@ export function ProblemSetCreateDialog() {
4040
},
4141
{
4242
onSuccess: () => {
43+
setIsDialogOpen(false);
4344
toastActions.showSuccessToast('Problemset created.');
4445
},
4546
}
4647
);
47-
setIsDialogOpen(false);
4848
};
4949

5050
const initialValues = {

judgels-client/src/routes/admin/problemsets/ProblemSetEditDialog/ProblemSetEditDialog.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export function ProblemSetEditDialog({ isOpen, problemSet, archiveSlug, onCloseD
2121
</>
2222
);
2323

24-
const updateProblemSet = data => {
25-
updateProblemSetMutation.mutate(
24+
const updateProblemSet = async data => {
25+
await updateProblemSetMutation.mutateAsync(
2626
{
2727
slug: data.slug,
2828
name: data.name,
@@ -32,11 +32,11 @@ export function ProblemSetEditDialog({ isOpen, problemSet, archiveSlug, onCloseD
3232
},
3333
{
3434
onSuccess: () => {
35+
onCloseDialog();
3536
toastActions.showSuccessToast('Problemset updated.');
3637
},
3738
}
3839
);
39-
onCloseDialog();
4040
};
4141

4242
const initialValues = problemSet && {

0 commit comments

Comments
 (0)