1- import { useRouter } from 'next/router' ;
2- import { useEffect } from 'react' ;
1+ import { useCallback , useEffect } from 'react' ;
32import ExtendedSidebarLayout from 'src/layouts/ExtendedSidebarLayout' ;
43
54import { FlexBox } from '@/components/FlexBox' ;
@@ -9,9 +8,11 @@ import { Integration } from '@/constants/integrations';
98import { useRedirectWithSession } from '@/constants/useRoute' ;
109import { PageWrapper } from '@/content/PullRequests/PageWrapper' ;
1110import { useAuth } from '@/hooks/useAuth' ;
11+ import { useBoolState } from '@/hooks/useEasyState' ;
1212import { fetchTeams } from '@/slices/team' ;
1313import { useDispatch , useSelector } from '@/store' ;
1414import { PageLayout } from '@/types/resources' ;
15+ import { depFn } from '@/utils/fn' ;
1516
1617function Page ( ) {
1718 useRedirectWithSession ( ) ;
@@ -21,18 +22,23 @@ function Page() {
2122 integrations : { github : isGithubIntegrated }
2223 } = useAuth ( ) ;
2324 const teamsList = useSelector ( ( state ) => state . team . teams ) ;
24- const router = useRouter ( ) ;
25+ const loading = useBoolState ( true ) ;
26+
27+ const fetchAllTeams = useCallback ( async ( ) => {
28+ depFn ( loading . true ) ;
29+ await dispatch (
30+ fetchTeams ( {
31+ org_id : orgId ,
32+ provider : Integration . GITHUB
33+ } )
34+ ) ;
35+ depFn ( loading . false ) ;
36+ } , [ dispatch , loading . false , loading . true , orgId ] ) ;
2537
2638 useEffect ( ( ) => {
2739 if ( ! orgId ) return ;
28- if ( ! teamsList . length )
29- dispatch (
30- fetchTeams ( {
31- org_id : orgId ,
32- provider : Integration . GITHUB
33- } )
34- ) ;
35- } , [ dispatch , isGithubIntegrated , orgId , router . replace , teamsList . length ] ) ;
40+ if ( ! teamsList . length ) fetchAllTeams ( ) ;
41+ } , [ fetchAllTeams , orgId , teamsList . length ] ) ;
3642
3743 return (
3844 < PageWrapper
@@ -45,7 +51,7 @@ function Page() {
4551 showEvenIfNoTeamSelected
4652 hideAllSelectors
4753 >
48- { isGithubIntegrated ? (
54+ { isGithubIntegrated && ! loading . value ? (
4955 < FlexBox col gap = { 4 } >
5056 { teamsList . length ? < TeamsList /> : < CreateEditTeams /> }
5157 </ FlexBox >
0 commit comments