From 7d2f87a13eb45cdfce7e5690baf0def81493b46a Mon Sep 17 00:00:00 2001 From: Afzal Sayed <14029371+afzalsayed96@users.noreply.github.com> Date: Wed, 21 Sep 2022 11:10:58 +0530 Subject: [PATCH] Improve new schedule creation flow (#4635) --- .../schedules/components/NewScheduleButton.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/features/schedules/components/NewScheduleButton.tsx b/packages/features/schedules/components/NewScheduleButton.tsx index 006fef6d2b..51c0293135 100644 --- a/packages/features/schedules/components/NewScheduleButton.tsx +++ b/packages/features/schedules/components/NewScheduleButton.tsx @@ -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) {