diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index 07ceb2ee44..b0ffea2ac6 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -2,6 +2,7 @@ import { BanIcon, CheckIcon, ClockIcon, + LocationMarkerIcon, PaperAirplaneIcon, PencilAltIcon, XIcon, @@ -16,6 +17,7 @@ import { Frequency as RRuleFrequency } from "rrule"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; +import showToast from "@calcom/lib/notification"; import Button from "@calcom/ui/Button"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/Dialog"; import { Tooltip } from "@calcom/ui/Tooltip"; @@ -23,9 +25,11 @@ import { TextArea } from "@calcom/ui/form/fields"; import { HttpError } from "@lib/core/http/error"; import useMeQuery from "@lib/hooks/useMeQuery"; +import { LocationType } from "@lib/location"; import { parseRecurringDates } from "@lib/parseDate"; import { inferQueryInput, inferQueryOutput, trpc } from "@lib/trpc"; +import { EditLocationDialog } from "@components/dialog/EditLocationDialog"; import { RescheduleDialog } from "@components/dialog/RescheduleDialog"; import TableActions, { ActionType } from "@components/ui/TableActions"; @@ -72,6 +76,7 @@ function BookingListItem(booking: BookingItemProps) { if (!res.ok) { throw new HttpError({ statusCode: res.status }); } + setRejectionDialogIsOpen(false); }, { async onSettled() { @@ -89,8 +94,7 @@ function BookingListItem(booking: BookingItemProps) { booking.listingStatus === "upcoming" && booking.recurringEventId !== null ? t("reject_all") : t("reject"), - onClick: (e) => { - e.stopPropagation(); + onClick: () => { setRejectionDialogIsOpen(true); }, icon: BanIcon, @@ -102,8 +106,7 @@ function BookingListItem(booking: BookingItemProps) { booking.listingStatus === "upcoming" && booking.recurringEventId !== null ? t("confirm_all") : t("confirm"), - onClick: (e) => { - e.stopPropagation(); + onClick: () => { mutation.mutate(true); }, icon: CheckIcon, @@ -120,25 +123,33 @@ function BookingListItem(booking: BookingItemProps) { icon: XIcon, }, { - id: "reschedule", - label: t("reschedule"), - icon: ClockIcon, + id: "edit_booking", + label: t("edit_booking"), + icon: PencilAltIcon, actions: [ { - id: "edit", - icon: PencilAltIcon, - label: t("edit_booking"), + id: "reschedule", + icon: ClockIcon, + label: t("reschedule_booking"), href: `/reschedule/${booking.uid}`, }, { id: "reschedule_request", - icon: ClockIcon, + icon: PaperAirplaneIcon, + iconClassName: "rotate-45 w-[18px] -ml-[2px]", label: t("send_reschedule_request"), - onClick: (e) => { - e.stopPropagation(); + onClick: () => { setIsOpenRescheduleDialog(true); }, }, + { + id: "change_location", + label: t("edit_location"), + onClick: () => { + setIsOpenLocationDialog(true); + }, + icon: LocationMarkerIcon, + }, ], }, ]; @@ -154,6 +165,26 @@ function BookingListItem(booking: BookingItemProps) { const startTime = dayjs(booking.startTime).format(isUpcoming ? "ddd, D MMM" : "D MMMM YYYY"); const [isOpenRescheduleDialog, setIsOpenRescheduleDialog] = useState(false); + const [isOpenSetLocationDialog, setIsOpenLocationDialog] = useState(false); + const setLocationMutation = trpc.useMutation("viewer.bookings.editLocation", { + onSuccess: () => { + showToast(t("location_updated"), "success"); + setIsOpenLocationDialog(false); + utils.invalidateQueries("viewer.bookings"); + }, + }); + + const saveLocation = (newLocationType: LocationType, details: { [key: string]: string }) => { + let newLocation = newLocationType as string; + if ( + newLocationType === LocationType.InPerson || + newLocationType === LocationType.Link || + newLocationType === LocationType.UserPhone + ) { + newLocation = details[Object.keys(details)[0]]; + } + setLocationMutation.mutate({ bookingId: booking.id, newLocation }); + }; // Calculate the booking date(s) let recurringStrings: string[] = []; @@ -168,6 +199,28 @@ function BookingListItem(booking: BookingItemProps) { ); } + const onClick = () => { + router.push({ + pathname: "/success", + query: { + date: booking.startTime, + type: booking.eventType.id, + eventSlug: booking.eventType.slug, + user: user?.username || "", + name: booking.attendees[0].name, + email: booking.attendees[0].email, + location: booking.location + ? booking.location.includes("integration") + ? (t("web_conferencing_details_to_follow") as string) + : booking.location + : "", + eventName: booking.eventType.eventName || "", + bookingId: booking.id, + recur: booking.recurringEventId, + reschedule: booking.confirmed, + }, + }); + }; return ( <> + {/* NOTE: Should refactor this dialog component as is being rendered multiple times */} @@ -209,115 +268,103 @@ function BookingListItem(booking: BookingItemProps) { - - router.push({ - pathname: "/success", - query: { - date: booking.startTime, - type: booking.eventType.id, - eventSlug: booking.eventType.slug, - user: user?.username || "", - name: booking.attendees[0].name, - email: booking.attendees[0].email, - location: booking.location - ? booking.location.includes("integration") - ? (t("web_conferencing_details_to_follow") as string) - : booking.location - : "", - eventName: booking.eventType.eventName || "", - bookingId: booking.id, - recur: booking.recurringEventId, - reschedule: booking.confirmed, - status: booking.listingStatus, - }, - }) - }> - -
{startTime}
-
- {dayjs(booking.startTime).format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")} -{" "} - {dayjs(booking.endTime).format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")} -
-
- {booking.recurringCount && - booking.eventType?.recurringEvent?.freq && - booking.listingStatus === "upcoming" && ( -
-
- ( -

{aDate}

- ))}> -

- - {`${t("every_for_freq", { - freq: t( + + +

+
{startTime}
+
+ {dayjs(booking.startTime).format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")} -{" "} + {dayjs(booking.endTime).format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")} +
+
+ {booking.recurringCount && + booking.eventType?.recurringEvent?.freq && + booking.listingStatus === "upcoming" && ( +
+
+ ( +

{aDate}

+ ))}> +

+ + {`${t("every_for_freq", { + freq: t( + `${RRuleFrequency[booking.eventType.recurringEvent.freq] + .toString() + .toLowerCase()}` + ), + })} ${booking.recurringCount} ${t( `${RRuleFrequency[booking.eventType.recurringEvent.freq] .toString() - .toLowerCase()}` - ), - })} ${booking.recurringCount} ${t( - `${RRuleFrequency[booking.eventType.recurringEvent.freq].toString().toLowerCase()}`, - { count: booking.recurringCount } - )}`} -

-
+ .toLowerCase()}`, + { count: booking.recurringCount } + )}`} +

+ +
-
- )} + )} +
- -
- {!booking.confirmed && !booking.rejected && ( - {t("unconfirmed")} - )} - {!!booking?.eventType?.price && !booking.paid && ( - Pending payment - )} -
- {startTime}:{" "} - - {dayjs(booking.startTime).format("HH:mm")} - {dayjs(booking.endTime).format("HH:mm")} - + +
+
+ {!booking.confirmed && !booking.rejected && ( + {t("unconfirmed")} + )} + {!!booking?.eventType?.price && !booking.paid && ( + Pending payment + )} +
+ {startTime}:{" "} + + {dayjs(booking.startTime).format("HH:mm")} - {dayjs(booking.endTime).format("HH:mm")} + +
-
-
- {booking.eventType?.team && {booking.eventType.team.name}: } - {booking.title} - {!!booking?.eventType?.price && !booking.paid && ( - Pending payment - )} - {!booking.confirmed && !booking.rejected && ( - {t("unconfirmed")} - )} -
- {booking.description && ( -
- "{booking.description}" +
+ {booking.eventType?.team && {booking.eventType.team.name}: } + {booking.title} + {!!booking?.eventType?.price && !booking.paid && ( + Pending payment + )} + {!booking.confirmed && !booking.rejected && ( + {t("unconfirmed")} + )}
- )} + {booking.description && ( +
+ "{booking.description}" +
+ )} - {booking.attendees.length !== 0 && ( - e.stopPropagation()}> - {booking.attendees[0].email} - - )} - {isCancelled && booking.rescheduled && ( -
- -
- )} + {booking.attendees.length !== 0 && ( + e.stopPropagation()}> + {booking.attendees[0].email} + + )} + {isCancelled && booking.rescheduled && ( +
+ +
+ )} +
diff --git a/apps/web/components/booking/pages/AvailabilityPage.tsx b/apps/web/components/booking/pages/AvailabilityPage.tsx index 4a23427d27..fcea4866b7 100644 --- a/apps/web/components/booking/pages/AvailabilityPage.tsx +++ b/apps/web/components/booking/pages/AvailabilityPage.tsx @@ -68,6 +68,8 @@ export const locationKeyToString = (location: LocationObject, t: TFunction) => { case LocationType.Link: return location.link || "Link"; // If disabled link won't exist on the object case LocationType.Phone: + return t("your_number"); + case LocationType.UserPhone: return t("phone_call"); case LocationType.GoogleMeet: return "Google Meet"; @@ -370,7 +372,9 @@ const AvailabilityPage = ({ profile, plan, eventType, workingHours, previousPage return ( {locationKeyToString(el, t)}{" "} - {arr.length - 1 !== i && or } + {arr.length - 1 !== i && ( + {t("or_lowercase")} + )} ); })} @@ -424,7 +428,7 @@ const AvailabilityPage = ({ profile, plan, eventType, workingHours, previousPage {previousPage === `${WEBAPP_URL}/${profile.slug}` && (
router.back()} />

Go Back

diff --git a/apps/web/components/dialog/EditLocationDialog.tsx b/apps/web/components/dialog/EditLocationDialog.tsx new file mode 100644 index 0000000000..63bfb909e5 --- /dev/null +++ b/apps/web/components/dialog/EditLocationDialog.tsx @@ -0,0 +1,335 @@ +import { LocationMarkerIcon } from "@heroicons/react/solid"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { isValidPhoneNumber } from "libphonenumber-js"; +import dynamic from "next/dynamic"; +import { useEffect } from "react"; +import { Controller, useForm, useWatch } from "react-hook-form"; +import { z } from "zod"; + +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { Button } from "@calcom/ui"; +import { Dialog, DialogContent } from "@calcom/ui/Dialog"; +import { Form } from "@calcom/ui/form/fields"; + +import { QueryCell } from "@lib/QueryCell"; +import { linkValueToString } from "@lib/linkValueToString"; +import { LocationType } from "@lib/location"; +import { LocationOptionsToString } from "@lib/locationOptions"; +import { inferQueryOutput, trpc } from "@lib/trpc"; + +import CheckboxField from "@components/ui/form/CheckboxField"; +import type PhoneInputType from "@components/ui/form/PhoneInput"; +import Select from "@components/ui/form/Select"; + +const PhoneInput = dynamic( + () => import("@components/ui/form/PhoneInput") +) as unknown as typeof PhoneInputType; + +type BookingItem = inferQueryOutput<"viewer.bookings">["bookings"][number]; + +type OptionTypeBase = { + label: string; + value: LocationType; + disabled?: boolean; +}; + +type LocationFormValues = { + locationType: LocationType; + locationAddress?: string; + locationLink?: string; + locationPhoneNumber?: string; + displayLocationPublicly?: boolean; +}; +interface ISetLocationDialog { + saveLocation: (newLocationType: LocationType, details: { [key: string]: string }) => void; + selection?: OptionTypeBase; + booking?: BookingItem; + defaultValues?: { + type: LocationType; + address?: string | undefined; + link?: string | undefined; + hostPhoneNumber?: string | undefined; + displayLocationPublicly?: boolean | undefined; + }[]; + setShowLocationModal: React.Dispatch>; + isOpenDialog: boolean; + setSelectedLocation?: (param: OptionTypeBase | undefined) => void; +} + +export const EditLocationDialog = (props: ISetLocationDialog) => { + const { + saveLocation, + selection, + booking, + setShowLocationModal, + isOpenDialog, + defaultValues, + setSelectedLocation, + } = props; + const { t } = useLocale(); + const locationsQuery = trpc.useQuery(["viewer.locationOptions"]); + + useEffect(() => { + if (selection) { + locationFormMethods.setValue("locationType", selection?.value); + } + }, [selection]); + + const locationFormSchema = z.object({ + locationType: z.string(), + locationAddress: z.string().optional(), + locationLink: z.string().url().optional(), + displayLocationPublicly: z.boolean().optional(), + locationPhoneNumber: z + .string() + .refine((val) => isValidPhoneNumber(val)) + .optional(), + }); + + const locationFormMethods = useForm({ + mode: "onSubmit", + resolver: zodResolver(locationFormSchema), + }); + + const selectedLocation = useWatch({ + control: locationFormMethods.control, + name: "locationType", + }); + + const LocationOptions = + selectedLocation === LocationType.InPerson ? ( + <> +
+ +
+ location.type === LocationType.InPerson + )?.address + : undefined + } + /> +
+ {!booking && ( +
+ ( + location.type === LocationType.InPerson) + ?.displayLocationPublicly + : undefined + } + description={t("display_location_label")} + onChange={(e) => + locationFormMethods.setValue("displayLocationPublicly", e.target.checked) + } + infomationIconText={t("display_location_info_badge")}> + )} + /> +
+ )} +
+ + ) : selectedLocation === LocationType.Link ? ( +
+ +
+ location.type === LocationType.Link + )?.link + : undefined + } + /> + {locationFormMethods.formState.errors.locationLink && ( +

{t("url_start_with_https")}

+ )} +
+ {!booking && ( +
+ ( + location.type === LocationType.Link) + ?.displayLocationPublicly + : undefined + } + onChange={(e) => locationFormMethods.setValue("displayLocationPublicly", e.target.checked)} + infomationIconText={t("display_location_info_badge")}> + )} + /> +
+ )} +
+ ) : selectedLocation === LocationType.UserPhone ? ( +
+ +
+ + control={locationFormMethods.control} + name="locationPhoneNumber" + required + id="locationPhoneNumber" + placeholder={t("host_phone_number")} + defaultValue={ + defaultValues + ? defaultValues.find( + (location: { type: LocationType }) => location.type === LocationType.UserPhone + )?.hostPhoneNumber + : undefined + } + /> + {locationFormMethods.formState.errors.locationPhoneNumber && ( +

Invalid input

+ )} +
+
+ ) : ( +

{LocationOptionsToString(selectedLocation, t)}

+ ); + + return ( + + +
+
+
+ +
+
+ + {!booking && ( +

{t("this_input_will_shown_booking_this_event")}

+ )} +
+
+
+ {booking && ( + <> +

{t("current_location")}:

+

{linkValueToString(booking.location, t)}

+ + )} +
{ + const { locationType: newLocation, displayLocationPublicly } = values; + + let details = {}; + if (newLocation === LocationType.InPerson) { + details = { + address: values.locationAddress, + displayLocationPublicly, + }; + } + if (newLocation === LocationType.Link) { + details = { link: values.locationLink, displayLocationPublicly }; + } + if (newLocation === LocationType.UserPhone) { + details = { hostPhoneNumber: values.locationPhoneNumber }; + } + + saveLocation(newLocation, details); + setShowLocationModal(false); + setSelectedLocation?.(undefined); + locationFormMethods.unregister([ + "locationType", + "locationLink", + "locationAddress", + "locationPhoneNumber", + ]); + }}> + { + if (!locationOptions.length) return null; + return ( + ( + location.type === LocationType.InPerson)?.address - } - /> -
-
- ( - onChange(e.target.checked)} - infomationIconText={t("display_location_info_badge")}> - )} - /> -
-
- ); - case LocationType.Link: - return ( -
- -
- location.type === LocationType.Link) - ?.link - } - /> - {locationFormMethods.formState.errors.locationLink && ( -

- {locationFormMethods.formState.errors.locationLink.message} -

- )} -
-
- ( - onChange(e.target.checked)} - infomationIconText={t("display_location_info_badge")}> - )} - /> -
-
- ); - case LocationType.UserPhone: - return ( -
- -
- location.type === LocationType.UserPhone)?.hostPhoneNumber - } - /> - {locationFormMethods.formState.errors.locationPhoneNumber && ( -

- {locationFormMethods.formState.errors.locationPhoneNumber.message} -

- )} -
-
- ); - case LocationType.Phone: - return

{t("cal_invitee_phone_number_scheduling")}

; - /* TODO: Render this dynamically from App Store */ - case LocationType.GoogleMeet: - return

{t("cal_provide_google_meet_location")}

; - case LocationType.Zoom: - return

{t("cal_provide_zoom_meeting_url")}

; - case LocationType.Daily: - return

{t("cal_provide_video_meeting_url")}

; - case LocationType.Jitsi: - return

{t("cal_provide_jitsi_meeting_url")}

; - case LocationType.Huddle01: - return

{t("cal_provide_huddle01_meeting_url")}

; - case LocationType.Tandem: - return

{t("cal_provide_tandem_meeting_url")}

; - case LocationType.Teams: - return

{t("cal_provide_teams_meeting_url")}

; - default: - return null; - } + setShowLocationModal(false); }; const removeCustom = (index: number) => { @@ -641,7 +514,7 @@ const EventTypePage = (props: inferSSRProps) => { @@ -1312,7 +1185,7 @@ const EventTypePage = (props: inferSSRProps) => {
) => { { ) => { name="hashedLink" data-testid="generated-hash-url" type="text" - className=" grow select-none border-gray-300 bg-gray-50 text-sm text-gray-500 ltr:rounded-l-sm rtl:rounded-r-sm" + className="grow select-none border-gray-300 bg-gray-50 text-sm text-gray-500 ltr:rounded-l-sm rtl:rounded-r-sm" defaultValue={placeholderHashedLink} /> ) => { /> { if (val) onChange(val.value); }} @@ -1763,7 +1636,7 @@ const EventTypePage = (props: inferSSRProps) => { return ( ) => { id="requirePayment" name="requirePayment" type="checkbox" - className="text-primary-600 h-4 w-4 rounded border-gray-300" + className="text-primary-600 h-4 w-4 rounded border-gray-300" defaultChecked={requirePayment} />
@@ -1989,7 +1862,7 @@ const EventTypePage = (props: inferSSRProps) => { min="0.5" type="number" required - className=" block w-full rounded-sm border-gray-300 pl-2 pr-12 sm:text-sm" + className="block w-full rounded-sm border-gray-300 pl-2 pr-12 sm:text-sm" placeholder="Price" onChange={(e) => { field.onChange(e.target.valueAsNumber * 100); @@ -2142,78 +2015,16 @@ const EventTypePage = (props: inferSSRProps) => {
- - -
-
-
- -
-
- -
-

{t("this_input_will_shown_booking_this_event")}

-
-
-
- { - const { locationType: newLocation, displayLocationPublicly } = values; - let details = {}; - if (newLocation === LocationType.InPerson) { - details = { - address: values.locationAddress, - displayLocationPublicly, - }; - } - if (newLocation === LocationType.Link) { - details = { link: values.locationLink, displayLocationPublicly }; - } - if (newLocation === LocationType.UserPhone) { - details = { hostPhoneNumber: values.locationPhoneNumber }; - } - addLocation(newLocation, details); - setShowLocationModal(false); - }}> -
- ( -