Migrate legacy api endpoints to tRPC II (#3865) (#3991)

* Migrate legacy api endpoints to tRPC II (#3865)

* fix: delete api route /api/availability/day

* fix: delete api route /api/availability/eventtype (#3573)

* fix: delete api route /api/event-type (#3573)

* migrate /api/book/confirm to viewer.bookings.confirm

* Merge branch 'main' into pr/3865

Co-authored-by: hussamkhatib <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: zomars <[email protected]>

* Import fixes

* Import fixes

Co-authored-by: mohammed hussam <[email protected]>
Co-authored-by: hussamkhatib <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-08-26 15:58:08 -06:00
1 parent 1d927a8b33
commit 02ac593ebf
10 files changed
+391 -821

No files matched your search

+22 -34
View File
@@ -1,7 +1,6 @@
import { BookingStatus } from "@prisma/client";
import { useRouter } from "next/router";
import { useState } from "react";
import { useMutation } from "react-query";
import { EventLocationType, getEventLocationType } from "@calcom/app-store/locations";
import dayjs from "@calcom/dayjs";
@@ -16,7 +15,6 @@ import { Icon } from "@calcom/ui/Icon";
import { Tooltip } from "@calcom/ui/Tooltip";
import { TextArea } from "@calcom/ui/form/fields";
import { HttpError } from "@lib/core/http/error";
import useMeQuery from "@lib/hooks/useMeQuery";
import { extractRecurringDates } from "@lib/parseDate";
@@ -42,39 +40,29 @@ function BookingListItem(booking: BookingItemProps) {
const router = useRouter();
const [rejectionReason, setRejectionReason] = useState<string>("");
const [rejectionDialogIsOpen, setRejectionDialogIsOpen] = useState(false);
const mutation = useMutation(
async (confirm: boolean) => {
let body = {
id: booking.id,
confirmed: confirm,
language: i18n.language,
reason: rejectionReason,
};
/**
* Only pass down the recurring event id when we need to confirm the entire series, which happens in
* the "Recurring" tab, to support confirming discretionally in the "Recurring" tab.
*/
if (booking.listingStatus === "recurring" && booking.recurringEventId !== null) {
body = Object.assign({}, body, { recurringEventId: booking.recurringEventId });
}
const res = await fetch("/api/book/confirm", {
method: "PATCH",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
});
if (!res.ok) {
throw new HttpError({ statusCode: res.status });
}
const mutation = trpc.useMutation(["viewer.bookings.confirm"], {
onSuccess: () => {
setRejectionDialogIsOpen(false);
utils.invalidateQueries("viewer.bookings");
},
{
async onSettled() {
await utils.invalidateQueries(["viewer.bookings"]);
},
});
const bookingConfirm = async (confirm: boolean) => {
let body = {
bookingId: booking.id,
confirmed: confirm,
reason: rejectionReason,
};
/**
* Only pass down the recurring event id when we need to confirm the entire series, which happens in
* the "Recurring" tab, to support confirming discretionally in the "Recurring" tab.
*/
if (booking.listingStatus === "recurring" && booking.recurringEventId !== null) {
body = Object.assign({}, body, { recurringEventId: booking.recurringEventId });
}
);
mutation.mutate(body);
};
const isUpcoming = new Date(booking.endTime) >= new Date();
const isCancelled = booking.status === BookingStatus.CANCELLED;
const isConfirmed = booking.status === BookingStatus.ACCEPTED;
@@ -101,7 +89,7 @@ function BookingListItem(booking: BookingItemProps) {
? t("confirm_all")
: t("confirm"),
onClick: () => {
mutation.mutate(true);
bookingConfirm(true);
},
icon: Icon.FiCheck,
disabled: mutation.isLoading,
@@ -269,7 +257,7 @@ function BookingListItem(booking: BookingItemProps) {
<Button
disabled={mutation.isLoading}
onClick={() => {
mutation.mutate(false);
bookingConfirm(false);
}}>
{t("rejection_confirmation")}
</Button>