2022-11-23 02:55:25 +00:00
|
|
|
import { Dispatch, SetStateAction, 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 15:52:42 +00:00
|
|
|
import { Button, Dialog, DialogContent, Icon, showToast, TextArea } from "@calcom/ui";
|
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 15:52:42 +00:00
|
|
|
<DialogContent
|
|
|
|
Icon={Icon.FiClock}
|
|
|
|
useOwnActionButtons
|
|
|
|
title={t("send_reschedule_request")}
|
|
|
|
description={t("reschedule_modal_description")}>
|
|
|
|
<div>
|
|
|
|
<p className="text-sm font-medium text-black">
|
|
|
|
{t("reason_for_reschedule_request")}
|
|
|
|
<span className="font-normal text-gray-500"> (Optional)</span>
|
|
|
|
</p>
|
|
|
|
<TextArea
|
|
|
|
data-testid="reschedule_reason"
|
|
|
|
name={t("reschedule_reason")}
|
|
|
|
value={rescheduleReason}
|
|
|
|
onChange={(e) => setRescheduleReason(e.target.value)}
|
|
|
|
className="mt-2"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex justify-end space-x-2">
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
setRescheduleReason("");
|
|
|
|
setIsOpenDialog(false);
|
|
|
|
}}
|
|
|
|
color="secondary">
|
|
|
|
{t("cancel")}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
data-testid="send_request"
|
|
|
|
disabled={isLoading}
|
|
|
|
onClick={() => {
|
|
|
|
rescheduleApi({
|
|
|
|
bookingId,
|
|
|
|
rescheduleReason,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{t("send_reschedule_request")}
|
|
|
|
</Button>
|
2022-04-14 21:25:24 +00:00
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|