2022-07-28 19:58:26 +00:00
import type { TFunction } from "next-i18next" ;
2023-06-23 06:23:00 +00:00
import { z } from "zod" ;
2022-07-28 19:58:26 +00:00
2023-01-18 22:30:25 +00:00
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData" ;
2022-08-26 00:48:50 +00:00
import logger from "@calcom/lib/logger" ;
2023-05-02 11:44:05 +00:00
import { BookingStatus } from "@calcom/prisma/enums" ;
2023-02-16 22:39:57 +00:00
import type { Ensure , Optional } from "@calcom/types/utils" ;
2022-08-26 00:48:50 +00:00
import type { EventLocationTypeFromAppMeta } from "../types/App" ;
export type DefaultEventLocationType = {
default : true ;
type : DefaultEventLocationTypeEnum ;
label : string ;
messageForOrganizer : string ;
2023-03-28 20:03:54 +00:00
category : "in person" | "conferencing" | "other" | "phone" ;
2022-08-26 00:48:50 +00:00
iconUrl : string ;
2023-02-14 13:19:45 +00:00
urlRegExp? : string ;
2022-08-26 00:48:50 +00:00
// HACK: `variable` and `defaultValueVariable` are required due to legacy reason where different locations were stored in different places.
2023-03-28 20:03:54 +00:00
variable :
| "locationType"
| "locationAddress"
| "address"
| "locationLink"
| "locationPhoneNumber"
| "phone"
| "hostDefault" ;
defaultValueVariable : "address" | "attendeeAddress" | "link" | "hostPhoneNumber" | "hostDefault" | "phone" ;
2022-08-26 00:48:50 +00:00
} & (
| {
organizerInputType : "phone" | "text" | null ;
organizerInputPlaceholder? : string | null ;
attendeeInputType? : null ;
attendeeInputPlaceholder? : null ;
}
| {
2022-11-05 20:10:10 +00:00
attendeeInputType : "phone" | "attendeeAddress" | null ;
2022-08-26 00:48:50 +00:00
attendeeInputPlaceholder : string ;
organizerInputType? : null ;
organizerInputPlaceholder? : null ;
}
) ;
2023-07-18 15:37:39 +00:00
export type EventLocationTypeFromApp = Ensure <
EventLocationTypeFromAppMeta ,
"defaultValueVariable" | "variable"
> ;
2022-08-26 00:48:50 +00:00
export type EventLocationType = DefaultEventLocationType | EventLocationTypeFromApp ;
export const DailyLocationType = "integrations:daily" ;
2023-01-10 02:01:57 +00:00
export const MeetLocationType = "integrations:google:meet" ;
2023-06-23 17:04:34 +00:00
/ * *
* This isn 't an actual location app type. It is a special value that informs to use the Organizer' s default conferencing app during booking
* /
export const OrganizerDefaultConferencingAppType = "conferencing" ;
2022-08-26 00:48:50 +00:00
export enum DefaultEventLocationTypeEnum {
2022-11-05 20:10:10 +00:00
/ * *
* Booker Address
* /
AttendeeInPerson = "attendeeInPerson" ,
/ * *
* Organizer Address
* /
2022-02-15 20:30:52 +00:00
InPerson = "inPerson" ,
2022-08-26 00:48:50 +00:00
/ * *
* Booker Phone
* /
2022-02-15 20:30:52 +00:00
Phone = "phone" ,
2022-08-26 00:48:50 +00:00
/ * *
* Organizer Phone
* /
2022-05-16 15:50:12 +00:00
UserPhone = "userPhone" ,
2022-03-13 15:56:56 +00:00
Link = "link" ,
2023-06-23 17:04:34 +00:00
// Same as `OrganizerDefaultConferencingAppType`
2023-03-28 20:03:54 +00:00
Conferencing = "conferencing" ,
2022-04-05 18:03:22 +00:00
}
2022-08-26 00:48:50 +00:00
export const defaultLocations : DefaultEventLocationType [ ] = [
2022-11-05 20:10:10 +00:00
{
default : true ,
type : DefaultEventLocationTypeEnum . AttendeeInPerson ,
2023-06-08 13:37:54 +00:00
label : "in_person_attendee_address" ,
2022-11-05 20:10:10 +00:00
variable : "address" ,
organizerInputType : null ,
messageForOrganizer : "Cal will ask your invitee to enter an address before scheduling." ,
attendeeInputType : "attendeeAddress" ,
2023-01-04 15:31:50 +00:00
attendeeInputPlaceholder : "enter_address" ,
2022-11-05 20:10:10 +00:00
defaultValueVariable : "attendeeAddress" ,
iconUrl : "/map-pin.svg" ,
2022-11-24 11:53:29 +00:00
category : "in person" ,
2022-11-05 20:10:10 +00:00
} ,
2022-08-26 00:48:50 +00:00
{
default : true ,
type : DefaultEventLocationTypeEnum . InPerson ,
2023-03-07 22:37:56 +00:00
label : "in_person" ,
2022-08-26 00:48:50 +00:00
organizerInputType : "text" ,
messageForOrganizer : "Provide an Address or Place" ,
// HACK:
variable : "locationAddress" ,
defaultValueVariable : "address" ,
iconUrl : "/map-pin.svg" ,
2022-11-24 11:53:29 +00:00
category : "in person" ,
2022-08-26 00:48:50 +00:00
} ,
2023-03-28 20:03:54 +00:00
{
default : true ,
type : DefaultEventLocationTypeEnum . Conferencing ,
iconUrl : "/link.svg" ,
organizerInputType : null ,
label : "organizer_default_conferencing_app" ,
variable : "hostDefault" ,
defaultValueVariable : "hostDefault" ,
category : "conferencing" ,
messageForOrganizer : "" ,
} ,
2022-08-26 00:48:50 +00:00
{
default : true ,
type : DefaultEventLocationTypeEnum . Link ,
2023-03-07 22:37:56 +00:00
label : "link_meeting" ,
2022-08-26 00:48:50 +00:00
organizerInputType : "text" ,
variable : "locationLink" ,
messageForOrganizer : "Provide a Meeting Link" ,
defaultValueVariable : "link" ,
2022-11-22 12:04:06 +00:00
iconUrl : "/link.svg" ,
2022-11-24 11:53:29 +00:00
category : "other" ,
2022-08-26 00:48:50 +00:00
} ,
{
default : true ,
type : DefaultEventLocationTypeEnum . Phone ,
2023-03-07 22:37:56 +00:00
label : "attendee_phone_number" ,
2022-08-26 00:48:50 +00:00
variable : "phone" ,
organizerInputType : null ,
attendeeInputType : "phone" ,
attendeeInputPlaceholder : ` enter_phone_number ` ,
defaultValueVariable : "phone" ,
messageForOrganizer : "Cal will ask your invitee to enter a phone number before scheduling." ,
// This isn't inputType phone because organizer doesn't need to provide it.
// inputType: "phone"
iconUrl : "/phone.svg" ,
2022-11-24 11:53:29 +00:00
category : "phone" ,
2022-08-26 00:48:50 +00:00
} ,
{
default : true ,
type : DefaultEventLocationTypeEnum . UserPhone ,
2023-03-07 22:37:56 +00:00
label : "organizer_phone_number" ,
2022-08-26 00:48:50 +00:00
messageForOrganizer : "Provide your phone number" ,
organizerInputType : "phone" ,
variable : "locationPhoneNumber" ,
defaultValueVariable : "hostPhoneNumber" ,
iconUrl : "/phone.svg" ,
2022-11-24 11:53:29 +00:00
category : "phone" ,
2022-08-26 00:48:50 +00:00
} ,
] ;
2022-04-05 18:03:22 +00:00
2023-06-23 06:23:00 +00:00
const translateAbleKeys = [
"in_person_attendee_address" ,
"in_person" ,
"attendee_phone_number" ,
"link_meeting" ,
"organizer_phone_number" ,
] ;
2022-05-25 20:34:08 +00:00
export type LocationObject = {
2022-08-26 00:48:50 +00:00
type : string ;
2023-06-13 14:54:53 +00:00
address? : string ;
2022-05-25 20:34:08 +00:00
displayLocationPublicly? : boolean ;
feat: Enable Apps for Teams & Orgs [CAL-1782] (#9337)
* Initial commit
* Adding feature flag
* Add schema relation for teams and credentials
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* Create getUserAdminTeams function & tRPC endpoint
* Get user admin teams on app store page
* Create UserAdminTeams type
* Add user query to getUserAdminTeams
* Letting duplicate slugs for teams to support orgs
* Covering null on unique clauses
* Add dropdown to install button on app store
* Supporting having the orgId in the session cookie
* On app page, only show dropdown if there are teams
* Add teamId to OAuth state
* Create team credential for OAuth flow
* Create team credential for GCal
* Add create user or team credential for Stripe
* Create webex credentials for users or teams
* Fix type error on useAddAppMutation
* Hubspot create credential on user or team
* Zoho create create credential for user or team
* Zoom create credentials on user or team
* Salesforce create credential on user or teams
* OAuth create credentials for user or teams
* Revert Outlook changes
* Revert GCal changes
* Default app instal, create credential on user or team
* Add teamId to credential creation
* Disable installing for teams for calendars
* Include teams when querying installed apps
* Render team credentials on installed page
* Uninstall team apps
* Type fix on app card
* Add input to include user in teams query
* Add dropdown to install app page for user or team
* Type fixes on category page
* Install app from eventType page to user or team
* Render user and team apps on event type app page
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* Render user and team apps on event type app page
* Add credentialOwner to eventTypeAppCard types
* Type fixes
* Create hook to check if app is enabled
* Clean up console.logs
* Fix useIsAppEnabled by returning not an array
* Convert event type apps to useIsAppEnabled
* Abstract credential owner type
* Remove console.logs
* On installed app page, show apps if only team credential is installed
* Clean up commented lines
* Handle installing app to just an team event from event type page
* Fix early return when creating team app credential
* Zoom add state to callback
* Get team location credentials and save credential id to location
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Type fix
* Grab team location credentials
* Add isInstalled to eventType apps query
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* Enable payment apps for team credentials
* Fix for team-user apps for event types
* Fix layout and add teamId to app card
* Disable apps on managed event types
* Add managed event type fields to event type apps
* Include organizations in query
* Change createAppCredential to createOAuthAppCredential
* Show app installed on teams
* Making sure we let localhost still work
* UI show installed for which team
* Type fixes
* For team events move use host location to top
* Add around to appStore
* New team event types organizer default conf app
* Fix app card bug
* Clean up
* Search for teamId or userId when deleting credential
* Type fixes
* Type fixes
* Type fixes
* Type fixes
* Address feedback
* Feedback
* Type check fixes
* feat: Organization branding in side menu (#9279)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Making sure we show the set up profile on org only
* Profile username availability rely on org hook
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: Organization support for event types page (#9449)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Processing orgs and children as profile options
* Reverting change not belonging to this PR
* Making sure we show the set up profile on org only
* Removing console.log
* Comparing memberships to choose the highest one
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Type errors
* Refactor and type fixes
* Update orgDomains.ts
* Feedback
* Reverting
* NIT
* Address feedback
* fix issue getting org slug from domain
* Improving orgDomains util
* Host comes with port
* Update useRouterQuery.ts
* Fix app card bug
* Fix schema
* Type fixes
* Revert changes to location apps
* Remove console.log
* Fix app store test
* Handle install app dropdown
* Add CalendarApp to `getCalendar`
* Add PaymentApp type fix
* Payment type fix
* Type fixes
* Match with main
* Change type to account for team
* Fix app count for team events
* Type fixes
* More type fixes
* Type fix?
* Fix the type fix
* Remove UserAdminTeams empty array union
* Type fix
* Type fix
* Type fix
* Uses type predicates
* Use teamId. Fixes installation for teams after user installation
* Fix Team Events not working
* Get embed for org events working
* Fix rewrites
* Address feedback
* Type fix
* Fixes
* Add useAppContextWithSchema in useIsAppEnabled
* Type fix for apps using useIsAppEnabled
* Integrations.handler change credentialIds to userCredentialIds
* Remove apps endpoint
* Add LockedIcon and disabled props to event type app context
* Type fixes
* Type fix
* Type fixes
* Show team installed apps for members
* Type fix
* Reverting findFirst
* Revert findFirst
* Avoid a possible 500
* Fix missing tanslation
* Avoid possible 500
* Undo default app for teams
* Type fix
* Fix test
* Update package.json
* feat: Fix invite bug - added tests (#9945)
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
* chore: Button Component Tidy up (#9888)
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
* feat: Make Team Private
## What does this PR do?
Fixes https://github.com/calcom/cal.com/issues/8974
1) When user is admin
<img width="1440" alt="Screenshot 2023-07-03 at 6 45 50 PM" src="https://github.com/calcom/cal.com/assets/53316345/ce15158f-d278-4f1a-ba2e-8b63e4274793">
2) When user is not admin and team is private
<img width="1440" alt="Screenshot 2023-07-03 at 6 47 15 PM" src="https://github.com/calcom/cal.com/assets/53316345/ce23560e-690a-4c42-a76d-49691260aa4d">
3)
<img width="1440" alt="Screenshot 2023-07-03 at 6 51 56 PM" src="https://github.com/calcom/cal.com/assets/53316345/13af38f8-5618-4dae-b359-b24dc91e4eb4">
## Type of change
<!-- Please delete bullets that are not relevant. -->
- New feature (non-breaking change which adds functionality)
## How should this be tested?
1) go to Team members page and turn on switch Make Team Private.
Now after making the team private only admin would be able to see all the members list in the settings. There will not be a button to Book a team member instead on the team page like before.
## Mandatory Tasks
- [ ] Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: Alan <alannnc@gmail.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2023-07-06 16:48:39 +00:00
credentialId? : number ;
2023-03-28 20:03:54 +00:00
} & Partial <
Record < "address" | "attendeeAddress" | "link" | "hostPhoneNumber" | "hostDefault" | "phone" , string >
> ;
2022-08-26 00:48:50 +00:00
// integrations:jitsi | 919999999999 | Delhi | https://manual.meeting.link | Around Video
export type BookingLocationValue = string ;
export const AppStoreLocationType : Record < string , string > = { } ;
const locationsFromApps : EventLocationTypeFromApp [ ] = [ ] ;
for ( const [ appName , meta ] of Object . entries ( appStoreMetadata ) ) {
const location = meta . appData ? . location ;
if ( location ) {
2023-01-18 22:30:25 +00:00
// TODO: This template variable replacement should happen once during app-store:build.
for ( const [ key , value ] of Object . entries ( location ) ) {
if ( typeof value === "string" ) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
location [ key ] = value . replace ( /{SLUG}/g , meta . slug ) . replace ( /{TITLE}/g , meta . name ) ;
}
}
2022-08-26 00:48:50 +00:00
const newLocation = {
. . . location ,
messageForOrganizer : location.messageForOrganizer || ` Set ${ location . label } link ` ,
iconUrl : meta.logo ,
// For All event location apps, locationLink is where we store the input
// TODO: locationLink and link seems redundant. We can modify the code to keep just one of them.
variable : location.variable || "locationLink" ,
defaultValueVariable : location.defaultValueVariable || "link" ,
} ;
// Static links always require organizer to input
if ( newLocation . linkType === "static" ) {
newLocation . organizerInputType = location . organizerInputType || "text" ;
if ( newLocation . organizerInputPlaceholder ? . match ( /https?:\/\// ) ) {
// HACK: Translation ends up removing https? if it's in the beginning :(
newLocation . organizerInputPlaceholder = ` ${ newLocation . organizerInputPlaceholder } ` ;
}
} else {
newLocation . organizerInputType = null ;
}
AppStoreLocationType [ appName ] = newLocation . type ;
locationsFromApps . push ( {
. . . newLocation ,
} ) ;
}
}
const locationsTypes = [ . . . defaultLocations , . . . locationsFromApps ] ;
export const getStaticLinkBasedLocation = ( locationType : string ) = >
locationsFromApps . find ( ( l ) = > l . linkType === "static" && l . type === locationType ) ;
export const getEventLocationTypeFromApp = ( locationType : string ) = >
locationsFromApps . find ( ( l ) = > l . type === locationType ) ;
export const getEventLocationType = ( locationType : string | undefined | null ) = >
locationsTypes . find ( ( l ) = > l . type === locationType ) ;
export const getEventLocationTypeFromValue = ( value : string | undefined | null ) = > {
if ( ! value ) {
return null ;
}
return locationsTypes . find ( ( l ) = > {
if ( l . default || l . linkType == "dynamic" || ! l . urlRegExp ) {
return ;
}
return new RegExp ( l . urlRegExp ) . test ( value ) ;
} ) ;
2022-05-25 20:34:08 +00:00
} ;
2022-08-26 00:48:50 +00:00
export const guessEventLocationType = ( locationTypeOrValue : string | undefined | null ) = >
getEventLocationType ( locationTypeOrValue ) || getEventLocationTypeFromValue ( locationTypeOrValue ) ;
2022-05-25 20:34:08 +00:00
2022-08-26 00:48:50 +00:00
export const LocationType = { . . . DefaultEventLocationTypeEnum , . . . AppStoreLocationType } ;
type PrivacyFilteredLocationObject = Optional < LocationObject , " address " | " link " > ;
export const privacyFilteredLocations = ( locations : LocationObject [ ] ) : PrivacyFilteredLocationObject [ ] = > {
const locationsAfterPrivacyFilter = locations . map ( ( location ) = > {
const eventLocationType = getEventLocationType ( location . type ) ;
if ( ! eventLocationType ) {
logger . debug ( ` Couldn't find location type. App might be uninstalled: ${ location . type } ` ) ;
}
2022-05-25 20:34:08 +00:00
// Filter out locations that are not to be displayed publicly
// Display if the location can be set to public - and also display all locations like google meet etc
2022-08-26 00:48:50 +00:00
if ( location . displayLocationPublicly || ! eventLocationType ) {
return location ;
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { address : _1 , link : _2 , hostPhoneNumber : _3 , . . . privacyFilteredLocation } = location ;
logger . debug ( "Applied Privacy Filter" , location , privacyFilteredLocation ) ;
return privacyFilteredLocation ;
2022-05-25 20:34:08 +00:00
}
} ) ;
2022-08-26 00:48:50 +00:00
return locationsAfterPrivacyFilter ;
} ;
2022-07-28 19:58:26 +00:00
/ * *
* Use this function for translating event location to a readable string
* @param location
* @param t
* @returns string
* /
2022-08-26 00:48:50 +00:00
export const getMessageForOrganizer = ( location : string , t : TFunction ) = > {
const videoLocation = getEventLocationTypeFromApp ( location ) ;
const defaultLocation = defaultLocations . find ( ( l ) = > l . type === location ) ;
if ( defaultLocation ) {
return t ( defaultLocation . messageForOrganizer ) ;
2022-07-28 19:58:26 +00:00
}
2022-12-07 20:12:26 +00:00
if ( videoLocation && videoLocation . linkType !== "static" && videoLocation . type !== "integrations:zoom" ) {
2022-08-26 00:48:50 +00:00
return t ( ` Cal will provide a ${ videoLocation . label } URL. ` ) ;
}
return "" ;
} ;
/ * *
* Use this function to translate booking location value to a readable string
* @param linkValue
* @param translationFunction
* @returns
* /
export const getHumanReadableLocationValue = (
linkValue : string | undefined | null ,
translationFunction : TFunction
) : string = > {
if ( ! linkValue ) {
return translationFunction ( "no_location" ) ;
}
// Just in case linkValue is a `locationType.type`(for old bookings)
const eventLocationType = getEventLocationType ( linkValue ) ;
if ( eventLocationType ) {
// If we can find a video location based on linkValue then it means that the linkValue is something like integrations:google-meet and in that case we don't have the meeting URL to show.
// Show a generic message in that case.
return ` ${ eventLocationType . label } ` ;
}
// Otherwise just show the available link value which can be a Phone number, a URL or a physical address of a place.
return linkValue || "" ;
} ;
export const locationKeyToString = ( location : LocationObject ) = > {
const eventLocationType = getEventLocationType ( location . type ) ;
if ( ! eventLocationType ) {
return null ;
}
const defaultValueVariable = eventLocationType . defaultValueVariable ;
if ( ! defaultValueVariable ) {
console . error ( ` defaultValueVariable not set for ${ location . type } ` ) ;
return "" ;
}
return location [ defaultValueVariable ] || eventLocationType . label ;
} ;
export const getEventLocationWithType = (
locations : LocationObject [ ] ,
locationType : EventLocationType [ "type" ] | undefined
) = > {
const location = locations . find ( ( location ) = > location . type === locationType ) ;
return location ;
2022-07-28 19:58:26 +00:00
} ;
2022-08-26 00:48:50 +00:00
2023-06-23 17:04:34 +00:00
/ * *
* It converts a static link based video location type ( e . g . integrations :campfire_video ) to it ' s value ( e . g . https : //campfire.to/my_link) set in the eventType.
* If the type provided is already a value ( when displayLocationPublicly is on ) , it would just return that .
* For , dynamic link based video location apps , it doesn ' t do anything .
* /
2022-08-26 00:48:50 +00:00
export const getLocationValueForDB = (
bookingLocationTypeOrValue : EventLocationType [ "type" ] ,
eventLocations : LocationObject [ ]
) = > {
let bookingLocation = bookingLocationTypeOrValue ;
eventLocations . forEach ( ( location ) = > {
if ( location . type === bookingLocationTypeOrValue ) {
const eventLocationType = getEventLocationType ( bookingLocationTypeOrValue ) ;
if ( ! eventLocationType ) {
return ;
}
if ( ! eventLocationType . default && eventLocationType . linkType === "dynamic" ) {
// Dynamic link based locations should still be saved as type. The beyond logic generates meeting URL based on the type.
// This difference can be avoided when we start storing both type and value of a location
return ;
}
bookingLocation = location [ eventLocationType . defaultValueVariable ] || bookingLocation ;
}
} ) ;
return bookingLocation ;
} ;
export const getEventLocationValue = ( eventLocations : LocationObject [ ] , bookingLocation : LocationObject ) = > {
const eventLocationType = getEventLocationType ( bookingLocation ? . type ) ;
if ( ! eventLocationType ) {
return "" ;
}
const defaultValueVariable = eventLocationType . defaultValueVariable ;
if ( ! defaultValueVariable ) {
console . error ( ` ${ defaultValueVariable } not set for ${ bookingLocation . type } ` ) ;
return "" ;
}
const eventLocation = getEventLocationWithType ( eventLocations , bookingLocation ? . type ) ;
if ( ! eventLocation ) {
console . error ( ` Could not find eventLocation for ${ bookingLocation } ` ) ;
return "" ;
}
// Must send .type here if value isn't available due to privacy setting.
// For Booker Phone Number, it would be a value always. For others, value is either autogenerated or provided by Organizer and thus it's possible that organizer doesn't want it to show
// Backend checks for `integration` to generate link
// TODO: use zodSchema to ensure the type of data is correct
return (
bookingLocation [ defaultValueVariable ] || eventLocation [ defaultValueVariable ] || eventLocationType . type
) ;
} ;
2022-09-15 01:27:46 +00:00
export function getSuccessPageLocationMessage (
location : EventLocationType [ "type" ] ,
t : TFunction ,
bookingStatus? : BookingStatus
) {
2022-08-26 00:48:50 +00:00
const eventLocationType = getEventLocationType ( location ) ;
let locationToDisplay = location ;
if ( eventLocationType && ! eventLocationType . default && eventLocationType . linkType === "dynamic" ) {
2022-09-15 01:27:46 +00:00
const isConfirmed = bookingStatus === BookingStatus . ACCEPTED ;
2022-08-26 00:48:50 +00:00
2022-09-15 01:27:46 +00:00
if ( bookingStatus === BookingStatus . CANCELLED || bookingStatus === BookingStatus . REJECTED ) {
2022-08-26 00:48:50 +00:00
locationToDisplay == t ( "web_conference" ) ;
} else if ( isConfirmed ) {
locationToDisplay =
getHumanReadableLocationValue ( location , t ) + ": " + t ( "meeting_url_in_conformation_email" ) ;
} else {
locationToDisplay = t ( "web_conferencing_details_to_follow" ) ;
}
}
return locationToDisplay ;
}
2023-06-23 06:23:00 +00:00
export const getTranslatedLocation = (
location : PrivacyFilteredLocationObject ,
eventLocationType : ReturnType < typeof getEventLocationType > ,
t : TFunction
) = > {
if ( ! eventLocationType ) return null ;
const locationKey = z . string ( ) . default ( "" ) . parse ( locationKeyToString ( location ) ) ;
const translatedLocation = location . type . startsWith ( "integrations:" )
? eventLocationType . label
: translateAbleKeys . includes ( locationKey )
? t ( locationKey )
: locationKey ;
return translatedLocation ;
} ;