2023-02-16 22:39:57 +00:00
|
|
|
import type { Dispatch, SetStateAction } from "react";
|
|
|
|
import { useState } from "react";
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-28 19:14:38 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Dialog,
|
|
|
|
DialogClose,
|
|
|
|
DialogContent,
|
|
|
|
DialogFooter,
|
|
|
|
DialogHeader,
|
|
|
|
showToast,
|
|
|
|
TextArea,
|
|
|
|
} from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Clock } from "@calcom/ui/components/icon";
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
interface IRescheduleDialog {
|
|
|
|
isOpenDialog: boolean;
|
|
|
|
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
|
|
|
|
bookingUId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RescheduleDialog = (props: IRescheduleDialog) => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const { isOpenDialog, setIsOpenDialog, bookingUId: bookingId } = props;
|
|
|
|
const [rescheduleReason, setRescheduleReason] = useState("");
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { mutate: rescheduleApi, isLoading } = trpc.viewer.bookings.requestReschedule.useMutation({
|
2022-10-18 19:47:36 +00:00
|
|
|
async onSuccess() {
|
|
|
|
showToast(t("reschedule_request_sent"), "success");
|
|
|
|
setIsOpenDialog(false);
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.bookings.invalidate();
|
2022-04-14 21:25:24 +00:00
|
|
|
},
|
2022-10-18 19:47:36 +00:00
|
|
|
onError() {
|
|
|
|
showToast(t("unexpected_error_try_again"), "error");
|
|
|
|
// @TODO: notify sentry
|
|
|
|
},
|
|
|
|
});
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
2022-11-28 19:14:38 +00:00
|
|
|
<DialogContent>
|
|
|
|
<div className="flex flex-row space-x-3">
|
|
|
|
<div className="flex h-10 w-10 flex-shrink-0 justify-center rounded-full bg-[#FAFAFA]">
|
2023-04-12 15:26:31 +00:00
|
|
|
<Clock className="m-auto h-6 w-6" />
|
2022-11-28 19:14:38 +00:00
|
|
|
</div>
|
|
|
|
<div className="pt-1">
|
|
|
|
<DialogHeader title={t("send_reschedule_request")} />
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-subtle text-sm">{t("reschedule_modal_description")}</p>
|
|
|
|
<p className="text-emphasis mt-6 mb-2 text-sm font-bold">
|
2022-11-28 19:14:38 +00:00
|
|
|
{t("reason_for_reschedule_request")}
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className="text-subtle font-normal"> (Optional)</span>
|
2022-11-28 19:14:38 +00:00
|
|
|
</p>
|
|
|
|
<TextArea
|
|
|
|
data-testid="reschedule_reason"
|
|
|
|
name={t("reschedule_reason")}
|
|
|
|
value={rescheduleReason}
|
|
|
|
onChange={(e) => setRescheduleReason(e.target.value)}
|
|
|
|
className="mb-5 sm:mb-6"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<DialogFooter>
|
|
|
|
<DialogClose />
|
|
|
|
<Button
|
|
|
|
data-testid="send_request"
|
|
|
|
disabled={isLoading}
|
|
|
|
onClick={() => {
|
|
|
|
rescheduleApi({
|
|
|
|
bookingId,
|
|
|
|
rescheduleReason,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{t("send_reschedule_request")}
|
|
|
|
</Button>
|
|
|
|
</DialogFooter>
|
|
|
|
</div>
|
2022-04-14 21:25:24 +00:00
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|