11import { AtomsWrapper } from "@/components/atoms-wrapper" ;
2- import { useMemo , useEffect , useState } from "react" ;
2+ import { useMemo } from "react" ;
33import { shallow } from "zustand/shallow" ;
44
55import dayjs from "@calcom/dayjs" ;
@@ -16,50 +16,51 @@ import { useTimePreferences } from "@calcom/features/bookings/lib";
1616import { LargeCalendar } from "@calcom/features/calendar-view/LargeCalendar" ;
1717import { getUsernameList } from "@calcom/features/eventtypes/lib/defaultEvents" ;
1818import { useTimesForSchedule } from "@calcom/features/schedules/lib/use-schedule/useTimesForSchedule" ;
19- import { getRoutedTeamMemberIdsFromSearchParams } from "@calcom/lib/bookings/getRoutedTeamMemberIdsFromSearchParams" ;
2019
2120import { formatUsername } from "../../booker/BookerPlatformWrapper" ;
2221import type {
2322 BookerPlatformWrapperAtomPropsForIndividual ,
2423 BookerPlatformWrapperAtomPropsForTeam ,
2524} from "../../booker/types" ;
26- import { useGetBookingForReschedule } from "../../hooks/bookings/useGetBookingForReschedule" ;
2725import { useAtomGetPublicEvent } from "../../hooks/event-types/public/useAtomGetPublicEvent" ;
2826import { useEventType } from "../../hooks/event-types/public/useEventType" ;
2927import { useTeamEventType } from "../../hooks/event-types/public/useTeamEventType" ;
3028import { useAvailableSlots } from "../../hooks/useAvailableSlots" ;
3129
30+ type CalendarViewPlatformWrapperAtomPropsForIndividual = {
31+ username : string | string [ ] ;
32+ eventSlug : string ;
33+ } ;
34+
35+ type CalendarViewPlatformWrapperAtomPropsForTeam = {
36+ teamId : number ;
37+ eventSlug : string ;
38+ } ;
39+
3240const CalendarViewPlatformWrapperComponent = (
33- props : BookerPlatformWrapperAtomPropsForIndividual | BookerPlatformWrapperAtomPropsForTeam
41+ props :
42+ | ( CalendarViewPlatformWrapperAtomPropsForIndividual & { teamId ?: number } )
43+ | ( CalendarViewPlatformWrapperAtomPropsForTeam & { username ?: string | string [ ] } )
3444) => {
35- const {
36- eventSlug,
37- isTeamEvent,
38- hostsLimit,
39- allowUpdatingUrlParams = false ,
40- teamMemberEmail,
41- crmAppSlug,
42- crmOwnerRecordType,
43- } = props ;
44-
45- const teamId : number | undefined = props . isTeamEvent ? props . teamId : undefined ;
45+ const isTeamEvent = ! ! props . teamId ;
46+ const teamId : number | undefined = props . teamId ? props . teamId : undefined ;
4647 const username = useMemo ( ( ) => {
4748 if ( props . username ) {
4849 return formatUsername ( props . username ) ;
4950 }
5051 return "" ;
5152 } , [ props . username ] ) ;
5253
53- const { isPending } = useEventType ( username , eventSlug , isTeamEvent ) ;
54- const { isPending : isTeamPending } = useTeamEventType ( teamId , eventSlug , isTeamEvent , hostsLimit ) ;
54+ const { isPending } = useEventType ( username , props . eventSlug , isTeamEvent ) ;
55+
56+ const { isPending : isTeamPending } = useTeamEventType ( teamId , props . eventSlug , isTeamEvent ) ;
5557
56- const setSelectedDuration = useBookerStoreContext ( ( state ) => state . setSelectedDuration ) ;
5758 const selectedDuration = useBookerStoreContext ( ( state ) => state . selectedDuration ) ;
5859
5960 const event = useAtomGetPublicEvent ( {
6061 username,
6162 eventSlug : props . eventSlug ,
62- isTeamEvent : props . isTeamEvent ,
63+ isTeamEvent : isTeamEvent ,
6364 teamId,
6465 selectedDuration,
6566 } ) ;
@@ -90,67 +91,21 @@ const CalendarViewPlatformWrapperComponent = (
9091 selectedDate,
9192 } ) ;
9293
93- useEffect ( ( ) => {
94- setSelectedDuration ( props . duration ?? null ) ;
95- } , [ props . duration , setSelectedDuration ] ) ;
96-
9794 const { timezone } = useTimePreferences ( ) ;
9895 const isDynamic = useMemo ( ( ) => {
9996 return getUsernameList ( username ?? "" ) . length > 1 ;
10097 } , [ username ] ) ;
10198
102- const [ routingParams , setRoutingParams ] = useState < {
103- routedTeamMemberIds ?: number [ ] ;
104- _shouldServeCache ?: boolean ;
105- skipContactOwner ?: boolean ;
106- isBookingDryRun ?: boolean ;
107- } > ( { } ) ;
108-
109- useEffect ( ( ) => {
110- const searchParams = props . routingFormSearchParams
111- ? new URLSearchParams ( props . routingFormSearchParams )
112- : new URLSearchParams ( window . location . search ) ;
113-
114- const routedTeamMemberIds = getRoutedTeamMemberIdsFromSearchParams ( searchParams ) ;
115- const skipContactOwner = searchParams . get ( "cal.skipContactOwner" ) === "true" ;
116-
117- const _cacheParam = searchParams ?. get ( "cal.cache" ) ;
118- const _shouldServeCache = _cacheParam ? _cacheParam === "true" : undefined ;
119- const isBookingDryRun =
120- searchParams ?. get ( "cal.isBookingDryRun" ) ?. toLowerCase ( ) === "true" ||
121- searchParams ?. get ( "cal.sandbox" ) ?. toLowerCase ( ) === "true" ;
122- setRoutingParams ( {
123- ...( skipContactOwner ? { skipContactOwner } : { } ) ,
124- ...( routedTeamMemberIds ? { routedTeamMemberIds } : { } ) ,
125- ...( _shouldServeCache ? { _shouldServeCache } : { } ) ,
126- ...( isBookingDryRun ? { isBookingDryRun } : { } ) ,
127- } ) ;
128- } , [ props . routingFormSearchParams ] ) ;
12999 const bookingData = useBookerStoreContext ( ( state ) => state . bookingData ) ;
130- const setBookingData = useBookerStoreContext ( ( state ) => state . setBookingData ) ;
131-
132- useGetBookingForReschedule ( {
133- uid : props . rescheduleUid ?? props . bookingUid ?? "" ,
134- onSuccess : ( data ) => {
135- setBookingData ( data ) ;
136- } ,
137- } ) ;
138100
139101 useInitializeBookerStoreContext ( {
140102 ...props ,
141- teamMemberEmail,
142- crmAppSlug,
143- crmOwnerRecordType,
144- crmRecordId : props . crmRecordId ,
145103 eventId : event ?. data ?. id ,
146- rescheduleUid : props . rescheduleUid ?? null ,
147- bookingUid : props . bookingUid ?? null ,
148104 layout : "week_view" ,
149- org : props . entity ?. orgSlug ,
150105 username,
151106 bookingData,
152107 isPlatform : true ,
153- allowUpdatingUrlParams,
108+ allowUpdatingUrlParams : false ,
154109 } ) ;
155110
156111 const schedule = useAvailableSlots ( {
@@ -160,23 +115,21 @@ const CalendarViewPlatformWrapperComponent = (
160115 endTime,
161116 timeZone : timezone ,
162117 duration : selectedDuration ?? undefined ,
163- rescheduleUid : props . rescheduleUid ,
164- teamMemberEmail : props . teamMemberEmail ?? undefined ,
165- ...( props . isTeamEvent
118+ teamMemberEmail : undefined ,
119+ ...( isTeamEvent
166120 ? {
167- isTeamEvent : props . isTeamEvent ,
121+ isTeamEvent : isTeamEvent ,
168122 teamId : teamId ,
169123 }
170124 : { } ) ,
171125 enabled :
172126 Boolean ( teamId || username ) &&
173127 Boolean ( month ) &&
174128 Boolean ( timezone ) &&
175- ( props . isTeamEvent ? ! isTeamPending : ! isPending ) &&
129+ ( isTeamEvent ? ! isTeamPending : ! isPending ) &&
176130 Boolean ( event ?. data ?. id ) ,
177- orgSlug : props . entity ?. orgSlug ?? undefined ,
178- eventTypeSlug : isDynamic ? "dynamic" : eventSlug || "" ,
179- ...routingParams ,
131+ orgSlug : undefined ,
132+ eventTypeSlug : isDynamic ? "dynamic" : props . eventSlug || "" ,
180133 } ) ;
181134
182135 return (
@@ -185,7 +138,7 @@ const CalendarViewPlatformWrapperComponent = (
185138 < Header
186139 isCalendarView = { true }
187140 isMyLink = { true }
188- eventSlug = { eventSlug }
141+ eventSlug = { props . eventSlug }
189142 enabledLayouts = { bookerLayout . bookerLayouts . enabledLayouts }
190143 extraDays = { 7 }
191144 isMobile = { false }
@@ -204,7 +157,9 @@ const CalendarViewPlatformWrapperComponent = (
204157} ;
205158
206159export const CalendarViewPlatformWrapper = (
207- props : BookerPlatformWrapperAtomPropsForIndividual | BookerPlatformWrapperAtomPropsForTeam
160+ props :
161+ | ( BookerPlatformWrapperAtomPropsForIndividual & { teamId ?: number } )
162+ | Omit < BookerPlatformWrapperAtomPropsForTeam , "isTeamEvent" >
208163) => {
209164 return (
210165 < BookerStoreProvider >
0 commit comments