2021-09-30 10:46:39 +00:00
|
|
|
import { BookingStatus } from "@prisma/client";
|
2022-05-18 21:05:49 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { useState } from "react";
|
2021-09-30 10:46:39 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { EventLocationType } from "@calcom/app-store/locations";
|
|
|
|
import { getEventLocationType } from "@calcom/app-store/locations";
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2023-03-23 18:49:28 +00:00
|
|
|
// TODO: Use browser locale, implement Intl in Dayjs maybe?
|
|
|
|
import "@calcom/dayjs/locales";
|
2022-12-27 21:03:39 +00:00
|
|
|
import ViewRecordingsDialog from "@calcom/features/ee/video/ViewRecordingsDialog";
|
2022-04-14 21:25:24 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
2022-10-19 09:45:44 +00:00
|
|
|
import { formatTime } from "@calcom/lib/date-fns";
|
2022-04-14 21:25:24 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-06-10 20:38:06 +00:00
|
|
|
import { getEveryFreqFor } from "@calcom/lib/recurringStrings";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { RouterInputs, RouterOutputs } from "@calcom/trpc/react";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import type { ActionType } from "@calcom/ui";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Badge,
|
|
|
|
Button,
|
|
|
|
Dialog,
|
|
|
|
DialogClose,
|
|
|
|
DialogContent,
|
|
|
|
DialogFooter,
|
|
|
|
MeetingTimeInTimezones,
|
|
|
|
showToast,
|
|
|
|
Tooltip,
|
2022-12-27 21:03:39 +00:00
|
|
|
TableActions,
|
2023-02-09 15:43:28 +00:00
|
|
|
TextAreaField,
|
2022-11-23 02:55:25 +00:00
|
|
|
} from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Check, Clock, MapPin, RefreshCcw, Send, Slash, X, CreditCard } from "@calcom/ui/components/icon";
|
2022-03-16 23:36:43 +00:00
|
|
|
|
2022-05-04 21:05:57 +00:00
|
|
|
import useMeQuery from "@lib/hooks/useMeQuery";
|
2021-09-30 10:46:39 +00:00
|
|
|
|
2023-04-11 21:44:14 +00:00
|
|
|
import { ChargeCardDialog } from "@components/dialog/ChargeCardDialog";
|
2022-05-27 23:27:41 +00:00
|
|
|
import { EditLocationDialog } from "@components/dialog/EditLocationDialog";
|
2022-04-14 21:25:24 +00:00
|
|
|
import { RescheduleDialog } from "@components/dialog/RescheduleDialog";
|
2021-09-30 10:46:39 +00:00
|
|
|
|
2022-12-22 12:35:01 +00:00
|
|
|
type BookingListingStatus = RouterInputs["viewer"]["bookings"]["get"]["filters"]["status"];
|
2022-05-05 21:16:25 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
type BookingItem = RouterOutputs["viewer"]["bookings"]["get"]["bookings"][number];
|
2021-09-30 10:46:39 +00:00
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
type BookingItemProps = BookingItem & {
|
|
|
|
listingStatus: BookingListingStatus;
|
2022-11-10 23:40:01 +00:00
|
|
|
recurringInfo: RouterOutputs["viewer"]["bookings"]["get"]["recurringInfo"][number] | undefined;
|
2022-05-05 21:16:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function BookingListItem(booking: BookingItemProps) {
|
2022-02-28 16:24:47 +00:00
|
|
|
// Get user so we can determine 12/24 hour format preferences
|
|
|
|
const query = useMeQuery();
|
|
|
|
const user = query.data;
|
2023-03-17 08:12:51 +00:00
|
|
|
const {
|
|
|
|
t,
|
|
|
|
i18n: { language },
|
|
|
|
} = useLocale();
|
2021-09-30 10:46:39 +00:00
|
|
|
const utils = trpc.useContext();
|
2022-05-18 21:05:49 +00:00
|
|
|
const router = useRouter();
|
2022-02-09 18:25:58 +00:00
|
|
|
const [rejectionReason, setRejectionReason] = useState<string>("");
|
|
|
|
const [rejectionDialogIsOpen, setRejectionDialogIsOpen] = useState(false);
|
2023-04-11 21:44:14 +00:00
|
|
|
const [chargeCardDialogIsOpen, setChargeCardDialogIsOpen] = useState(false);
|
2022-12-27 21:03:39 +00:00
|
|
|
const [viewRecordingsDialogIsOpen, setViewRecordingsDialogIsOpen] = useState<boolean>(false);
|
2023-04-11 21:44:14 +00:00
|
|
|
const cardCharged = booking?.payment[0]?.success;
|
2022-11-10 23:40:01 +00:00
|
|
|
const mutation = trpc.viewer.bookings.confirm.useMutation({
|
2022-11-12 21:21:01 +00:00
|
|
|
onSuccess: (data) => {
|
2023-02-08 20:36:22 +00:00
|
|
|
if (data?.status === BookingStatus.REJECTED) {
|
2022-11-12 21:21:01 +00:00
|
|
|
setRejectionDialogIsOpen(false);
|
|
|
|
showToast(t("booking_rejection_success"), "success");
|
|
|
|
} else {
|
|
|
|
showToast(t("booking_confirmation_success"), "success");
|
|
|
|
}
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.bookings.invalidate();
|
2022-10-04 19:46:17 +00:00
|
|
|
},
|
|
|
|
onError: () => {
|
|
|
|
showToast(t("booking_confirmation_failed"), "error");
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.bookings.invalidate();
|
2021-09-30 10:46:39 +00:00
|
|
|
},
|
2022-08-26 21:58:08 +00:00
|
|
|
});
|
|
|
|
|
2022-10-06 20:38:50 +00:00
|
|
|
const isUpcoming = new Date(booking.endTime) >= new Date();
|
|
|
|
const isPast = new Date(booking.endTime) < new Date();
|
|
|
|
const isCancelled = booking.status === BookingStatus.CANCELLED;
|
|
|
|
const isConfirmed = booking.status === BookingStatus.ACCEPTED;
|
|
|
|
const isRejected = booking.status === BookingStatus.REJECTED;
|
|
|
|
const isPending = booking.status === BookingStatus.PENDING;
|
|
|
|
const isRecurring = booking.recurringEventId !== null;
|
|
|
|
const isTabRecurring = booking.listingStatus === "recurring";
|
|
|
|
const isTabUnconfirmed = booking.listingStatus === "unconfirmed";
|
|
|
|
|
2022-08-26 21:58:08 +00:00
|
|
|
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
|
2022-10-06 19:23:22 +00:00
|
|
|
* the "Recurring" tab and "Unconfirmed" tab, to support confirming discretionally in the "Recurring" tab.
|
2022-08-26 21:58:08 +00:00
|
|
|
*/
|
2022-10-06 19:23:22 +00:00
|
|
|
if ((isTabRecurring || isTabUnconfirmed) && isRecurring) {
|
2022-08-26 21:58:08 +00:00
|
|
|
body = Object.assign({}, body, { recurringEventId: booking.recurringEventId });
|
2021-09-30 10:46:39 +00:00
|
|
|
}
|
2022-08-26 21:58:08 +00:00
|
|
|
mutation.mutate(body);
|
|
|
|
};
|
|
|
|
|
2023-03-14 04:19:05 +00:00
|
|
|
const getSeatReferenceUid = () => {
|
|
|
|
if (!booking.seatsReferences[0]) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return booking.seatsReferences[0].referenceUid;
|
|
|
|
};
|
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
const pendingActions: ActionType[] = [
|
2021-09-30 10:46:39 +00:00
|
|
|
{
|
|
|
|
id: "reject",
|
2022-10-06 19:23:22 +00:00
|
|
|
label: (isTabRecurring || isTabUnconfirmed) && isRecurring ? t("reject_all") : t("reject"),
|
2022-05-27 23:27:41 +00:00
|
|
|
onClick: () => {
|
2022-05-18 21:05:49 +00:00
|
|
|
setRejectionDialogIsOpen(true);
|
|
|
|
},
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: Slash,
|
2021-09-30 10:46:39 +00:00
|
|
|
disabled: mutation.isLoading,
|
|
|
|
},
|
2023-04-11 21:44:14 +00:00
|
|
|
// For bookings with payment, only confirm if the booking is paid for
|
|
|
|
...((isPending && !booking?.eventType?.price) || (!!booking?.eventType?.price && booking.paid)
|
|
|
|
? [
|
|
|
|
{
|
|
|
|
id: "confirm",
|
|
|
|
label: (isTabRecurring || isTabUnconfirmed) && isRecurring ? t("confirm_all") : t("confirm"),
|
|
|
|
onClick: () => {
|
|
|
|
bookingConfirm(true);
|
|
|
|
},
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: Check,
|
2023-04-11 21:44:14 +00:00
|
|
|
disabled: mutation.isLoading,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: []),
|
2021-09-30 10:46:39 +00:00
|
|
|
];
|
|
|
|
|
2022-12-27 21:03:39 +00:00
|
|
|
const showRecordingActions: ActionType[] = [
|
|
|
|
{
|
|
|
|
id: "view_recordings",
|
|
|
|
label: t("view_recordings"),
|
|
|
|
onClick: () => {
|
|
|
|
setViewRecordingsDialogIsOpen(true);
|
|
|
|
},
|
|
|
|
disabled: mutation.isLoading,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-10 20:38:06 +00:00
|
|
|
let bookedActions: ActionType[] = [
|
2021-09-30 10:46:39 +00:00
|
|
|
{
|
|
|
|
id: "cancel",
|
2022-10-06 19:23:22 +00:00
|
|
|
label: isTabRecurring && isRecurring ? t("cancel_all_remaining") : t("cancel"),
|
2022-07-19 23:29:52 +00:00
|
|
|
/* When cancelling we need to let the UI and the API know if the intention is to
|
|
|
|
cancel all remaining bookings or just that booking instance. */
|
2022-11-29 20:27:29 +00:00
|
|
|
href: `/booking/${booking.uid}?cancel=true${
|
2022-11-16 19:48:17 +00:00
|
|
|
isTabRecurring && isRecurring ? "&allRemainingBookings=true" : ""
|
2023-03-14 04:19:05 +00:00
|
|
|
}${booking.seatsReferences.length ? `&seatReferenceUid=${getSeatReferenceUid()}` : ""}
|
|
|
|
`,
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: X,
|
2021-09-30 10:46:39 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-27 23:27:41 +00:00
|
|
|
id: "edit_booking",
|
2022-09-27 23:51:41 +00:00
|
|
|
label: t("edit"),
|
2022-04-14 21:25:24 +00:00
|
|
|
actions: [
|
|
|
|
{
|
2022-05-27 23:27:41 +00:00
|
|
|
id: "reschedule",
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: Clock,
|
2022-05-27 23:27:41 +00:00
|
|
|
label: t("reschedule_booking"),
|
2023-03-14 04:19:05 +00:00
|
|
|
href: `/reschedule/${booking.uid}${
|
|
|
|
booking.seatsReferences.length ? `?seatReferenceUid=${getSeatReferenceUid()}` : ""
|
|
|
|
}`,
|
2022-04-14 21:25:24 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "reschedule_request",
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: Send,
|
2022-08-05 15:03:27 +00:00
|
|
|
iconClassName: "rotate-45 w-[16px] -translate-x-0.5 ",
|
2022-04-14 21:25:24 +00:00
|
|
|
label: t("send_reschedule_request"),
|
2022-05-27 23:27:41 +00:00
|
|
|
onClick: () => {
|
2022-05-18 21:05:49 +00:00
|
|
|
setIsOpenRescheduleDialog(true);
|
|
|
|
},
|
2022-04-14 21:25:24 +00:00
|
|
|
},
|
2022-05-27 23:27:41 +00:00
|
|
|
{
|
|
|
|
id: "change_location",
|
|
|
|
label: t("edit_location"),
|
|
|
|
onClick: () => {
|
|
|
|
setIsOpenLocationDialog(true);
|
|
|
|
},
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: MapPin,
|
2022-05-27 23:27:41 +00:00
|
|
|
},
|
2022-04-14 21:25:24 +00:00
|
|
|
],
|
2021-09-30 10:46:39 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-04-11 21:44:14 +00:00
|
|
|
const chargeCardActions: ActionType[] = [
|
|
|
|
{
|
|
|
|
id: "charge_card",
|
|
|
|
label: cardCharged ? t("no_show_fee_charged") : t("collect_no_show_fee"),
|
|
|
|
disabled: cardCharged,
|
|
|
|
onClick: () => {
|
|
|
|
setChargeCardDialogIsOpen(true);
|
|
|
|
},
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: CreditCard,
|
2023-04-11 21:44:14 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-10-06 19:23:22 +00:00
|
|
|
if (isTabRecurring && isRecurring) {
|
2022-06-10 20:38:06 +00:00
|
|
|
bookedActions = bookedActions.filter((action) => action.id !== "edit_booking");
|
2022-12-21 13:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isPast && isPending && !isConfirmed) {
|
|
|
|
bookedActions = bookedActions.filter((action) => action.id !== "cancel");
|
2022-06-10 20:38:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 21:25:24 +00:00
|
|
|
const RequestSentMessage = () => {
|
|
|
|
return (
|
2023-04-12 15:26:31 +00:00
|
|
|
<Badge startIcon={Send} size="md" variant="gray" data-testid="request_reschedule_sent">
|
2023-03-14 12:34:41 +00:00
|
|
|
{t("reschedule_request_sent")}
|
|
|
|
</Badge>
|
2022-04-14 21:25:24 +00:00
|
|
|
);
|
|
|
|
};
|
2021-09-30 10:46:39 +00:00
|
|
|
|
2023-03-17 08:12:51 +00:00
|
|
|
const startTime = dayjs(booking.startTime)
|
|
|
|
.locale(language)
|
|
|
|
.format(isUpcoming ? "ddd, D MMM" : "D MMMM YYYY");
|
2022-04-14 21:25:24 +00:00
|
|
|
const [isOpenRescheduleDialog, setIsOpenRescheduleDialog] = useState(false);
|
2022-05-27 23:27:41 +00:00
|
|
|
const [isOpenSetLocationDialog, setIsOpenLocationDialog] = useState(false);
|
2022-11-10 23:40:01 +00:00
|
|
|
const setLocationMutation = trpc.viewer.bookings.editLocation.useMutation({
|
2022-05-27 23:27:41 +00:00
|
|
|
onSuccess: () => {
|
|
|
|
showToast(t("location_updated"), "success");
|
|
|
|
setIsOpenLocationDialog(false);
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.bookings.invalidate();
|
2022-05-27 23:27:41 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-08-26 00:48:50 +00:00
|
|
|
const saveLocation = (newLocationType: EventLocationType["type"], details: { [key: string]: string }) => {
|
2022-05-27 23:27:41 +00:00
|
|
|
let newLocation = newLocationType as string;
|
2022-08-26 00:48:50 +00:00
|
|
|
const eventLocationType = getEventLocationType(newLocationType);
|
|
|
|
if (eventLocationType?.organizerInputType) {
|
2022-05-27 23:27:41 +00:00
|
|
|
newLocation = details[Object.keys(details)[0]];
|
|
|
|
}
|
|
|
|
setLocationMutation.mutate({ bookingId: booking.id, newLocation });
|
|
|
|
};
|
2022-05-05 21:16:25 +00:00
|
|
|
|
2022-11-04 16:43:02 +00:00
|
|
|
// Getting accepted recurring dates to show
|
|
|
|
const recurringDates = booking.recurringInfo?.bookings[BookingStatus.ACCEPTED]
|
|
|
|
.concat(booking.recurringInfo?.bookings[BookingStatus.CANCELLED])
|
|
|
|
.concat(booking.recurringInfo?.bookings[BookingStatus.PENDING])
|
|
|
|
.sort((date1: Date, date2: Date) => date1.getTime() - date2.getTime());
|
2022-05-18 21:05:49 +00:00
|
|
|
|
2022-10-19 09:45:44 +00:00
|
|
|
const onClickTableData = () => {
|
2022-05-27 23:27:41 +00:00
|
|
|
router.push({
|
2022-11-29 20:27:29 +00:00
|
|
|
pathname: `/booking/${booking.uid}`,
|
2022-05-27 23:27:41 +00:00
|
|
|
query: {
|
2022-11-16 19:48:17 +00:00
|
|
|
allRemainingBookings: isTabRecurring,
|
2022-11-15 19:00:02 +00:00
|
|
|
email: booking.attendees[0] ? booking.attendees[0].email : undefined,
|
2022-05-27 23:27:41 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2023-03-03 16:35:11 +00:00
|
|
|
|
2023-03-13 22:03:06 +00:00
|
|
|
const title = booking.title;
|
2023-04-17 16:19:24 +00:00
|
|
|
// To be used after we run query on legacy bookings
|
|
|
|
// const showRecordingsButtons = booking.isRecorded && isPast && isConfirmed;
|
|
|
|
|
|
|
|
const showRecordingsButtons =
|
|
|
|
(booking.location === "integrations:daily" || booking?.location?.trim() === "") && isPast && isConfirmed;
|
|
|
|
|
2021-09-30 10:46:39 +00:00
|
|
|
return (
|
2022-02-09 18:25:58 +00:00
|
|
|
<>
|
2022-04-14 21:25:24 +00:00
|
|
|
<RescheduleDialog
|
|
|
|
isOpenDialog={isOpenRescheduleDialog}
|
|
|
|
setIsOpenDialog={setIsOpenRescheduleDialog}
|
|
|
|
bookingUId={booking.uid}
|
|
|
|
/>
|
2022-05-27 23:27:41 +00:00
|
|
|
<EditLocationDialog
|
|
|
|
booking={booking}
|
|
|
|
saveLocation={saveLocation}
|
|
|
|
isOpenDialog={isOpenSetLocationDialog}
|
|
|
|
setShowLocationModal={setIsOpenLocationDialog}
|
|
|
|
/>
|
2023-04-11 21:44:14 +00:00
|
|
|
{booking.paid && (
|
|
|
|
<ChargeCardDialog
|
|
|
|
isOpenDialog={chargeCardDialogIsOpen}
|
|
|
|
setIsOpenDialog={setChargeCardDialogIsOpen}
|
|
|
|
bookingId={booking.id}
|
|
|
|
paymentAmount={booking?.payment[0].amount}
|
|
|
|
paymentCurrency={booking?.payment[0].currency}
|
|
|
|
/>
|
|
|
|
)}
|
2022-12-27 21:03:39 +00:00
|
|
|
{showRecordingsButtons && (
|
|
|
|
<ViewRecordingsDialog
|
|
|
|
booking={booking}
|
|
|
|
isOpenDialog={viewRecordingsDialogIsOpen}
|
|
|
|
setIsOpenDialog={setViewRecordingsDialogIsOpen}
|
|
|
|
timeFormat={user?.timeFormat ?? null}
|
|
|
|
/>
|
|
|
|
)}
|
2022-04-14 21:25:24 +00:00
|
|
|
{/* NOTE: Should refactor this dialog component as is being rendered multiple times */}
|
2022-02-09 18:25:58 +00:00
|
|
|
<Dialog open={rejectionDialogIsOpen} onOpenChange={setRejectionDialogIsOpen}>
|
2023-02-09 15:43:28 +00:00
|
|
|
<DialogContent title={t("rejection_reason_title")} description={t("rejection_reason_description")}>
|
|
|
|
<div>
|
|
|
|
<TextAreaField
|
|
|
|
name="rejectionReason"
|
|
|
|
label={
|
|
|
|
<>
|
|
|
|
{t("rejection_reason")}
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className="text-subtle font-normal"> (Optional)</span>
|
2023-02-09 15:43:28 +00:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
value={rejectionReason}
|
|
|
|
onChange={(e) => setRejectionReason(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-02-09 18:25:58 +00:00
|
|
|
|
|
|
|
<DialogFooter>
|
2022-11-28 19:14:38 +00:00
|
|
|
<DialogClose />
|
2022-02-09 18:25:58 +00:00
|
|
|
<Button
|
|
|
|
disabled={mutation.isLoading}
|
|
|
|
onClick={() => {
|
2022-08-26 21:58:08 +00:00
|
|
|
bookingConfirm(false);
|
2022-02-09 18:25:58 +00:00
|
|
|
}}>
|
|
|
|
{t("rejection_confirmation")}
|
|
|
|
</Button>
|
|
|
|
</DialogFooter>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
|
2023-04-05 18:14:46 +00:00
|
|
|
<tr className="hover:bg-muted group flex flex-col sm:flex-row">
|
2022-10-19 09:45:44 +00:00
|
|
|
<td
|
|
|
|
className="hidden align-top ltr:pl-6 rtl:pr-6 sm:table-cell sm:min-w-[12rem]"
|
|
|
|
onClick={onClickTableData}>
|
2022-05-27 23:27:41 +00:00
|
|
|
<div className="cursor-pointer py-4">
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-emphasis text-sm leading-6">{startTime}</div>
|
|
|
|
<div className="text-subtle text-sm">
|
2022-10-19 09:45:44 +00:00
|
|
|
{formatTime(booking.startTime, user?.timeFormat, user?.timeZone)} -{" "}
|
|
|
|
{formatTime(booking.endTime, user?.timeFormat, user?.timeZone)}
|
|
|
|
<MeetingTimeInTimezones
|
|
|
|
timeFormat={user?.timeFormat}
|
|
|
|
userTimezone={user?.timeZone}
|
|
|
|
startTime={booking.startTime}
|
|
|
|
endTime={booking.endTime}
|
|
|
|
attendees={booking.attendees}
|
|
|
|
/>
|
2022-05-27 23:27:41 +00:00
|
|
|
</div>
|
2022-09-27 23:51:41 +00:00
|
|
|
{isPending && (
|
|
|
|
<Badge className="ltr:mr-2 rtl:ml-2" variant="orange">
|
|
|
|
{t("unconfirmed")}
|
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
{booking.eventType?.team && (
|
|
|
|
<Badge className="ltr:mr-2 rtl:ml-2" variant="gray">
|
|
|
|
{booking.eventType.team.name}
|
|
|
|
</Badge>
|
|
|
|
)}
|
2022-11-29 18:28:02 +00:00
|
|
|
{booking.paid && (
|
|
|
|
<Badge className="ltr:mr-2 rtl:ml-2" variant="green">
|
2023-04-11 21:44:14 +00:00
|
|
|
{booking.payment[0].paymentOption === "HOLD" ? t("card_held") : t("paid")}
|
2022-11-29 18:28:02 +00:00
|
|
|
</Badge>
|
|
|
|
)}
|
2022-11-04 16:43:02 +00:00
|
|
|
{recurringDates !== undefined && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-muted mt-2 text-sm">
|
2022-11-04 16:43:02 +00:00
|
|
|
<RecurringBookingsTooltip booking={booking} recurringDates={recurringDates} />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-05-05 21:16:25 +00:00
|
|
|
</div>
|
2022-02-09 18:25:58 +00:00
|
|
|
</td>
|
2022-10-19 09:45:44 +00:00
|
|
|
<td className={"w-full px-4" + (isRejected ? " line-through" : "")} onClick={onClickTableData}>
|
2022-09-27 23:51:41 +00:00
|
|
|
{/* Time and Badges for mobile */}
|
|
|
|
<div className="w-full pt-4 pb-2 sm:hidden">
|
|
|
|
<div className="flex w-full items-center justify-between sm:hidden">
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-emphasis text-sm leading-6">{startTime}</div>
|
|
|
|
<div className="text-subtle pr-2 text-sm">
|
2022-10-19 09:45:44 +00:00
|
|
|
{formatTime(booking.startTime, user?.timeFormat, user?.timeZone)} -{" "}
|
|
|
|
{formatTime(booking.endTime, user?.timeFormat, user?.timeZone)}
|
|
|
|
<MeetingTimeInTimezones
|
|
|
|
timeFormat={user?.timeFormat}
|
|
|
|
userTimezone={user?.timeZone}
|
|
|
|
startTime={booking.startTime}
|
|
|
|
endTime={booking.endTime}
|
|
|
|
attendees={booking.attendees}
|
|
|
|
/>
|
2022-09-27 23:51:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{isPending && (
|
|
|
|
<Badge className="ltr:mr-2 rtl:ml-2 sm:hidden" variant="orange">
|
|
|
|
{t("unconfirmed")}
|
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
{booking.eventType?.team && (
|
|
|
|
<Badge className="ltr:mr-2 rtl:ml-2 sm:hidden" variant="gray">
|
|
|
|
{booking.eventType.team.name}
|
|
|
|
</Badge>
|
|
|
|
)}
|
2022-09-09 15:02:31 +00:00
|
|
|
{!!booking?.eventType?.price && !booking.paid && (
|
2022-09-27 23:51:41 +00:00
|
|
|
<Badge className="ltr:mr-2 rtl:ml-2 sm:hidden" variant="orange">
|
2022-09-09 15:02:31 +00:00
|
|
|
{t("pending_payment")}
|
|
|
|
</Badge>
|
|
|
|
)}
|
2022-11-04 16:43:02 +00:00
|
|
|
{recurringDates !== undefined && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-muted text-sm sm:hidden">
|
2022-11-04 16:43:02 +00:00
|
|
|
<RecurringBookingsTooltip booking={booking} recurringDates={recurringDates} />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-09-27 23:51:41 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="cursor-pointer py-4">
|
2022-05-27 23:27:41 +00:00
|
|
|
<div
|
2023-03-03 16:35:11 +00:00
|
|
|
title={title}
|
2022-05-27 23:27:41 +00:00
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
"max-w-10/12 sm:max-w-56 text-emphasis text-sm font-medium leading-6 md:max-w-full",
|
2022-05-27 23:27:41 +00:00
|
|
|
isCancelled ? "line-through" : ""
|
|
|
|
)}>
|
2023-03-03 16:35:11 +00:00
|
|
|
{title}
|
2022-09-12 20:41:59 +00:00
|
|
|
<span> </span>
|
|
|
|
|
|
|
|
{!!booking?.eventType?.price && !booking.paid && (
|
2023-04-09 09:13:57 +00:00
|
|
|
<Badge className="ms-2 me-2 hidden sm:inline-flex" variant="orange">
|
2022-12-19 16:59:11 +00:00
|
|
|
{t("pending_payment")}
|
|
|
|
</Badge>
|
2022-09-12 20:41:59 +00:00
|
|
|
)}
|
2022-05-27 23:27:41 +00:00
|
|
|
</div>
|
|
|
|
{booking.description && (
|
|
|
|
<div
|
2023-04-05 18:14:46 +00:00
|
|
|
className="max-w-10/12 sm:max-w-32 md:max-w-52 xl:max-w-80 text-default truncate text-sm"
|
2022-05-27 23:27:41 +00:00
|
|
|
title={booking.description}>
|
|
|
|
"{booking.description}"
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{booking.attendees.length !== 0 && (
|
2022-09-12 20:41:59 +00:00
|
|
|
<DisplayAttendees
|
|
|
|
attendees={booking.attendees}
|
|
|
|
user={booking.user}
|
|
|
|
currentEmail={user?.email}
|
|
|
|
/>
|
2022-02-09 18:25:58 +00:00
|
|
|
)}
|
2022-05-27 23:27:41 +00:00
|
|
|
{isCancelled && booking.rescheduled && (
|
2023-03-14 12:34:41 +00:00
|
|
|
<div className="mt-2 inline-block md:hidden">
|
2022-05-27 23:27:41 +00:00
|
|
|
<RequestSentMessage />
|
|
|
|
</div>
|
2022-02-09 18:25:58 +00:00
|
|
|
)}
|
2021-09-30 10:46:39 +00:00
|
|
|
</div>
|
2022-02-09 18:25:58 +00:00
|
|
|
</td>
|
2023-03-14 12:34:41 +00:00
|
|
|
<td className="flex w-full justify-end py-4 pl-4 text-right text-sm font-medium ltr:pr-4 rtl:pl-4 sm:pl-0">
|
2022-02-09 18:25:58 +00:00
|
|
|
{isUpcoming && !isCancelled ? (
|
|
|
|
<>
|
2022-06-06 16:54:47 +00:00
|
|
|
{isPending && user?.id === booking.user?.id && <TableActions actions={pendingActions} />}
|
|
|
|
{isConfirmed && <TableActions actions={bookedActions} />}
|
2023-04-05 18:14:46 +00:00
|
|
|
{isRejected && <div className="text-subtle text-sm">{t("rejected")}</div>}
|
2022-02-09 18:25:58 +00:00
|
|
|
</>
|
|
|
|
) : null}
|
2022-09-14 11:02:26 +00:00
|
|
|
{isPast && isPending && !isConfirmed ? <TableActions actions={bookedActions} /> : null}
|
2022-12-27 21:03:39 +00:00
|
|
|
{showRecordingsButtons && <TableActions actions={showRecordingActions} />}
|
2022-04-14 21:25:24 +00:00
|
|
|
{isCancelled && booking.rescheduled && (
|
|
|
|
<div className="hidden h-full items-center md:flex">
|
|
|
|
<RequestSentMessage />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-04-11 21:44:14 +00:00
|
|
|
{booking.status === "ACCEPTED" && booking.paid && booking?.payment[0]?.paymentOption === "HOLD" && (
|
|
|
|
<div className="ml-2">
|
|
|
|
<TableActions actions={chargeCardActions} />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-02-09 18:25:58 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</>
|
2021-09-30 10:46:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:51:41 +00:00
|
|
|
interface RecurringBookingsTooltipProps {
|
|
|
|
booking: BookingItemProps;
|
|
|
|
recurringDates: Date[];
|
|
|
|
}
|
|
|
|
|
2022-10-24 22:37:55 +00:00
|
|
|
const RecurringBookingsTooltip = ({ booking, recurringDates }: RecurringBookingsTooltipProps) => {
|
|
|
|
// Get user so we can determine 12/24 hour format preferences
|
|
|
|
const query = useMeQuery();
|
|
|
|
const user = query.data;
|
2023-03-17 08:12:51 +00:00
|
|
|
const {
|
|
|
|
t,
|
|
|
|
i18n: { language },
|
|
|
|
} = useLocale();
|
2022-10-06 19:23:22 +00:00
|
|
|
const now = new Date();
|
2022-10-24 22:37:55 +00:00
|
|
|
const recurringCount = recurringDates.filter((date) => {
|
2022-11-04 16:43:02 +00:00
|
|
|
return (
|
|
|
|
date >= now &&
|
|
|
|
!booking.recurringInfo?.bookings[BookingStatus.CANCELLED]
|
|
|
|
.map((date) => date.toDateString())
|
|
|
|
.includes(date.toDateString())
|
|
|
|
);
|
2022-10-24 22:37:55 +00:00
|
|
|
}).length;
|
2022-09-27 23:51:41 +00:00
|
|
|
|
|
|
|
return (
|
2022-11-04 16:43:02 +00:00
|
|
|
(booking.recurringInfo &&
|
2022-09-27 23:51:41 +00:00
|
|
|
booking.eventType?.recurringEvent?.freq &&
|
2022-10-06 19:23:22 +00:00
|
|
|
(booking.listingStatus === "recurring" ||
|
|
|
|
booking.listingStatus === "unconfirmed" ||
|
|
|
|
booking.listingStatus === "cancelled") && (
|
2022-09-27 23:51:41 +00:00
|
|
|
<div className="underline decoration-gray-400 decoration-dashed underline-offset-2">
|
|
|
|
<div className="flex">
|
|
|
|
<Tooltip
|
2022-11-04 16:43:02 +00:00
|
|
|
content={recurringDates.map((aDate, key) => {
|
|
|
|
const pastOrCancelled =
|
|
|
|
aDate < now ||
|
|
|
|
booking.recurringInfo?.bookings[BookingStatus.CANCELLED]
|
|
|
|
.map((date) => date.toDateString())
|
|
|
|
.includes(aDate.toDateString());
|
|
|
|
return (
|
|
|
|
<p key={key} className={classNames(pastOrCancelled && "line-through")}>
|
|
|
|
{formatTime(aDate, user?.timeFormat, user?.timeZone)}
|
|
|
|
{" - "}
|
2023-03-17 08:12:51 +00:00
|
|
|
{dayjs(aDate).locale(language).format("D MMMM YYYY")}
|
2022-11-04 16:43:02 +00:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
})}>
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-default">
|
2023-04-12 15:26:31 +00:00
|
|
|
<RefreshCcw
|
2022-09-27 23:51:41 +00:00
|
|
|
strokeWidth="3"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="text-muted float-left mr-1 mt-1.5 inline-block h-3 w-3"
|
2022-09-27 23:51:41 +00:00
|
|
|
/>
|
|
|
|
<p className="mt-1 pl-5 text-xs">
|
|
|
|
{booking.status === BookingStatus.ACCEPTED
|
|
|
|
? `${t("event_remaining", {
|
2022-10-24 22:37:55 +00:00
|
|
|
count: recurringCount,
|
2022-09-27 23:51:41 +00:00
|
|
|
})}`
|
|
|
|
: getEveryFreqFor({
|
|
|
|
t,
|
|
|
|
recurringEvent: booking.eventType.recurringEvent,
|
2022-11-04 16:43:02 +00:00
|
|
|
recurringCount: booking.recurringInfo.count,
|
2022-09-27 23:51:41 +00:00
|
|
|
})}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)) ||
|
|
|
|
null
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-09-12 20:41:59 +00:00
|
|
|
interface UserProps {
|
|
|
|
id: number;
|
|
|
|
name: string | null;
|
|
|
|
email: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FirstAttendee = ({
|
|
|
|
user,
|
|
|
|
currentEmail,
|
|
|
|
}: {
|
|
|
|
user: UserProps;
|
|
|
|
currentEmail: string | null | undefined;
|
|
|
|
}) => {
|
2022-11-15 13:39:06 +00:00
|
|
|
const { t } = useLocale();
|
2022-09-12 20:41:59 +00:00
|
|
|
return user.email === currentEmail ? (
|
2022-11-15 13:39:06 +00:00
|
|
|
<div className="inline-block">{t("you")}</div>
|
2022-09-12 20:41:59 +00:00
|
|
|
) : (
|
|
|
|
<a
|
|
|
|
key={user.email}
|
|
|
|
className=" hover:text-blue-500"
|
|
|
|
href={"mailto:" + user.email}
|
|
|
|
onClick={(e) => e.stopPropagation()}>
|
|
|
|
{user.name}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-11-15 13:39:06 +00:00
|
|
|
type AttendeeProps = {
|
|
|
|
name?: string;
|
|
|
|
email: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Attendee = ({ email, name }: AttendeeProps) => {
|
2022-09-12 20:41:59 +00:00
|
|
|
return (
|
2022-11-15 13:39:06 +00:00
|
|
|
<a className="hover:text-blue-500" href={"mailto:" + email} onClick={(e) => e.stopPropagation()}>
|
|
|
|
{name || email}
|
2022-09-12 20:41:59 +00:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const DisplayAttendees = ({
|
|
|
|
attendees,
|
|
|
|
user,
|
|
|
|
currentEmail,
|
|
|
|
}: {
|
|
|
|
attendees: AttendeeProps[];
|
|
|
|
user: UserProps | null;
|
2022-11-15 13:39:06 +00:00
|
|
|
currentEmail?: string | null;
|
2022-09-12 20:41:59 +00:00
|
|
|
}) => {
|
2022-11-15 13:39:06 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-emphasis text-sm">
|
2022-11-15 13:39:06 +00:00
|
|
|
{user && <FirstAttendee user={user} currentEmail={currentEmail} />}
|
|
|
|
{attendees.length > 1 ? <span>, </span> : <span> {t("and")} </span>}
|
|
|
|
<Attendee {...attendees[0]} />
|
|
|
|
{attendees.length > 1 && (
|
|
|
|
<>
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-emphasis inline-block text-sm"> {t("and")} </div>
|
2022-11-15 13:39:06 +00:00
|
|
|
{attendees.length > 2 ? (
|
|
|
|
<Tooltip
|
|
|
|
content={attendees.slice(1).map((attendee) => (
|
|
|
|
<p key={attendee.email}>
|
|
|
|
<Attendee {...attendee} />
|
|
|
|
</p>
|
|
|
|
))}>
|
|
|
|
<div className="inline-block">{t("plus_more", { count: attendees.length - 1 })}</div>
|
|
|
|
</Tooltip>
|
|
|
|
) : (
|
|
|
|
<Attendee {...attendees[1]} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2022-09-12 20:41:59 +00:00
|
|
|
};
|
|
|
|
|
2021-09-30 10:46:39 +00:00
|
|
|
export default BookingListItem;
|