11import { useCallback , useEffect , useMemo , useRef } from 'react' ;
2- import { useNavigate } from 'react-router-dom' ;
2+ import { useLocation , useNavigate } from 'react-router-dom' ;
33
44import {
55 DISCORD_URL ,
88} from 'consts' ;
99import { useAppDispatch , useAppSelector } from 'hooks' ;
1010import { goToUrl } from 'libs' ;
11+ import { ROUTES } from 'routes' ;
12+ import { useGetProjectsQuery } from 'services/project' ;
1113import { useGetRunsQuery } from 'services/run' ;
1214import { useGetUserBillingInfoQuery } from 'services/user' ;
1315
@@ -17,6 +19,7 @@ import { useSideNavigation } from '../hooks';
1719import {
1820 BILLING_TUTORIAL ,
1921 CONFIGURE_CLI_TUTORIAL ,
22+ CREATE_FIRST_PROJECT ,
2023 // CREDITS_TUTORIAL,
2124 JOIN_DISCORD_TUTORIAL ,
2225 QUICKSTART_TUTORIAL ,
@@ -26,40 +29,73 @@ import { ITutorialItem } from 'App/types';
2629
2730export const useTutorials = ( ) => {
2831 const navigate = useNavigate ( ) ;
32+ const location = useLocation ( ) ;
2933 const dispatch = useAppDispatch ( ) ;
3034 const { billingUrl } = useSideNavigation ( ) ;
3135 const useName = useAppSelector ( selectUserName ) ;
32- const { billingCompleted, configureCLICompleted, discordCompleted, tallyCompleted, quickStartCompleted, hideStartUp } =
33- useAppSelector ( selectTutorialPanel ) ;
36+ const {
37+ billingCompleted,
38+ createProjectCompleted,
39+ configureCLICompleted,
40+ discordCompleted,
41+ tallyCompleted,
42+ quickStartCompleted,
43+ hideStartUp,
44+ } = useAppSelector ( selectTutorialPanel ) ;
3445
3546 const { data : userBillingData } = useGetUserBillingInfoQuery ( { username : useName ?? '' } , { skip : ! useName } ) ;
47+ const { data : projectData } = useGetProjectsQuery ( ) ;
3648 const { data : runsData } = useGetRunsQuery ( {
3749 limit : 1 ,
3850 } ) ;
3951
4052 const completeIsChecked = useRef < boolean > ( false ) ;
4153
4254 useEffect ( ( ) => {
43- if ( userBillingData && runsData && ! completeIsChecked . current ) {
55+ if (
56+ userBillingData &&
57+ projectData &&
58+ runsData &&
59+ ! completeIsChecked . current &&
60+ location . pathname !== ROUTES . PROJECT . ADD
61+ ) {
4462 const billingCompleted = userBillingData . balance > 0 ;
4563 const configureCLICompleted = runsData . length > 0 ;
64+ const createProjectCompleted = projectData . length > 0 ;
4665
4766 let tempHideStartUp = hideStartUp ;
4867
4968 if ( hideStartUp === null ) {
50- tempHideStartUp = billingCompleted && configureCLICompleted ;
69+ tempHideStartUp = billingCompleted && configureCLICompleted && createProjectCompleted ;
5170 }
5271
5372 // Set hideStartUp without updating localstorage
54- dispatch ( updateTutorialPanelState ( { billingCompleted, configureCLICompleted, hideStartUp : tempHideStartUp } ) ) ;
73+ dispatch (
74+ updateTutorialPanelState ( {
75+ billingCompleted,
76+ configureCLICompleted,
77+ createProjectCompleted,
78+ hideStartUp : tempHideStartUp ,
79+ } ) ,
80+ ) ;
5581
5682 if ( ! tempHideStartUp && process . env . UI_VERSION === 'sky' ) {
5783 dispatch ( openTutorialPanel ( ) ) ;
5884 }
5985
6086 completeIsChecked . current = true ;
6187 }
62- } , [ userBillingData , runsData ] ) ;
88+ } , [ userBillingData , runsData , projectData , location . pathname ] ) ;
89+
90+ useEffect ( ( ) => {
91+ if ( projectData && projectData . length > 0 && ! createProjectCompleted ) {
92+ dispatch (
93+ updateTutorialPanelState ( {
94+ createProjectCompleted : true ,
95+ } ) ,
96+ ) ;
97+ }
98+ } , [ projectData ] ) ;
6399
64100 const startBillingTutorial = useCallback ( ( ) => {
65101 navigate ( billingUrl ) ;
@@ -69,6 +105,14 @@ export const useTutorials = () => {
69105 dispatch ( updateTutorialPanelState ( { billingCompleted : true } ) ) ;
70106 } , [ ] ) ;
71107
108+ const startFirstProjectTutorial = useCallback ( ( ) => {
109+ navigate ( ROUTES . PROJECT . ADD ) ;
110+ } , [ ] ) ;
111+
112+ const finishFirstProjectTutorial = useCallback ( ( ) => {
113+ dispatch ( updateTutorialPanelState ( { createProjectCompleted : true } ) ) ;
114+ } , [ ] ) ;
115+
72116 const startConfigCliTutorial = useCallback ( ( ) => { } , [ billingUrl ] ) ;
73117
74118 const finishConfigCliTutorial = useCallback ( ( ) => {
@@ -103,44 +147,54 @@ export const useTutorials = () => {
103147 // },
104148
105149 {
106- ...CONFIGURE_CLI_TUTORIAL ,
150+ ...CREATE_FIRST_PROJECT ,
107151 id : 2 ,
152+ completed : createProjectCompleted ,
153+ startCallback : startFirstProjectTutorial ,
154+ finishCallback : finishFirstProjectTutorial ,
155+ } ,
156+
157+ {
158+ ...CONFIGURE_CLI_TUTORIAL ,
159+ id : 3 ,
108160 completed : configureCLICompleted ,
109161 startCallback : startConfigCliTutorial ,
110162 finishCallback : finishConfigCliTutorial ,
111163 } ,
112164
113165 {
114166 ...BILLING_TUTORIAL ,
115- id : 3 ,
167+ id : 4 ,
116168 completed : billingCompleted ,
117169 startCallback : startBillingTutorial ,
118170 finishCallback : finishBillingTutorial ,
119171 } ,
120172
121173 {
122174 ...QUICKSTART_TUTORIAL ,
123- id : 4 ,
175+ id : 5 ,
124176 startWithoutActivation : true ,
125177 completed : quickStartCompleted ,
126178 startCallback : startQuickStartTutorial ,
127179 } ,
128180
129181 {
130182 ...JOIN_DISCORD_TUTORIAL ,
131- id : 5 ,
183+ id : 6 ,
132184 startWithoutActivation : true ,
133185 completed : discordCompleted ,
134186 startCallback : startDiscordTutorial ,
135187 } ,
136188 ] ;
137189 } , [
138190 billingUrl ,
191+ createProjectCompleted ,
139192 quickStartCompleted ,
140193 discordCompleted ,
141194 tallyCompleted ,
142195 billingCompleted ,
143196 configureCLICompleted ,
197+ finishFirstProjectTutorial ,
144198 finishBillingTutorial ,
145199 finishConfigCliTutorial ,
146200 ] ) ;
0 commit comments