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
|
|
|
|
2022-08-26 00:48:50 +00:00
|
|
|
import { EventLocationType, getEventLocationType } from "@calcom/app-store/locations";
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
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";
|
2022-11-10 23:40:01 +00:00
|
|
|
import { RouterInputs, RouterOutputs, trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Badge,
|
|
|
|
Button,
|
|
|
|
Dialog,
|
|
|
|
DialogClose,
|
|
|
|
DialogContent,
|
|
|
|
DialogFooter,
|
|
|
|
DialogHeader,
|
|
|
|
Icon,
|
|
|
|
MeetingTimeInTimezones,
|
|
|
|
showToast,
|
|
|
|
TextArea,
|
|
|
|
Tooltip,
|
2022-12-27 21:03:39 +00:00
|
|
|
ActionType,
|
|
|
|
TableActions,
|
2022-11-23 02:55:25 +00:00
|
|
|
} from "@calcom/ui";
|
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
|
|
|
|
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;
|
2022-11-04 16:43:02 +00:00
|
|
|
const { t } = 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);
|
2022-12-27 21:03:39 +00:00
|
|
|
const [viewRecordingsDialogIsOpen, setViewRecordingsDialogIsOpen] = useState<boolean>(false);
|
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) => {
|
|
|
|
if (data.status === BookingStatus.REJECTED) {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
},
|
2022-08-03 16:01:29 +00:00
|
|
|
icon: Icon.FiSlash,
|
2021-09-30 10:46:39 +00:00
|
|
|
disabled: mutation.isLoading,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "confirm",
|
2022-10-06 19:23:22 +00:00
|
|
|
label: (isTabRecurring || isTabUnconfirmed) && isRecurring ? t("confirm_all") : t("confirm"),
|
2022-05-27 23:27:41 +00:00
|
|
|
onClick: () => {
|
2022-08-26 21:58:08 +00:00
|
|
|
bookingConfirm(true);
|
2022-05-18 21:05:49 +00:00
|
|
|
},
|
2022-08-03 16:01:29 +00:00
|
|
|
icon: Icon.FiCheck,
|
2021-09-30 10:46:39 +00:00
|
|
|
disabled: mutation.isLoading,
|
|
|
|
color: "primary",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
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" : ""
|
|
|
|
}`,
|
2022-08-03 16:01:29 +00:00
|
|
|
icon: Icon.FiX,
|
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",
|
2022-08-03 16:01:29 +00:00
|
|
|
icon: Icon.FiClock,
|
2022-05-27 23:27:41 +00:00
|
|
|
label: t("reschedule_booking"),
|
2022-04-14 21:25:24 +00:00
|
|
|
href: `/reschedule/${booking.uid}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "reschedule_request",
|
2022-08-03 16:01:29 +00:00
|
|
|
icon: Icon.FiSend,
|
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);
|
|
|
|
},
|
2022-08-03 16:01:29 +00:00
|
|
|
icon: Icon.FiMapPin,
|
2022-05-27 23:27:41 +00:00
|
|
|
},
|
2022-04-14 21:25:24 +00:00
|
|
|
],
|
2021-09-30 10:46:39 +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 (
|
2022-09-02 20:39:44 +00:00
|
|
|
<div className="ml-1 mr-8 flex text-gray-500" data-testid="request_reschedule_sent">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiSend className="-mt-[1px] w-4 rotate-45" />
|
2022-04-14 21:25:24 +00:00
|
|
|
<p className="ml-2 ">{t("reschedule_request_sent")}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2021-09-30 10:46:39 +00:00
|
|
|
|
2022-04-14 21:25:24 +00:00
|
|
|
const startTime = dayjs(booking.startTime).format(isUpcoming ? "ddd, D MMM" : "D MMMM YYYY");
|
|
|
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2022-12-27 21:03:39 +00:00
|
|
|
const showRecordingsButtons = booking.location === "integrations:daily" && 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}
|
|
|
|
/>
|
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}>
|
|
|
|
<DialogContent>
|
|
|
|
<DialogHeader title={t("rejection_reason_title")} />
|
|
|
|
|
|
|
|
<p className="-mt-4 text-sm text-gray-500">{t("rejection_reason_description")}</p>
|
|
|
|
<p className="mt-6 mb-2 text-sm font-bold text-black">
|
|
|
|
{t("rejection_reason")}
|
|
|
|
<span className="font-normal text-gray-500"> (Optional)</span>
|
|
|
|
</p>
|
|
|
|
<TextArea
|
|
|
|
name={t("rejection_reason")}
|
|
|
|
value={rejectionReason}
|
|
|
|
onChange={(e) => setRejectionReason(e.target.value)}
|
|
|
|
className="mb-5 sm:mb-6"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
2022-12-19 18:56:34 +00:00
|
|
|
<tr className="group flex flex-col hover:bg-neutral-50 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">
|
|
|
|
<div className="text-sm leading-6 text-gray-900">{startTime}</div>
|
|
|
|
<div className="text-sm text-gray-500">
|
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">
|
|
|
|
{t("paid")}
|
|
|
|
</Badge>
|
|
|
|
)}
|
2022-11-04 16:43:02 +00:00
|
|
|
{recurringDates !== undefined && (
|
|
|
|
<div className="mt-2 text-sm text-gray-400">
|
|
|
|
<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">
|
|
|
|
<div className="text-sm leading-6 text-gray-900">{startTime}</div>
|
|
|
|
<div className="pr-2 text-sm text-gray-500">
|
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 && (
|
|
|
|
<div className="text-sm text-gray-400 sm:hidden">
|
|
|
|
<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
|
|
|
|
title={booking.title}
|
|
|
|
className={classNames(
|
2023-01-12 16:57:43 +00:00
|
|
|
"max-w-10/12 sm:max-w-56 text-sm font-medium leading-6 text-gray-900 md:max-w-full",
|
2022-05-27 23:27:41 +00:00
|
|
|
isCancelled ? "line-through" : ""
|
|
|
|
)}>
|
|
|
|
{booking.title}
|
2022-09-12 20:41:59 +00:00
|
|
|
<span> </span>
|
|
|
|
|
|
|
|
{!!booking?.eventType?.price && !booking.paid && (
|
2023-01-04 07:38:45 +00:00
|
|
|
<Badge className="hidden ltr:ml-2 ltr:mr-2 rtl:ml-2 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
|
2022-12-17 21:49:15 +00:00
|
|
|
className="max-w-10/12 sm:max-w-32 md:max-w-52 xl:max-w-80 truncate text-sm text-gray-600"
|
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 && (
|
|
|
|
<div className="mt-2 inline-block text-left text-sm md:hidden">
|
|
|
|
<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>
|
2022-09-30 10:47:20 +00:00
|
|
|
<td className="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} />}
|
|
|
|
{isRejected && <div className="text-sm text-gray-500">{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>
|
|
|
|
)}
|
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;
|
2022-09-27 23:51:41 +00:00
|
|
|
const { t } = 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)}
|
|
|
|
{" - "}
|
|
|
|
{dayjs(aDate).format("D MMMM YYYY")}
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
})}>
|
2022-09-27 23:51:41 +00:00
|
|
|
<div className="text-gray-600 dark:text-white">
|
|
|
|
<Icon.FiRefreshCcw
|
|
|
|
strokeWidth="3"
|
|
|
|
className="float-left mr-1 mt-1.5 inline-block h-3 w-3 text-gray-400"
|
|
|
|
/>
|
|
|
|
<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 (
|
|
|
|
<div className="text-sm text-gray-900">
|
|
|
|
{user && <FirstAttendee user={user} currentEmail={currentEmail} />}
|
|
|
|
{attendees.length > 1 ? <span>, </span> : <span> {t("and")} </span>}
|
|
|
|
<Attendee {...attendees[0]} />
|
|
|
|
{attendees.length > 1 && (
|
|
|
|
<>
|
|
|
|
<div className="inline-block text-sm text-gray-900"> {t("and")} </div>
|
|
|
|
{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;
|