Improve new schedule creation flow (#4635)

pull/4636/head^2
Afzal Sayed 2022-09-21 11:10:58 +05:30 committed by GitHub
parent 4e7200a44b
commit 7d2f87a13e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -18,11 +18,23 @@ export function NewScheduleButton({ name = "new-schedule" }: { name?: string })
name: string;
}>();
const { register } = form;
const utils = trpc.useContext();
const createMutation = trpc.useMutation("viewer.availability.schedule.create", {
onSuccess: async ({ schedule }) => {
await router.push("/availability/" + schedule.id);
showToast(t("schedule_created_successfully", { scheduleName: schedule.name }), "success");
utils.setQueryData(["viewer.availability.list"], (data) => {
const newSchedule = { ...schedule, isDefault: false, availability: [] };
if (!data)
return {
schedules: [newSchedule],
};
return {
...data,
schedules: [...data.schedules, newSchedule],
};
});
},
onError: (err) => {
if (err instanceof HttpError) {