@@ -9,7 +9,6 @@ import SkeletonLoader from "@calcom/features/availability/components/SkeletonLoa
9
9
import { BulkEditDefaultForEventsModal } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal" ;
10
10
import type { BulkUpdatParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal" ;
11
11
import { NewScheduleButton , ScheduleListItem } from "@calcom/features/schedules" ;
12
- import Shell from "@calcom/features/shell/Shell" ;
13
12
import { AvailabilitySliderTable } from "@calcom/features/timezone-buddy/components/AvailabilitySliderTable" ;
14
13
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams" ;
15
14
import { useLocale } from "@calcom/lib/hooks/useLocale" ;
@@ -195,14 +194,11 @@ type PageProps = {
195
194
currentOrg ?: Awaited < ReturnType < typeof OrganizationRepository . findCurrentOrg > > | null ;
196
195
} ;
197
196
198
- export default function AvailabilityPage ( { currentOrg } : PageProps ) {
197
+ export const AvailabilityCTA = ( ) => {
199
198
const { t } = useLocale ( ) ;
200
199
const searchParams = useCompatSearchParams ( ) ;
201
200
const router = useRouter ( ) ;
202
201
const pathname = usePathname ( ) ;
203
- const me = useMeQuery ( ) ;
204
- const { data : _data } = trpc . viewer . organizations . listCurrent . useQuery ( undefined , { enabled : ! currentOrg } ) ;
205
- const data = currentOrg ?? _data ;
206
202
207
203
// Get a new searchParams string by merging the current
208
204
// searchParams with a provided key/value pair
@@ -216,7 +212,7 @@ export default function AvailabilityPage({ currentOrg }: PageProps) {
216
212
[ searchParams ]
217
213
) ;
218
214
219
- const isOrg = Boolean ( data ) ;
215
+ const { data } = trpc . viewer . organizations . listCurrent . useQuery ( ) ;
220
216
const isOrgAdminOrOwner =
221
217
( data && ( data . user . role === MembershipRole . OWNER || data . user . role === MembershipRole . ADMIN ) ) ?? false ;
222
218
const isOrgAndPrivate = data ?. isOrganization && data . isPrivate ;
@@ -230,35 +226,44 @@ export default function AvailabilityPage({ currentOrg }: PageProps) {
230
226
}
231
227
232
228
return (
233
- < div >
234
- < Shell
235
- heading = { t ( "availability" ) }
236
- subtitle = { t ( "configure_availability" ) }
237
- title = { t ( "availability" ) }
238
- description = { t ( "configure_availability" ) }
239
- hideHeadingOnMobile
240
- withoutSeo = { true }
241
- withoutMain = { false }
242
- CTA = {
243
- < div className = "flex gap-2" >
244
- < ToggleGroup
245
- className = "hidden md:block"
246
- defaultValue = { searchParams ?. get ( "type" ) ?? "mine" }
247
- onValueChange = { ( value ) => {
248
- if ( ! value ) return ;
249
- router . push ( `${ pathname } ?${ createQueryString ( "type" , value ) } ` ) ;
250
- } }
251
- options = { toggleGroupOptions }
252
- />
253
- < NewScheduleButton />
254
- </ div >
255
- } >
256
- { searchParams ?. get ( "type" ) === "team" && canViewTeamAvailability ? (
257
- < AvailabilitySliderTable userTimeFormat = { me ?. data ?. timeFormat ?? null } isOrg = { isOrg } />
258
- ) : (
259
- < AvailabilityListWithQuery />
260
- ) }
261
- </ Shell >
229
+ < div className = "flex gap-2" >
230
+ < ToggleGroup
231
+ className = "hidden md:block"
232
+ defaultValue = { searchParams ?. get ( "type" ) ?? "mine" }
233
+ onValueChange = { ( value ) => {
234
+ if ( ! value ) return ;
235
+ router . push ( `${ pathname } ?${ createQueryString ( "type" , value ) } ` ) ;
236
+ } }
237
+ options = { toggleGroupOptions }
238
+ />
239
+ < NewScheduleButton />
262
240
</ div >
263
241
) ;
242
+ } ;
243
+
244
+ export default function AvailabilityPage ( { currentOrg } : PageProps ) {
245
+ const { t } = useLocale ( ) ;
246
+ const searchParams = useCompatSearchParams ( ) ;
247
+ const me = useMeQuery ( ) ;
248
+ const { data : _data } = trpc . viewer . organizations . listCurrent . useQuery ( undefined , { enabled : ! currentOrg } ) ;
249
+ const data = currentOrg ?? _data ;
250
+
251
+ const isOrg = Boolean ( data ) ;
252
+ const isOrgAdminOrOwner =
253
+ ( data && ( data . user . role === MembershipRole . OWNER || data . user . role === MembershipRole . ADMIN ) ) ?? false ;
254
+ const isOrgAndPrivate = data ?. isOrganization && data . isPrivate ;
255
+
256
+ const canViewTeamAvailability = isOrgAdminOrOwner || ! isOrgAndPrivate ;
257
+
258
+ const toggleGroupOptions = [ { value : "mine" , label : t ( "my_availability" ) } ] ;
259
+
260
+ if ( canViewTeamAvailability ) {
261
+ toggleGroupOptions . push ( { value : "team" , label : t ( "team_availability" ) } ) ;
262
+ }
263
+
264
+ return searchParams ?. get ( "type" ) === "team" && canViewTeamAvailability ? (
265
+ < AvailabilitySliderTable userTimeFormat = { me ?. data ?. timeFormat ?? null } isOrg = { isOrg } />
266
+ ) : (
267
+ < AvailabilityListWithQuery />
268
+ ) ;
264
269
}
0 commit comments