2022-04-15 02:24:27 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-04 15:40:46 +00:00
|
|
|
import { Button } from "@calcom/ui/components/button";
|
2022-04-15 02:24:27 +00:00
|
|
|
|
|
|
|
import { ConfirmDialog } from "./confirmDialog";
|
|
|
|
|
|
|
|
interface IWipeMyCalActionButtonProps {
|
2022-04-20 21:37:25 +00:00
|
|
|
bookingsEmpty: boolean;
|
2022-09-22 07:48:27 +00:00
|
|
|
bookingStatus: "upcoming" | "recurring" | "past" | "cancelled" | "unconfirmed";
|
2022-04-15 02:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const WipeMyCalActionButton = (props: IWipeMyCalActionButtonProps) => {
|
2022-07-22 17:27:06 +00:00
|
|
|
const { bookingsEmpty, bookingStatus } = props;
|
2022-04-15 02:24:27 +00:00
|
|
|
const [openDialog, setOpenDialog] = useState(false);
|
2022-06-01 17:24:41 +00:00
|
|
|
const { isSuccess, isLoading, data } = trpc.useQuery([
|
|
|
|
"viewer.integrations",
|
|
|
|
{ variant: "other", onlyInstalled: undefined },
|
|
|
|
]);
|
2022-04-15 02:24:27 +00:00
|
|
|
|
2022-04-20 21:37:25 +00:00
|
|
|
if (bookingStatus !== "upcoming" || bookingsEmpty) {
|
|
|
|
return <></>;
|
|
|
|
}
|
2022-07-22 17:27:06 +00:00
|
|
|
const wipeMyCalCredentials = data?.items.find((item: { type: string }) => item.type === "wipemycal_other");
|
2022-04-20 21:37:25 +00:00
|
|
|
|
|
|
|
const [credentialId] = wipeMyCalCredentials?.credentialIds || [false];
|
|
|
|
|
2022-04-15 02:24:27 +00:00
|
|
|
return (
|
2022-09-02 19:30:06 +00:00
|
|
|
<>
|
2022-04-20 21:37:25 +00:00
|
|
|
{data && isSuccess && !isLoading && credentialId && (
|
2022-09-02 19:30:06 +00:00
|
|
|
<div className="mb-4">
|
2022-07-22 17:27:06 +00:00
|
|
|
<ConfirmDialog isOpenDialog={openDialog} setIsOpenDialog={setOpenDialog} />
|
2022-09-09 15:02:31 +00:00
|
|
|
<Button color="primary" onClick={() => setOpenDialog(true)} data-testid="wipe-today-button">
|
2022-06-10 19:16:10 +00:00
|
|
|
Wipe Today
|
|
|
|
</Button>
|
2022-09-02 19:30:06 +00:00
|
|
|
</div>
|
2022-04-20 21:37:25 +00:00
|
|
|
)}
|
2022-09-02 19:30:06 +00:00
|
|
|
</>
|
2022-04-15 02:24:27 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { WipeMyCalActionButton };
|