2022-04-27 15:19:04 +00:00
import { zodResolver } from "@hookform/resolvers/zod" ;
2022-07-14 00:10:45 +00:00
import { EventTypeCustomInputType , WorkflowActions } from "@prisma/client" ;
2022-08-15 19:52:01 +00:00
import { SchedulingType } from "@prisma/client" ;
2022-07-06 19:01:16 +00:00
import { isValidPhoneNumber } from "libphonenumber-js" ;
2022-03-15 14:39:20 +00:00
import { useSession } from "next-auth/react" ;
2021-09-22 19:52:38 +00:00
import Head from "next/head" ;
import { useRouter } from "next/router" ;
2022-03-24 02:27:35 +00:00
import { useEffect , useMemo , useState } from "react" ;
2021-12-03 10:15:20 +00:00
import { Controller , useForm , useWatch } from "react-hook-form" ;
2021-09-22 19:52:38 +00:00
import { FormattedNumber , IntlProvider } from "react-intl" ;
2021-09-14 08:45:28 +00:00
import { ReactMultiEmail } from "react-multi-email" ;
2021-12-03 10:15:20 +00:00
import { useMutation } from "react-query" ;
2022-05-05 21:16:25 +00:00
import { v4 as uuidv4 } from "uuid" ;
2022-04-27 15:19:04 +00:00
import { z } from "zod" ;
2021-09-22 19:52:38 +00:00
2022-08-26 00:48:50 +00:00
import {
locationKeyToString ,
getEventLocationValue ,
getEventLocationType ,
EventLocationType ,
} from "@calcom/app-store/locations" ;
2022-07-28 19:58:26 +00:00
import { createPaymentLink } from "@calcom/app-store/stripepayment/lib/client" ;
2022-08-26 00:48:50 +00:00
import { LocationObject , LocationType } from "@calcom/core/location" ;
2022-06-28 20:40:58 +00:00
import dayjs from "@calcom/dayjs" ;
2022-05-27 15:37:02 +00:00
import {
useEmbedNonStylesConfig ,
useIsBackgroundTransparent ,
useIsEmbed ,
} from "@calcom/embed-core/embed-iframe" ;
2022-07-28 19:58:26 +00:00
import { useContracts } from "@calcom/features/ee/web3/contexts/contractsContext" ;
2022-07-23 00:39:50 +00:00
import CustomBranding from "@calcom/lib/CustomBranding" ;
2022-04-08 05:33:24 +00:00
import classNames from "@calcom/lib/classNames" ;
2022-04-06 17:20:30 +00:00
import { useLocale } from "@calcom/lib/hooks/useLocale" ;
2022-07-28 19:58:26 +00:00
import useTheme from "@calcom/lib/hooks/useTheme" ;
2022-03-24 02:27:35 +00:00
import { HttpError } from "@calcom/lib/http-error" ;
2022-06-10 20:38:06 +00:00
import { getEveryFreqFor } from "@calcom/lib/recurringStrings" ;
2022-07-28 19:58:26 +00:00
import { collectPageParameters , telemetryEventTypes , useTelemetry } from "@calcom/lib/telemetry" ;
2022-03-16 23:36:43 +00:00
import { Button } from "@calcom/ui/Button" ;
2022-07-27 02:24:00 +00:00
import { Icon } from "@calcom/ui/Icon" ;
2022-05-05 21:16:25 +00:00
import { Tooltip } from "@calcom/ui/Tooltip" ;
2022-07-28 19:58:26 +00:00
import PhoneInput from "@calcom/ui/form/PhoneInputLazy" ;
2022-03-16 23:36:43 +00:00
import { EmailInput , Form } from "@calcom/ui/form/fields" ;
2021-09-22 19:52:38 +00:00
2021-09-14 08:45:28 +00:00
import { asStringOrNull } from "@lib/asStringOrNull" ;
import { timeZone } from "@lib/clock" ;
2021-12-03 16:18:31 +00:00
import { ensureArray } from "@lib/ensureArray" ;
2021-09-22 19:52:38 +00:00
import createBooking from "@lib/mutations/bookings/create-booking" ;
2022-05-05 21:16:25 +00:00
import createRecurringBooking from "@lib/mutations/bookings/create-recurring-booking" ;
import { parseDate , parseRecurringDates } from "@lib/parseDate" ;
2021-12-03 10:15:20 +00:00
import slugify from "@lib/slugify" ;
2021-09-22 19:52:38 +00:00
2022-08-15 19:52:01 +00:00
import { UserAvatars } from "@components/booking/UserAvatars" ;
2021-09-22 19:52:38 +00:00
2021-09-22 18:36:13 +00:00
import { BookPageProps } from "../../../pages/[user]/book" ;
2022-04-28 15:44:26 +00:00
import { HashLinkPageProps } from "../../../pages/d/[link]/book" ;
2021-09-22 18:36:13 +00:00
import { TeamBookingPageProps } from "../../../pages/team/[slug]/book" ;
2021-09-14 08:45:28 +00:00
2022-05-17 20:43:27 +00:00
declare global {
// eslint-disable-next-line no-var
var web3 : {
currentProvider : {
selectedAddress : string ;
} ;
} ;
}
2022-08-26 00:48:50 +00:00
type BookingPageProps = BookPageProps | TeamBookingPageProps | HashLinkPageProps ;
2021-09-22 18:36:13 +00:00
2022-02-01 21:48:40 +00:00
type BookingFormValues = {
name : string ;
email : string ;
notes? : string ;
2022-08-26 00:48:50 +00:00
locationType? : EventLocationType [ "type" ] ;
2022-02-01 21:48:40 +00:00
guests? : string [ ] ;
phone? : string ;
2022-05-16 15:50:12 +00:00
hostPhoneNumber? : string ; // Maybe come up with a better way to name this to distingish between two types of phone numbers
2022-02-01 21:48:40 +00:00
customInputs ? : {
2022-05-18 21:05:49 +00:00
[ key : string ] : string | boolean ;
2022-02-01 21:48:40 +00:00
} ;
2022-05-30 19:40:29 +00:00
rescheduleReason? : string ;
2022-07-14 00:10:45 +00:00
smsReminderNumber? : string ;
2022-02-01 21:48:40 +00:00
} ;
2022-04-06 17:20:30 +00:00
const BookingPage = ( {
eventType ,
booking ,
profile ,
isDynamicGroupBooking ,
2022-05-05 21:16:25 +00:00
recurringEventCount ,
2022-04-28 15:44:26 +00:00
hasHashedBookingLink ,
hashedLink ,
2022-04-06 17:20:30 +00:00
} : BookingPageProps ) = > {
2021-10-25 13:05:21 +00:00
const { t , i18n } = useLocale ( ) ;
2022-04-08 05:33:24 +00:00
const isEmbed = useIsEmbed ( ) ;
2022-04-25 04:33:00 +00:00
const shouldAlignCentrallyInEmbed = useEmbedNonStylesConfig ( "align" ) !== "left" ;
const shouldAlignCentrally = ! isEmbed || shouldAlignCentrallyInEmbed ;
2021-09-14 08:45:28 +00:00
const router = useRouter ( ) ;
2022-02-01 21:48:40 +00:00
const { contracts } = useContracts ( ) ;
2022-03-15 14:39:20 +00:00
const { data : session } = useSession ( ) ;
2022-04-08 05:33:24 +00:00
const isBackgroundTransparent = useIsBackgroundTransparent ( ) ;
2022-05-14 13:49:39 +00:00
const telemetry = useTelemetry ( ) ;
2022-04-08 05:33:24 +00:00
2022-05-11 05:14:08 +00:00
useEffect ( ( ) = > {
2022-06-02 16:19:01 +00:00
if ( top !== window ) {
//page_view will be collected automatically by _middleware.ts
telemetry . event (
telemetryEventTypes . embedView ,
2022-05-11 05:14:08 +00:00
collectPageParameters ( "/book" , { isTeamBooking : document.URL.includes ( "team/" ) } )
2022-06-02 16:19:01 +00:00
) ;
}
2022-05-14 13:49:39 +00:00
// eslint-disable-next-line react-hooks/exhaustive-deps
2022-05-11 05:14:08 +00:00
} , [ ] ) ;
2022-02-03 23:23:20 +00:00
useEffect ( ( ) = > {
if ( eventType . metadata . smartContractAddress ) {
const eventOwner = eventType . users [ 0 ] ;
if ( ! contracts [ ( eventType . metadata . smartContractAddress || null ) as number ] )
router . replace ( ` / ${ eventOwner . username } ` ) ;
}
2022-05-14 13:49:39 +00:00
} , [ contracts , eventType . metadata . smartContractAddress , eventType . users , router ] ) ;
2022-02-03 23:23:20 +00:00
2021-12-03 10:15:20 +00:00
const mutation = useMutation ( createBooking , {
2022-02-18 16:53:45 +00:00
onSuccess : async ( responseData ) = > {
2022-05-06 14:15:05 +00:00
const { id , attendees , paymentUid } = responseData ;
2021-12-03 10:15:20 +00:00
if ( paymentUid ) {
return await router . push (
createPaymentLink ( {
paymentUid ,
date ,
name : attendees [ 0 ] . name ,
2022-05-25 01:29:29 +00:00
email : attendees [ 0 ] . email ,
2021-12-03 10:15:20 +00:00
absolute : false ,
} )
) ;
}
return router . push ( {
pathname : "/success" ,
query : {
date ,
2022-03-15 14:39:20 +00:00
type : eventType . id ,
2022-04-06 17:20:30 +00:00
eventSlug : eventType.slug ,
2022-03-15 14:39:20 +00:00
user : profile.slug ,
2021-12-03 10:15:20 +00:00
reschedule : ! ! rescheduleUid ,
name : attendees [ 0 ] . name ,
email : attendees [ 0 ] . email ,
2022-08-26 00:48:50 +00:00
location : responseData.location ,
2022-04-08 16:50:10 +00:00
eventName : profile.eventName || "" ,
2022-05-06 14:15:05 +00:00
bookingId : id ,
2022-06-08 14:02:09 +00:00
isSuccessBookingPage : true ,
2021-12-03 10:15:20 +00:00
} ,
} ) ;
} ,
} ) ;
2022-05-05 21:16:25 +00:00
const recurringMutation = useMutation ( createRecurringBooking , {
onSuccess : async ( responseData = [ ] ) = > {
2022-05-11 07:59:49 +00:00
const { attendees = [ ] , id , recurringEventId } = responseData [ 0 ] || { } ;
2022-05-05 21:16:25 +00:00
const location = ( function humanReadableLocation ( location ) {
if ( ! location ) {
return ;
}
if ( location . includes ( "integration" ) ) {
return t ( "web_conferencing_details_to_follow" ) ;
}
return location ;
} ) ( responseData [ 0 ] . location ) ;
return router . push ( {
pathname : "/success" ,
query : {
date ,
type : eventType . id ,
eventSlug : eventType.slug ,
recur : recurringEventId ,
user : profile.slug ,
reschedule : ! ! rescheduleUid ,
name : attendees [ 0 ] . name ,
email : attendees [ 0 ] . email ,
location ,
eventName : profile.eventName || "" ,
2022-05-11 07:59:49 +00:00
bookingId : id ,
2022-05-05 21:16:25 +00:00
} ,
} ) ;
} ,
} ) ;
2021-12-03 10:15:20 +00:00
const rescheduleUid = router . query . rescheduleUid as string ;
2022-07-26 08:27:57 +00:00
useTheme ( profile . theme ) ;
2021-09-14 08:45:28 +00:00
const date = asStringOrNull ( router . query . date ) ;
2022-03-15 14:39:20 +00:00
const [ guestToggle , setGuestToggle ] = useState ( booking && booking . attendees . length > 1 ) ;
2021-09-14 08:45:28 +00:00
2022-03-15 14:39:20 +00:00
const eventTypeDetail = { isWeb3Active : false , . . . eventType } ;
2022-02-01 21:48:40 +00:00
2021-12-03 10:15:20 +00:00
// it would be nice if Prisma at some point in the future allowed for Json<Location>; as of now this is not the case.
2022-05-25 20:34:08 +00:00
const locations : LocationObject [ ] = useMemo (
( ) = > ( eventType . locations as LocationObject [ ] ) || [ ] ,
2022-03-15 14:39:20 +00:00
[ eventType . locations ]
2021-09-14 08:45:28 +00:00
) ;
2021-12-03 10:15:20 +00:00
useEffect ( ( ) = > {
if ( router . query . guest ) {
setGuestToggle ( true ) ;
}
} , [ router . query . guest ] ) ;
2021-09-14 08:45:28 +00:00
2022-05-18 21:05:49 +00:00
const loggedInIsOwner = eventType ? . users [ 0 ] ? . id === session ? . user ? . id ;
2022-04-14 21:25:24 +00:00
const guestListEmails = ! isDynamicGroupBooking
? booking ? . attendees . slice ( 1 ) . map ( ( attendee ) = > attendee . email )
: [ ] ;
2022-08-05 17:08:47 +00:00
// There should only exists one default userData variable for primaryAttendee.
const defaultUserValues = {
email : booking?.attendees [ 0 ] . email
? booking . attendees [ 0 ] . email
: router . query . email
? ( router . query . email as string )
: "" ,
name : booking?.attendees [ 0 ] . name
? booking . attendees [ 0 ] . name
: router . query . name
? ( router . query . name as string )
: "" ,
} ;
2022-01-10 23:25:06 +00:00
const defaultValues = ( ) = > {
if ( ! rescheduleUid ) {
return {
2022-08-05 17:08:47 +00:00
name : defaultUserValues.name || ( ! loggedInIsOwner && session ? . user ? . name ) || "" ,
email : defaultUserValues.email || ( ! loggedInIsOwner && session ? . user ? . email ) || "" ,
2022-01-10 23:25:06 +00:00
notes : ( router . query . notes as string ) || "" ,
guests : ensureArray ( router . query . guest ) as string [ ] ,
2022-03-15 14:39:20 +00:00
customInputs : eventType.customInputs.reduce (
2022-01-10 23:25:06 +00:00
( customInputs , input ) = > ( {
. . . customInputs ,
[ input . id ] : router . query [ slugify ( input . label ) ] ,
} ) ,
{ }
) ,
} ;
}
2022-03-15 14:39:20 +00:00
if ( ! booking || ! booking . attendees . length ) {
2022-01-10 23:25:06 +00:00
return { } ;
}
2022-03-15 14:39:20 +00:00
const primaryAttendee = booking . attendees [ 0 ] ;
2022-01-10 23:25:06 +00:00
if ( ! primaryAttendee ) {
return { } ;
}
2022-05-18 21:05:49 +00:00
const customInputType = booking . customInputs ;
2022-01-10 23:25:06 +00:00
return {
2022-08-05 17:08:47 +00:00
name : defaultUserValues.name ,
email : defaultUserValues.email || "" ,
2022-04-14 21:25:24 +00:00
guests : guestListEmails ,
notes : booking.description || "" ,
2022-05-30 19:40:29 +00:00
rescheduleReason : "" ,
2022-05-18 21:05:49 +00:00
customInputs : eventType.customInputs.reduce (
( customInputs , input ) = > ( {
. . . customInputs ,
[ input . id ] : booking . customInputs
? booking . customInputs [ input . label as keyof typeof customInputType ]
: "" ,
} ) ,
{ }
) ,
2022-01-10 23:25:06 +00:00
} ;
} ;
2022-04-27 21:21:18 +00:00
const bookingFormSchema = z
. object ( {
name : z.string ( ) . min ( 1 ) ,
email : z.string ( ) . email ( ) ,
2022-07-06 19:01:16 +00:00
phone : z
. string ( )
. refine ( ( val ) = > isValidPhoneNumber ( val ) )
. optional ( ) ,
2022-07-14 00:10:45 +00:00
smsReminderNumber : z
. string ( )
. refine ( ( val ) = > isValidPhoneNumber ( val ) )
. optional ( ) ,
2022-04-27 21:21:18 +00:00
} )
. passthrough ( ) ;
2022-04-27 15:19:04 +00:00
2021-12-03 10:15:20 +00:00
const bookingForm = useForm < BookingFormValues > ( {
2022-01-10 23:25:06 +00:00
defaultValues : defaultValues ( ) ,
2022-04-27 21:21:18 +00:00
resolver : zodResolver ( bookingFormSchema ) , // Since this isn't set to strict we only validate the fields in the schema
2021-12-03 10:15:20 +00:00
} ) ;
2021-09-14 08:45:28 +00:00
2022-08-26 00:48:50 +00:00
const selectedLocationType = useWatch ( {
2021-12-03 10:15:20 +00:00
control : bookingForm.control ,
name : "locationType" ,
2022-08-26 00:48:50 +00:00
defaultValue : ( ( ) : EventLocationType [ "type" ] | undefined = > {
2021-12-03 10:15:20 +00:00
if ( router . query . location ) {
2022-08-26 00:48:50 +00:00
return router . query . location as EventLocationType [ "type" ] ;
2021-09-14 08:45:28 +00:00
}
2021-12-03 10:15:20 +00:00
if ( locations . length === 1 ) {
return locations [ 0 ] ? . type ;
}
} ) ( ) ,
} ) ;
2021-09-14 08:45:28 +00:00
2022-08-26 00:48:50 +00:00
const selectedLocation = getEventLocationType ( selectedLocationType ) ;
const AttendeeInput =
selectedLocation ? . attendeeInputType === "text"
? "input"
: selectedLocation ? . attendeeInputType === "phone"
? PhoneInput
: null ;
2021-09-22 18:36:13 +00:00
2022-05-05 21:16:25 +00:00
// Calculate the booking date(s)
let recurringStrings : string [ ] = [ ] ,
recurringDates : Date [ ] = [ ] ;
if ( eventType . recurringEvent ? . freq && recurringEventCount !== null ) {
[ recurringStrings , recurringDates ] = parseRecurringDates (
{
startDate : date ,
2022-07-07 01:08:38 +00:00
timeZone : timeZone ( ) ,
2022-05-05 21:16:25 +00:00
recurringEvent : eventType.recurringEvent ,
recurringCount : parseInt ( recurringEventCount . toString ( ) ) ,
} ,
i18n
) ;
}
2021-12-03 10:15:20 +00:00
const bookEvent = ( booking : BookingFormValues ) = > {
2022-06-02 16:19:01 +00:00
telemetry . event (
top !== window ? telemetryEventTypes.embedBookingConfirmed : telemetryEventTypes.bookingConfirmed ,
{ isTeamBooking : document.URL.includes ( "team/" ) }
2021-12-03 10:15:20 +00:00
) ;
// "metadata" is a reserved key to allow for connecting external users without relying on the email address.
// <...url>&metadata[user_id]=123 will be send as a custom input field as the hidden type.
2022-02-01 21:48:40 +00:00
// @TODO: move to metadata
2021-12-03 10:15:20 +00:00
const metadata = Object . keys ( router . query )
. filter ( ( key ) = > key . startsWith ( "metadata" ) )
. reduce (
( metadata , key ) = > ( {
. . . metadata ,
[ key . substring ( "metadata[" . length , key . length - 1 ) ] : router . query [ key ] ,
} ) ,
{ }
) ;
2021-09-14 08:45:28 +00:00
2022-05-05 21:16:25 +00:00
let web3Details : Record < "userWallet" | "userSignature" , string > | undefined ;
2022-02-01 21:48:40 +00:00
if ( eventTypeDetail . metadata . smartContractAddress ) {
web3Details = {
2022-02-03 20:08:25 +00:00
userWallet : window.web3.currentProvider.selectedAddress ,
2022-02-01 21:48:40 +00:00
userSignature : contracts [ ( eventTypeDetail . metadata . smartContractAddress || null ) as number ] ,
} ;
}
2022-05-05 21:16:25 +00:00
if ( recurringDates . length ) {
// Identify set of bookings to one intance of recurring event to support batch changes
const recurringEventId = uuidv4 ( ) ;
const recurringBookings = recurringDates . map ( ( recurringDate ) = > ( {
. . . booking ,
web3Details ,
start : dayjs ( recurringDate ) . format ( ) ,
end : dayjs ( recurringDate ) . add ( eventType . length , "minute" ) . format ( ) ,
eventTypeId : eventType.id ,
eventTypeSlug : eventType.slug ,
recurringEventId ,
// Added to track down the number of actual occurrences selected by the user
recurringCount : recurringDates.length ,
timeZone : timeZone ( ) ,
language : i18n.language ,
rescheduleUid ,
user : router.query.user ,
2022-08-26 00:48:50 +00:00
location : getEventLocationValue ( locations , {
type : booking . locationType ? booking.locationType : selectedLocationType || "" ,
phone : booking.phone ,
} ) ,
2022-05-05 21:16:25 +00:00
metadata ,
customInputs : Object.keys ( booking . customInputs || { } ) . map ( ( inputId ) = > ( {
2022-05-17 20:43:27 +00:00
label : eventType.customInputs.find ( ( input ) = > input . id === parseInt ( inputId ) ) ? . label || "" ,
value : booking.customInputs && inputId in booking . customInputs ? booking . customInputs [ inputId ] : "" ,
2022-05-05 21:16:25 +00:00
} ) ) ,
hasHashedBookingLink ,
hashedLink ,
2022-07-14 00:10:45 +00:00
smsReminderNumber :
2022-08-26 00:48:50 +00:00
selectedLocationType === LocationType . Phone ? booking.phone : booking.smsReminderNumber ,
2022-05-05 21:16:25 +00:00
} ) ) ;
recurringMutation . mutate ( recurringBookings ) ;
} else {
mutation . mutate ( {
. . . booking ,
web3Details ,
start : dayjs ( date ) . format ( ) ,
end : dayjs ( date ) . add ( eventType . length , "minute" ) . format ( ) ,
eventTypeId : eventType.id ,
eventTypeSlug : eventType.slug ,
timeZone : timeZone ( ) ,
language : i18n.language ,
rescheduleUid ,
2022-05-24 13:19:12 +00:00
bookingUid : router.query.bookingUid as string ,
2022-05-05 21:16:25 +00:00
user : router.query.user ,
2022-08-26 00:48:50 +00:00
location : getEventLocationValue ( locations , {
type : ( booking . locationType ? booking.locationType : selectedLocationType ) || "" ,
phone : booking.phone ,
} ) ,
2022-05-05 21:16:25 +00:00
metadata ,
customInputs : Object.keys ( booking . customInputs || { } ) . map ( ( inputId ) = > ( {
2022-05-17 20:43:27 +00:00
label : eventType.customInputs.find ( ( input ) = > input . id === parseInt ( inputId ) ) ? . label || "" ,
value : booking.customInputs && inputId in booking . customInputs ? booking . customInputs [ inputId ] : "" ,
2022-05-05 21:16:25 +00:00
} ) ) ,
hasHashedBookingLink ,
hashedLink ,
2022-07-14 00:10:45 +00:00
smsReminderNumber :
2022-08-26 00:48:50 +00:00
selectedLocationType === LocationType . Phone ? booking.phone : booking.smsReminderNumber ,
2022-05-05 21:16:25 +00:00
} ) ;
}
2021-09-14 08:45:28 +00:00
} ;
2022-08-05 17:08:47 +00:00
// Should be disabled when rescheduleUid is present and data was found in defaultUserValues name/email fields.
const disableInput = ! ! rescheduleUid && ! ! defaultUserValues . email && ! ! defaultUserValues . name ;
2022-08-26 00:48:50 +00:00
const disableLocations = ! ! rescheduleUid ;
2022-05-18 21:05:49 +00:00
const disabledExceptForOwner = disableInput && ! loggedInIsOwner ;
const inputClassName =
2022-08-24 20:18:42 +00:00
"dark:placeholder:text-darkgray-600 focus:border-brand dark:border-darkgray-300 dark:text-darkgray-900 block w-full rounded-md border-gray-300 text-sm focus:ring-black disabled:bg-gray-200 disabled:hover:cursor-not-allowed dark:bg-transparent dark:selection:bg-green-500 disabled:dark:text-gray-500" ;
2022-04-14 21:25:24 +00:00
2022-07-14 00:10:45 +00:00
let isSmsReminderNumberNeeded = false ;
if ( eventType . workflows . length > 0 ) {
eventType . workflows . forEach ( ( workflowReference ) = > {
if ( workflowReference . workflow . steps . length > 0 ) {
workflowReference . workflow . steps . forEach ( ( step ) = > {
if ( step . action === WorkflowActions . SMS_ATTENDEE ) {
isSmsReminderNumberNeeded = true ;
return ;
}
} ) ;
}
} ) ;
}
2021-09-14 08:45:28 +00:00
return (
2021-09-24 22:11:30 +00:00
< div >
< Head >
< title >
2021-10-08 11:43:48 +00:00
{ rescheduleUid
? t ( "booking_reschedule_confirmation" , {
2022-03-15 14:39:20 +00:00
eventTypeTitle : eventType.title ,
profileName : profile.name ,
2021-10-08 11:43:48 +00:00
} )
: t ( "booking_confirmation" , {
2022-03-15 14:39:20 +00:00
eventTypeTitle : eventType.title ,
profileName : profile.name ,
2021-10-08 11:43:48 +00:00
} ) } { " " }
| Cal . com
2021-09-24 22:11:30 +00:00
< / title >
< link rel = "icon" href = "/favicon.ico" / >
< / Head >
2022-03-15 14:39:20 +00:00
< CustomBranding lightVal = { profile . brandColor } darkVal = { profile . darkBrandColor } / >
2022-04-08 05:33:24 +00:00
< main
2022-04-14 02:47:34 +00:00
className = { classNames (
2022-04-25 04:33:00 +00:00
shouldAlignCentrally ? "mx-auto" : "" ,
isEmbed ? "" : "sm:my-24" ,
"my-0 max-w-3xl "
2022-04-14 02:47:34 +00:00
) } >
2022-07-26 08:27:57 +00:00
< div
className = { classNames (
"main overflow-hidden" ,
isEmbed ? "" : "border border-gray-200" ,
2022-08-24 20:18:42 +00:00
isBackgroundTransparent ? "" : "dark:border-1 dark:bg-darkgray-200 bg-white" ,
"dark:border-darkgray-300 rounded-md sm:border"
2022-07-26 08:27:57 +00:00
) } >
2022-08-05 08:46:44 +00:00
< div className = "sm:flex" >
2022-08-24 20:18:42 +00:00
< div className = "sm:dark:border-darkgray-50 dark:text-darkgray-600 px-6 pt-6 pb-0 text-gray-600 sm:w-1/2 sm:border-r sm:pb-6" >
2022-08-15 19:52:01 +00:00
< UserAvatars
profile = { profile }
users = { eventType . users }
showMembers = { eventType . schedulingType !== SchedulingType . ROUND_ROBIN }
2022-07-26 08:27:57 +00:00
size = { 14 }
/ >
< h2 className = "font-cal text-bookinglight mt-2 font-medium dark:text-gray-300" >
{ profile . name }
< / h2 >
< h1 className = "text-bookingdark mb-4 text-xl font-semibold dark:text-white" >
{ eventType . title }
< / h1 >
{ ! ! eventType . seatsPerTimeSlot && (
< p
className = { ` ${
booking && booking . attendees . length / eventType . seatsPerTimeSlot >= 0.5
? "text-rose-600"
: booking && booking . attendees . length / eventType . seatsPerTimeSlot >= 0.33
? "text-yellow-500"
: "text-emerald-400"
} mb - 2 ` }>
{ booking
? eventType . seatsPerTimeSlot - booking . attendees . length
: eventType . seatsPerTimeSlot } { " " }
/ { e v e n t T y p e . s e a t s P e r T i m e S l o t } { t ( " s e a t s _ a v a i l a b l e " ) }
< / p >
) }
{ eventType ? . description && (
2022-08-24 20:18:42 +00:00
< p className = "text-bookinglight mb-2 text-sm " >
< Icon.FiInfo className = "mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" / >
2022-07-26 08:27:57 +00:00
{ eventType . description }
2021-09-14 08:45:28 +00:00
< / p >
2022-07-26 08:27:57 +00:00
) }
{ eventType ? . requiresConfirmation && (
2022-08-24 20:18:42 +00:00
< p className = "text-bookinglight mb-2 text-sm " >
< Icon.FiClipboard className = "mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" / >
2022-07-26 08:27:57 +00:00
{ t ( "requires_confirmation" ) }
< / p >
) }
2022-08-24 20:18:42 +00:00
< p className = "text-bookinglight mb-2 text-sm " >
< Icon.FiClock className = "mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" / >
2022-07-26 08:27:57 +00:00
{ eventType . length } { t ( "minutes" ) }
< / p >
{ eventType . price > 0 && (
2022-08-24 20:18:42 +00:00
< p className = "text-bookinglight mb-1 -ml-2 px-2 py-1 text-sm " >
2022-08-03 16:01:29 +00:00
< Icon.FiCreditCard className = "mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" / >
2022-07-26 08:27:57 +00:00
< IntlProvider locale = "en" >
< FormattedNumber
value = { eventType . price / 100.0 }
style = "currency"
currency = { eventType . currency . toUpperCase ( ) }
/ >
< / IntlProvider >
< / p >
) }
{ ! rescheduleUid && eventType . recurringEvent ? . freq && recurringEventCount && (
2022-08-24 20:18:42 +00:00
< div className = "mb-3 text-sm text-gray-600 " >
< Icon.FiRefreshCw className = "mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" / >
2022-07-26 08:27:57 +00:00
< p className = "mb-1 -ml-2 inline px-2 py-1" >
{ getEveryFreqFor ( {
t ,
recurringEvent : eventType.recurringEvent ,
recurringCount : recurringEventCount ,
} ) }
2021-09-22 18:36:13 +00:00
< / p >
2022-07-26 08:27:57 +00:00
< / div >
) }
2022-08-09 04:49:46 +00:00
< div className = "text-bookinghighlight mb-4 flex items-center text-sm" >
2022-08-03 16:01:29 +00:00
< Icon.FiCalendar className = "mr-[10px] ml-[2px] inline-block h-4 w-4" / >
2022-08-09 04:49:46 +00:00
< div >
2022-07-26 08:27:57 +00:00
{ ( rescheduleUid || ! eventType . recurringEvent ? . freq ) &&
parseDate ( dayjs ( date ) . tz ( timeZone ( ) ) , i18n ) }
{ ! rescheduleUid &&
eventType . recurringEvent ? . freq &&
recurringStrings . slice ( 0 , 5 ) . map ( ( aDate , key ) = > < p key = { key } > { aDate } < / p > ) }
{ ! rescheduleUid && eventType . recurringEvent ? . freq && recurringStrings . length > 5 && (
< div className = "flex" >
< Tooltip
content = { recurringStrings . slice ( 5 ) . map ( ( aDate , key ) = > (
< p key = { key } > { aDate } < / p >
) ) } >
2022-08-24 20:18:42 +00:00
< p className = "dark:text-darkgray-600 text-sm" >
2022-07-26 08:27:57 +00:00
{ t ( "plus_more" , { count : recurringStrings.length - 5 } ) }
< / p >
< / Tooltip >
< / div >
) }
< / div >
< / div >
{ eventTypeDetail . isWeb3Active && eventType . metadata . smartContractAddress && (
< p className = "text-bookinglight mb-1 -ml-2 px-2 py-1" >
{ t ( "requires_ownership_of_a_token" ) + " " + eventType . metadata . smartContractAddress }
< / p >
) }
{ booking ? . startTime && rescheduleUid && (
< div >
2022-08-24 20:18:42 +00:00
< p className = "mt-8 mb-2 text-sm " data - testid = "former_time_p" >
2022-07-26 08:27:57 +00:00
{ t ( "former_time" ) }
< / p >
2022-08-24 20:18:42 +00:00
< p className = "line-through " >
< Icon.FiCalendar className = "mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" / >
2022-07-26 08:27:57 +00:00
{ typeof booking . startTime === "string" && parseDate ( dayjs ( booking . startTime ) , i18n ) }
< / p >
< / div >
) }
< / div >
2022-08-05 08:46:44 +00:00
< div className = "p-6 sm:w-1/2" >
2022-07-26 08:27:57 +00:00
< Form form = { bookingForm } handleSubmit = { bookEvent } >
< div className = "mb-4" >
< label htmlFor = "name" className = "block text-sm font-medium text-gray-700 dark:text-white" >
{ t ( "your_name" ) }
< / label >
< div className = "mt-1" >
< input
{ . . . bookingForm . register ( "name" , { required : true } ) }
type = "text"
name = "name"
id = "name"
required
className = { inputClassName }
placeholder = { t ( "example_name" ) }
disabled = { disableInput }
/ >
2022-05-05 21:16:25 +00:00
< / div >
2022-07-26 08:27:57 +00:00
< / div >
< div className = "mb-4" >
< label htmlFor = "email" className = "block text-sm font-medium text-gray-700 dark:text-white" >
{ t ( "email_address" ) }
< / label >
< div className = "mt-1" >
< EmailInput
{ . . . bookingForm . register ( "email" ) }
required
className = { classNames (
inputClassName ,
bookingForm . formState . errors . email
? "border-red-700 focus:ring-red-700"
: " border-gray-300 dark:border-gray-900"
) }
placeholder = "you@example.com"
type = "search" // Disables annoying 1password intrusive popup (non-optimal, I know I know...)
disabled = { disableInput }
/ >
{ bookingForm . formState . errors . email && (
< div className = "mt-2 flex items-center text-sm text-red-700 " >
2022-08-03 16:01:29 +00:00
< Icon.FiInfo className = "mr-2 h-3 w-3" / >
2022-07-26 08:27:57 +00:00
< p > { t ( "email_validation_error" ) } < / p >
2022-05-05 21:16:25 +00:00
< / div >
) }
< / div >
< / div >
2022-07-26 08:27:57 +00:00
{ locations . length > 1 && (
2021-09-14 08:45:28 +00:00
< div className = "mb-4" >
2022-07-26 08:27:57 +00:00
< span className = "block text-sm font-medium text-gray-700 dark:text-white" >
{ t ( "location" ) }
< / span >
2022-08-26 00:48:50 +00:00
{ locations . map ( ( location , i ) = > {
const locationString = locationKeyToString ( location ) ;
// TODO: Right now selectedLocationType isn't send by getSSP. Once that's available defaultChecked should work and show the location in the original booking
const defaultChecked = rescheduleUid ? selectedLocationType === location.type : i === 0 ;
if ( typeof locationString !== "string" ) {
// It's possible that location app got uninstalled
return null ;
}
return (
< label key = { i } className = "block" >
< input
type = "radio"
disabled = { ! ! disableLocations }
className = "location h-4 w-4 border-gray-300 text-black focus:ring-black ltr:mr-2 rtl:ml-2"
{ . . . bookingForm . register ( "locationType" , { required : true } ) }
value = { location . type }
defaultChecked = { defaultChecked }
/ >
< span className = "text-sm ltr:ml-2 rtl:mr-2 dark:text-gray-500" >
{ locationKeyToString ( location ) }
< / span >
< / label >
) ;
} ) }
2021-09-14 08:45:28 +00:00
< / div >
2022-07-26 08:27:57 +00:00
) }
2022-08-26 00:48:50 +00:00
{ /* TODO: Change name and id ="phone" to something generic */ }
{ AttendeeInput && (
2021-09-14 08:45:28 +00:00
< div className = "mb-4" >
< label
2022-07-26 08:27:57 +00:00
htmlFor = "phone"
2021-10-12 08:29:12 +00:00
className = "block text-sm font-medium text-gray-700 dark:text-white" >
2022-07-26 08:27:57 +00:00
{ t ( "phone_number" ) }
2021-09-14 08:45:28 +00:00
< / label >
< div className = "mt-1" >
2022-08-26 00:48:50 +00:00
< AttendeeInput < BookingFormValues >
2022-07-26 08:27:57 +00:00
control = { bookingForm . control }
name = "phone"
2022-08-26 00:48:50 +00:00
placeholder = { t ( selectedLocation ? . attendeeInputPlaceholder || "" ) }
2022-07-26 08:27:57 +00:00
id = "phone"
2021-09-14 08:45:28 +00:00
required
2022-04-14 21:25:24 +00:00
disabled = { disableInput }
2021-09-14 08:45:28 +00:00
/ >
< / div >
2022-07-26 08:27:57 +00:00
{ bookingForm . formState . errors . phone && (
< div className = "mt-2 flex items-center text-sm text-red-700 " >
2022-08-03 16:01:29 +00:00
< Icon.FiInfo className = "mr-2 h-3 w-3" / >
2022-07-26 08:27:57 +00:00
< p > { t ( "invalid_number" ) } < / p >
< / div >
) }
2021-09-14 08:45:28 +00:00
< / div >
2022-07-26 08:27:57 +00:00
) }
{ eventType . customInputs
. sort ( ( a , b ) = > a . id - b . id )
. map ( ( input ) = > (
< div className = "mb-4" key = { input . id } >
{ input . type !== EventTypeCustomInputType . BOOL && (
< label
htmlFor = { "custom_" + input . id }
className = "mb-1 block text-sm font-medium text-gray-700 dark:text-white" >
{ input . label }
2021-09-14 08:45:28 +00:00
< / label >
2022-07-26 08:27:57 +00:00
) }
{ input . type === EventTypeCustomInputType . TEXTLONG && (
< textarea
{ . . . bookingForm . register ( ` customInputs. ${ input . id } ` , {
required : input.required ,
} ) }
id = { "custom_" + input . id }
rows = { 3 }
className = { inputClassName }
placeholder = { input . placeholder }
disabled = { disabledExceptForOwner }
2022-03-03 09:57:59 +00:00
/ >
2022-07-06 19:01:16 +00:00
) }
2022-07-26 08:27:57 +00:00
{ input . type === EventTypeCustomInputType . TEXT && (
< input
type = "text"
{ . . . bookingForm . register ( ` customInputs. ${ input . id } ` , {
required : input.required ,
} ) }
id = { "custom_" + input . id }
className = { inputClassName }
placeholder = { input . placeholder }
disabled = { disabledExceptForOwner }
/ >
) }
{ input . type === EventTypeCustomInputType . NUMBER && (
< input
type = "number"
{ . . . bookingForm . register ( ` customInputs. ${ input . id } ` , {
required : input.required ,
} ) }
id = { "custom_" + input . id }
className = { inputClassName }
placeholder = ""
disabled = { disabledExceptForOwner }
/ >
) }
{ input . type === EventTypeCustomInputType . BOOL && (
< div className = "flex h-5 items-center" >
2021-12-03 10:15:20 +00:00
< input
2022-07-26 08:27:57 +00:00
type = "checkbox"
2021-12-03 10:15:20 +00:00
{ . . . bookingForm . register ( ` customInputs. ${ input . id } ` , {
required : input.required ,
} ) }
id = { "custom_" + input . id }
2022-07-26 08:27:57 +00:00
className = "h-4 w-4 rounded border-gray-300 text-black focus:ring-black disabled:bg-gray-200 ltr:mr-2 rtl:ml-2 disabled:dark:text-gray-500"
2021-12-03 10:15:20 +00:00
placeholder = ""
2022-05-18 21:05:49 +00:00
disabled = { disabledExceptForOwner }
2021-12-03 10:15:20 +00:00
/ >
2021-09-22 11:04:32 +00:00
< label
2022-07-26 08:27:57 +00:00
htmlFor = { "custom_" + input . id }
2022-02-09 00:05:13 +00:00
className = "mb-1 block text-sm font-medium text-gray-700 dark:text-white" >
2022-07-26 08:27:57 +00:00
{ input . label }
2021-09-22 11:04:32 +00:00
< / label >
< / div >
) }
< / div >
2022-07-26 08:27:57 +00:00
) ) }
{ ! eventType . disableGuests && (
< div className = "mb-4" >
{ ! guestToggle && (
2022-07-14 00:10:45 +00:00
< label
2022-07-26 08:27:57 +00:00
onClick = { ( ) = > setGuestToggle ( ! guestToggle ) }
htmlFor = "guests"
className = "mb-1 block text-sm font-medium hover:cursor-pointer dark:text-white" >
{ /*<UserAddIcon className="inline-block w-5 h-5 mr-1 -mt-1" />*/ }
{ t ( "additional_guests" ) }
2022-07-14 00:10:45 +00:00
< / label >
2022-07-26 08:27:57 +00:00
) }
{ guestToggle && (
< div >
< label
htmlFor = "guests"
className = "mb-1 block text-sm font-medium text-gray-700 dark:text-white" >
{ t ( "guests" ) }
< / label >
{ ! disableInput && (
< Controller
control = { bookingForm . control }
name = "guests"
render = { ( { field : { onChange , value } } ) = > (
< ReactMultiEmail
className = "relative"
placeholder = "guest@example.com"
emails = { value }
onChange = { onChange }
getLabel = { (
email : string ,
index : number ,
removeEmail : ( index : number ) = > void
) = > {
return (
< div data - tag key = { index } className = "cursor-pointer" >
{ email }
{ ! disableInput && (
< span data - tag - handle onClick = { ( ) = > removeEmail ( index ) } >
×
< / span >
) }
< / div >
) ;
} }
/ >
) }
/ >
) }
{ /* Custom code when guest emails should not be editable */ }
{ disableInput && guestListEmails && guestListEmails . length > 0 && (
< div data - tag className = "react-multi-email" >
{ /* // @TODO: user owners are appearing as guest here when should be only user input */ }
{ guestListEmails . map ( ( email , index ) = > {
return (
< div key = { index } className = "cursor-pointer" >
< span data - tag > { email } < / span >
< / div >
) ;
} ) }
< / div >
) }
2022-07-14 00:10:45 +00:00
< / div >
2022-07-26 08:27:57 +00:00
) }
< / div >
) }
2022-08-26 00:48:50 +00:00
{ isSmsReminderNumberNeeded && selectedLocationType !== LocationType . Phone && (
2021-09-14 08:45:28 +00:00
< div className = "mb-4" >
< label
2022-07-26 08:27:57 +00:00
htmlFor = "smsReminderNumber"
className = "block text-sm font-medium text-gray-700 dark:text-white" >
{ t ( "number_for_sms_reminders" ) }
2021-09-14 08:45:28 +00:00
< / label >
2022-07-26 08:27:57 +00:00
< div className = "mt-1" >
< PhoneInput < BookingFormValues >
control = { bookingForm . control }
name = "smsReminderNumber"
placeholder = { t ( "enter_phone_number" ) }
id = "smsReminderNumber"
required
disabled = { disableInput }
2022-05-30 19:40:29 +00:00
/ >
2022-07-26 08:27:57 +00:00
< / div >
{ bookingForm . formState . errors . smsReminderNumber && (
< div className = "mt-2 flex items-center text-sm text-red-700 " >
2022-08-03 16:01:29 +00:00
< Icon.FiInfo className = "mr-2 h-3 w-3" / >
2022-07-26 08:27:57 +00:00
< p > { t ( "invalid_number" ) } < / p >
< / div >
2022-05-30 19:40:29 +00:00
) }
2021-09-14 08:45:28 +00:00
< / div >
) }
2022-07-26 08:27:57 +00:00
< div className = "mb-4" >
< label
htmlFor = "notes"
className = "mb-1 block text-sm font-medium text-gray-700 dark:text-white" >
{ rescheduleUid ? t ( "reschedule_optional" ) : t ( "additional_notes" ) }
< / label >
{ rescheduleUid ? (
< textarea
{ . . . bookingForm . register ( "rescheduleReason" ) }
id = "rescheduleReason"
name = "rescheduleReason"
rows = { 3 }
className = { inputClassName }
placeholder = { t ( "reschedule_placeholder" ) }
/ >
) : (
< textarea
{ . . . bookingForm . register ( "notes" ) }
id = "notes"
name = "notes"
rows = { 3 }
className = { inputClassName }
placeholder = { t ( "share_additional_notes" ) }
disabled = { disabledExceptForOwner }
/ >
) }
< / div >
< div className = "flex items-start space-x-2 rtl:space-x-reverse" >
< Button
type = "submit"
2022-08-24 20:18:42 +00:00
className = "dark:bg-darkmodebrand dark:text-darkmodebrandcontrast"
2022-07-26 08:27:57 +00:00
data - testid = { rescheduleUid ? "confirm-reschedule-button" : "confirm-book-button" }
loading = { mutation . isLoading || recurringMutation . isLoading } >
{ rescheduleUid ? t ( "reschedule" ) : t ( "confirm" ) }
< / Button >
< Button color = "secondary" type = "button" onClick = { ( ) = > router . back ( ) } >
{ t ( "cancel" ) }
< / Button >
< / div >
< / Form >
{ ( mutation . isError || recurringMutation . isError ) && (
< ErrorMessage error = { mutation . error || recurringMutation . error } / >
) }
2021-09-14 08:45:28 +00:00
< / div >
< / div >
2022-07-26 08:27:57 +00:00
< / div >
2021-09-24 22:11:30 +00:00
< / main >
< / div >
2021-09-14 08:45:28 +00:00
) ;
} ;
export default BookingPage ;
2022-06-10 18:38:46 +00:00
function ErrorMessage ( { error } : { error : unknown } ) {
const { t } = useLocale ( ) ;
const { query : { rescheduleUid } = { } } = useRouter ( ) ;
return (
< div data - testid = "booking-fail" className = "mt-2 border-l-4 border-yellow-400 bg-yellow-50 p-4" >
< div className = "flex" >
< div className = "flex-shrink-0" >
2022-08-03 16:01:29 +00:00
< Icon.FiAlertTriangle className = "h-5 w-5 text-yellow-400" aria - hidden = "true" / >
2022-06-10 18:38:46 +00:00
< / div >
< div className = "ltr:ml-3 rtl:mr-3" >
< p className = "text-sm text-yellow-700" >
{ rescheduleUid ? t ( "reschedule_fail" ) : t ( "booking_fail" ) } { " " }
{ error instanceof HttpError || error instanceof Error ? error . message : "Unknown error" }
< / p >
< / div >
< / div >
< / div >
) ;
}