11"use client" ;
22
3- import { useEffect , Suspense } from "react" ;
4-
53import { InstallAppButton } from "@calcom/app-store/InstallAppButton" ;
6- import { DestinationCalendarSettingsWebWrapper } from "./DestinationCalendarSettingsWebWrapper" ;
7- import { SelectedCalendarsSettingsWebWrapper } from "@calcom/web/modules/calendars/components/SelectedCalendarsSettingsWebWrapper" ;
8- import AppListCard from "@calcom/web/modules/apps/components/AppListCard" ;
9- import { SkeletonLoader } from "@calcom/web/modules/apps/components/SkeletonLoader" ;
104import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader" ;
115import { useLocale } from "@calcom/lib/hooks/useLocale" ;
12- import { trpc } from "@calcom/trpc/react" ;
136import type { RouterOutputs } from "@calcom/trpc/react" ;
7+ import { trpc } from "@calcom/trpc/react" ;
148import { Button } from "@calcom/ui/components/button" ;
159import { EmptyScreen } from "@calcom/ui/components/empty-screen" ;
1610import { ShellSubHeading } from "@calcom/ui/components/layout" ;
1711import { List } from "@calcom/ui/components/list" ;
1812import { showToast } from "@calcom/ui/components/toast" ;
1913import { revalidateSettingsCalendars } from "@calcom/web/app/cache/path/settings/my-account" ;
14+ import AppListCard from "@calcom/web/modules/apps/components/AppListCard" ;
15+ import { SkeletonLoader } from "@calcom/web/modules/apps/components/SkeletonLoader" ;
16+ import { SelectedCalendarsSettingsWebWrapper } from "@calcom/web/modules/calendars/components/SelectedCalendarsSettingsWebWrapper" ;
17+ import SubHeadingTitleWithConnections from "@components/integrations/SubHeadingTitleWithConnections" ;
18+ import useRouterQuery from "@lib/hooks/useRouterQuery" ;
2019
2120import { QueryCell } from "@lib/QueryCell" ;
22- import useRouterQuery from "@lib/hooks/useRouterQuery" ;
21+ import { Suspense , useEffect } from "react" ;
22+ import { DestinationCalendarSettingsWebWrapper } from "./DestinationCalendarSettingsWebWrapper" ;
2323
24- import SubHeadingTitleWithConnections from "@components/integrations/SubHeadingTitleWithConnections" ;
24+ type CalendarListContainerProps = {
25+ connectedCalendars : RouterOutputs [ "viewer" ] [ "calendars" ] [ "connectedCalendars" ] ;
26+ installedCalendars : RouterOutputs [ "viewer" ] [ "apps" ] [ "integrations" ] ;
27+ heading ?: boolean ;
28+ fromOnboarding ?: boolean ;
29+ } ;
2530
2631type Props = {
2732 onChanged : ( ) => unknown | Promise < unknown > ;
@@ -30,7 +35,7 @@ type Props = {
3035 isPending ?: boolean ;
3136} ;
3237
33- function CalendarList ( props : Props ) {
38+ function CalendarList ( props : Props ) : JSX . Element {
3439 const { t } = useLocale ( ) ;
3540 const query = trpc . viewer . apps . integrations . useQuery ( { variant : "calendar" , onlyInstalled : false } ) ;
3641
@@ -66,18 +71,16 @@ function CalendarList(props: Props) {
6671 ) ;
6772}
6873
69- const AddCalendarButton = ( ) => {
74+ const AddCalendarButton = ( ) : JSX . Element => {
7075 const { t } = useLocale ( ) ;
7176 return (
72- < >
73- < Button color = "secondary" StartIcon = "plus" href = "/apps/categories/calendar" >
74- { t ( "add_calendar" ) }
75- </ Button >
76- </ >
77+ < Button color = "secondary" StartIcon = "plus" href = "/apps/categories/calendar" >
78+ { t ( "add_calendar" ) }
79+ </ Button >
7780 ) ;
7881} ;
7982
80- export const CalendarListContainerSkeletonLoader = ( ) => {
83+ export const CalendarListContainerSkeletonLoader = ( ) : JSX . Element => {
8184 const { t } = useLocale ( ) ;
8285 return (
8386 < SettingsHeader
@@ -89,19 +92,12 @@ export const CalendarListContainerSkeletonLoader = () => {
8992 ) ;
9093} ;
9194
92- type CalendarListContainerProps = {
93- connectedCalendars : RouterOutputs [ "viewer" ] [ "calendars" ] [ "connectedCalendars" ] ;
94- installedCalendars : RouterOutputs [ "viewer" ] [ "apps" ] [ "integrations" ] ;
95- heading ?: boolean ;
96- fromOnboarding ?: boolean ;
97- } ;
98-
9995export function CalendarListContainer ( {
10096 connectedCalendars : data ,
10197 installedCalendars,
10298 heading = true ,
10399 fromOnboarding,
104- } : CalendarListContainerProps ) {
100+ } : CalendarListContainerProps ) : JSX . Element {
105101 const { t } = useLocale ( ) ;
106102 const { error, setQuery : setError } = useRouterQuery ( "error" ) ;
107103
@@ -113,7 +109,7 @@ export function CalendarListContainer({
113109 // eslint-disable-next-line react-hooks/exhaustive-deps
114110 } , [ ] ) ;
115111 const utils = trpc . useUtils ( ) ;
116- const onChanged = ( ) =>
112+ const onChanged = ( ) : void => {
117113 Promise . allSettled ( [
118114 utils . viewer . apps . integrations . invalidate (
119115 { variant : "calendar" , onlyInstalled : true } ,
@@ -124,59 +120,69 @@ export function CalendarListContainer({
124120 utils . viewer . calendars . connectedCalendars . invalidate ( ) ,
125121 revalidateSettingsCalendars ( ) ,
126122 ] ) ;
127-
123+ } ;
128124 const mutation = trpc . viewer . calendars . setDestinationCalendar . useMutation ( {
129125 onSuccess : ( ) => {
130126 utils . viewer . calendars . connectedCalendars . invalidate ( ) ;
131127 revalidateSettingsCalendars ( ) ;
132128 } ,
133129 } ) ;
134130
131+ let content = null ;
132+ if ( ! ! data . connectedCalendars . length || ! ! installedCalendars ?. items . length ) {
133+ let headingContent = null ;
134+ if ( heading ) {
135+ headingContent = (
136+ < >
137+ < DestinationCalendarSettingsWebWrapper connectedCalendars = { data } />
138+ < Suspense fallback = { < SkeletonLoader /> } >
139+ < SelectedCalendarsSettingsWebWrapper
140+ onChanged = { onChanged }
141+ fromOnboarding = { fromOnboarding }
142+ destinationCalendarId = { data . destinationCalendar ?. externalId }
143+ isPending = { mutation . isPending }
144+ connectedCalendars = { data }
145+ />
146+ </ Suspense >
147+ </ >
148+ ) ;
149+ }
150+ content = headingContent ;
151+ } else if ( fromOnboarding ) {
152+ content = (
153+ < >
154+ { ! ! data ?. connectedCalendars . length && (
155+ < ShellSubHeading
156+ className = "mt-4"
157+ title = { < SubHeadingTitleWithConnections title = { t ( "connect_additional_calendar" ) } /> }
158+ />
159+ ) }
160+ < CalendarList onChanged = { onChanged } />
161+ </ >
162+ ) ;
163+ } else {
164+ content = (
165+ < EmptyScreen
166+ Icon = "calendar"
167+ headline = { t ( "no_category_apps" , {
168+ category : t ( "calendar" ) . toLowerCase ( ) ,
169+ } ) }
170+ description = { t ( `no_category_apps_description_calendar` ) }
171+ buttonRaw = {
172+ < Button color = "secondary" data-testid = "connect-calendar-apps" href = "/apps/categories/calendar" >
173+ { t ( `connect_calendar_apps` ) }
174+ </ Button >
175+ }
176+ />
177+ ) ;
178+ }
179+
135180 return (
136181 < SettingsHeader
137182 title = { t ( "calendars" ) }
138183 description = { t ( "calendars_description" ) }
139184 CTA = { < AddCalendarButton /> } >
140- { ! ! data . connectedCalendars . length || ! ! installedCalendars ?. items . length ? (
141- < >
142- { heading && (
143- < >
144- < DestinationCalendarSettingsWebWrapper />
145- < Suspense fallback = { < SkeletonLoader /> } >
146- < SelectedCalendarsSettingsWebWrapper
147- onChanged = { onChanged }
148- fromOnboarding = { fromOnboarding }
149- destinationCalendarId = { data . destinationCalendar ?. externalId }
150- isPending = { mutation . isPending }
151- />
152- </ Suspense >
153- </ >
154- ) }
155- </ >
156- ) : fromOnboarding ? (
157- < >
158- { ! ! data ?. connectedCalendars . length && (
159- < ShellSubHeading
160- className = "mt-4"
161- title = { < SubHeadingTitleWithConnections title = { t ( "connect_additional_calendar" ) } /> }
162- />
163- ) }
164- < CalendarList onChanged = { onChanged } />
165- </ >
166- ) : (
167- < EmptyScreen
168- Icon = "calendar"
169- headline = { t ( "no_category_apps" , {
170- category : t ( "calendar" ) . toLowerCase ( ) ,
171- } ) }
172- description = { t ( `no_category_apps_description_calendar` ) }
173- buttonRaw = {
174- < Button color = "secondary" data-testid = "connect-calendar-apps" href = "/apps/categories/calendar" >
175- { t ( `connect_calendar_apps` ) }
176- </ Button >
177- }
178- />
179- ) }
185+ { content }
180186 </ SettingsHeader >
181187 ) ;
182188}
0 commit comments