Skip to content

Commit

Permalink
fix: error handlingn fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qamarq committed Dec 9, 2024
1 parent ec7b260 commit cc95e13
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions frontend/src/app/plans/edit/[id]/_components/CreateNewPlanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,27 @@ export function CreateNewPlanPage({
const groups = plan.allGroups
.filter((g) => g.isChecked)
.map((g) => ({ id: g.groupOnlineId }));
const res = await createNewPlan({
name: plan.name,
courses,
registrations,
groups,
});
if (res === false) {
try {
const res = await createNewPlan({
name: plan.name,
courses,
registrations,
groups,
});
plan.setPlan((prev) => ({
...prev,
synced: true,
updatedAt: new Date(res.schedule.updatedAt),
onlineId: res.schedule.id.toString(),
}));
toast.success("Utworzono plan");
return true;
} catch (error) {
return toast.error("Nie udało się utworzyć planu w wersji online", {
description: "Zaloguj się i spróbuj ponownie",
duration: 5000,
});
}
plan.setPlan((prev) => ({
...prev,
synced: true,
updatedAt: new Date(res.schedule.updatedAt),
onlineId: res.schedule.id.toString(),
}));
toast.success("Utworzono plan");
return true;
};

const handleSyncPlan = async () => {
Expand All @@ -125,7 +126,7 @@ export function CreateNewPlanPage({
.filter((g) => g.isChecked)
.map((g) => ({ id: g.groupOnlineId })),
});
if (res === false || !res.success) {
if (!res.success) {
return toast.error("Nie udało się zaktualizować planu");
}
await refetchOnlinePlan();
Expand All @@ -138,6 +139,8 @@ export function CreateNewPlanPage({
: new Date(),
}));
return true;
} catch (error) {
return toast.error("Nie udało się zaktualizować planu");
} finally {
setSyncing(false);
}
Expand Down

0 comments on commit cc95e13

Please sign in to comment.