1
1
import { type TFunction } from "i18next" ;
2
- import { useState } from "react" ;
2
+ import { useEffect , useState } from "react" ;
3
3
import type { Dispatch , SetStateAction } from "react" ;
4
4
5
5
import { useLocale } from "@calcom/lib/hooks/useLocale" ;
6
6
import { userMetadata } from "@calcom/prisma/zod-utils" ;
7
7
import { trpc } from "@calcom/trpc/react" ;
8
- import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery " ;
8
+ import type { RouterOutputs } from "@calcom/trpc/react" ;
9
9
import classNames from "@calcom/ui/classNames" ;
10
10
import { Button } from "@calcom/ui/components/button" ;
11
11
import { List } from "@calcom/ui/components/list" ;
@@ -16,14 +16,17 @@ import { StepConnectionLoader } from "../components/StepConnectionLoader";
16
16
interface ConnectedAppStepProps {
17
17
nextStep : ( ) => void ;
18
18
isPageLoading : boolean ;
19
+ user : RouterOutputs [ "viewer" ] [ "me" ] [ "get" ] ;
19
20
}
20
21
21
22
const ConnectedVideoStepInner = ( {
22
23
t,
23
24
setAnyInstalledVideoApps,
25
+ user,
24
26
} : {
25
27
t : TFunction ;
26
28
setAnyInstalledVideoApps : Dispatch < SetStateAction < boolean > > ;
29
+ user : RouterOutputs [ "viewer" ] [ "me" ] [ "get" ] ;
27
30
} ) => {
28
31
const { data : queryConnectedVideoApps , isPending } = trpc . viewer . apps . integrations . useQuery ( {
29
32
variant : "conferencing" ,
@@ -39,25 +42,20 @@ const ConnectedVideoStepInner = ({
39
42
sortByMostPopular : true ,
40
43
sortByInstalledFirst : true ,
41
44
} ) ;
42
- // we want to start loading immediately, after all this is a hook.
43
- const { data, status } = useMeQuery ( ) ;
44
-
45
- if ( isPending ) {
46
- return < StepConnectionLoader /> ;
47
- }
48
45
49
46
const hasAnyInstalledVideoApps = queryConnectedVideoApps ?. items . some (
50
47
( item ) => item . userCredentialIds . length > 0
51
48
) ;
52
- if ( hasAnyInstalledVideoApps ) {
53
- setAnyInstalledVideoApps ( true ) ;
54
- }
55
49
56
- if ( status !== "success" ) {
50
+ useEffect ( ( ) => {
51
+ setAnyInstalledVideoApps ( Boolean ( hasAnyInstalledVideoApps ) ) ;
52
+ } , [ hasAnyInstalledVideoApps , setAnyInstalledVideoApps ] ) ;
53
+
54
+ if ( isPending ) {
57
55
return < StepConnectionLoader /> ;
58
56
}
59
57
60
- const result = userMetadata . safeParse ( data ? .metadata ) ;
58
+ const result = userMetadata . safeParse ( user . metadata ) ;
61
59
if ( ! result . success ) {
62
60
return < StepConnectionLoader /> ;
63
61
}
@@ -91,12 +89,12 @@ const ConnectedVideoStepInner = ({
91
89
} ;
92
90
93
91
const ConnectedVideoStep = ( props : ConnectedAppStepProps ) => {
94
- const { nextStep, isPageLoading } = props ;
92
+ const { nextStep, isPageLoading, user } = props ;
95
93
const { t } = useLocale ( ) ;
96
94
const [ hasAnyInstalledVideoApps , setAnyInstalledVideoApps ] = useState ( false ) ;
97
95
return (
98
96
< >
99
- < ConnectedVideoStepInner setAnyInstalledVideoApps = { setAnyInstalledVideoApps } t = { t } />
97
+ < ConnectedVideoStepInner setAnyInstalledVideoApps = { setAnyInstalledVideoApps } t = { t } user = { user } />
100
98
< Button
101
99
EndIcon = "arrow-right"
102
100
data-testid = "save-video-button"
0 commit comments