Skip to content

Commit

Permalink
refresh route upon submitting form or deleting appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamdevnote committed May 10, 2024
1 parent ce0d5f8 commit 6dd54c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { cn, formatToDisplayDate, formatToDisplayTime } from "@/lib/utils";
import AppointmentDateTimePicker from "../appointmentDateTimePicker/appointmentDateTimePicker";
import { APPOINTMENT_QUERYResult } from "@/lib/sanity/sanity.types";
import { SplitContainer } from "@/components/templates/container";
import { useRouter } from "next/navigation";

/**
* Extracted async calls into its own functions to manage them separate from rendering logic.
Expand Down Expand Up @@ -97,6 +98,7 @@ export const AppointmentForm = ({
}: AppointmentFormProps) => {
const submitBtnLabel = (mode === "create" ? "Book" : "Edit") + " Appointment";
const { toast } = useToast();
const router = useRouter();
const form = useForm<z.infer<typeof FormSchema>>({
defaultValues:
mode === "edit" && !!appointment
Expand Down Expand Up @@ -125,6 +127,7 @@ export const AppointmentForm = ({
await sendEmail(values);

onClose ? onClose() : null;
router.refresh();
toast({
title: `Your appointment has been successfully ${mode === "create" ? "booked" : "updated"}!`,
intent: "success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { useToast } from "@/components/molecules/toast";
import { Button } from "@/components/atoms/button";
import cancel_img from "./cancel_img.svg";
import { useRouter } from "next/navigation";

const cancelAppointment = async (
url: string,
Expand Down Expand Up @@ -45,6 +46,7 @@ export default function CancelDialog({
}: CancelDialogProps) {
const { toast } = useToast();
const [open, setOpen] = useState(false);
const router = useRouter();
const { trigger: swrTrigger, isMutating } = useSWRMutation(
"/api/my-appointments",
cancelAppointment,
Expand All @@ -54,6 +56,7 @@ export default function CancelDialog({
try {
await swrTrigger({ appointmentId });
if (!isMutating) {
router.refresh();
setOpen(false);
toast({
title: "Your appointment has been cancelled!",
Expand Down

0 comments on commit 6dd54c4

Please sign in to comment.