@@ -5,20 +5,22 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
55import cn from 'classnames' ;
66import * as yup from 'yup' ;
77import { Box , Link , WizardProps } from '@cloudscape-design/components' ;
8+ import { ButtonProps } from '@cloudscape-design/components/button' ;
89import { CardsProps } from '@cloudscape-design/components/cards' ;
910
10- import type { TabsProps , ToggleProps } from 'components' ;
11+ import { Alert , Button , TabsProps , ToggleProps } from 'components' ;
1112import { Container , FormCodeEditor , FormField , FormInput , FormSelect , SpaceBetween , Tabs , Toggle , Wizard } from 'components' ;
1213
1314import { useBreadcrumbs , useNotifications } from 'hooks' ;
14- import { getServerError } from 'libs' ;
15+ import { getServerError , goToUrl } from 'libs' ;
1516import { ROUTES } from 'routes' ;
1617import { useApplyRunMutation } from 'services/run' ;
1718
1819import { OfferList } from 'pages/Offers/List' ;
1920
2021import { useGenerateYaml } from './hooks/useGenerateYaml' ;
2122import { useGetRunSpecFromYaml } from './hooks/useGetRunSpecFromYaml' ;
23+ import { useCheckingForFleetsInProjects } from '../../../hooks/useCheckingForFleetsInProjectsOfMember' ;
2224import { FORM_FIELD_NAMES } from './constants' ;
2325
2426import { IRunEnvironmentFormKeys , IRunEnvironmentFormValues } from './types' ;
@@ -117,6 +119,9 @@ export const CreateDevEnvironment: React.FC = () => {
117119
118120 const [ getRunSpecFromYaml ] = useGetRunSpecFromYaml ( { projectName : selectedProject ?? '' } ) ;
119121
122+ const projectHavingFleetMap = useCheckingForFleetsInProjects ( { projectNames : selectedProject ? [ selectedProject ] : [ ] } ) ;
123+ const projectDontHasFleets = ! ! selectedProject && ! projectHavingFleetMap [ selectedProject ] ;
124+
120125 const [ applyRun , { isLoading : isApplying } ] = useApplyRunMutation ( ) ;
121126
122127 const loading = isApplying ;
@@ -174,6 +179,10 @@ export const CreateDevEnvironment: React.FC = () => {
174179 const stepValidators = [ validateOffer , validateSecondStep , validateConfig ] ;
175180
176181 if ( reason === 'next' ) {
182+ if ( projectDontHasFleets ) {
183+ window . scrollTo ( 0 , 0 ) ;
184+ }
185+
177186 stepValidators [ activeStepIndex ] ?.( ) . then ( ( isValid ) => {
178187 if ( isValid ) {
179188 setActiveStepIndex ( requestedStepIndex ) ;
@@ -275,8 +284,29 @@ export const CreateDevEnvironment: React.FC = () => {
275284 setValue ( 'config_yaml' , yaml ) ;
276285 } , [ yaml ] ) ;
277286
287+ const onCreateAFleet : ButtonProps [ 'onClick' ] = ( event ) => {
288+ event . preventDefault ( ) ;
289+ goToUrl ( 'https://dstack.ai/docs/quickstart/#create-a-fleet' , true ) ;
290+ } ;
291+
278292 return (
279293 < form className = { cn ( { [ styles . wizardForm ] : activeStepIndex === 0 } ) } onSubmit = { handleSubmit ( onSubmit ) } >
294+ { projectDontHasFleets && (
295+ < div className = { styles . alertBox } >
296+ < Alert
297+ header = { t ( 'fleets.no_alert.title' ) }
298+ type = "info"
299+ action = {
300+ < Button iconName = "external" formAction = "none" onClick = { onCreateAFleet } >
301+ { t ( 'fleets.no_alert.button_title' ) }
302+ </ Button >
303+ }
304+ >
305+ The project < code > { selectedProject } </ code > has no fleets. Create one before submitting a run.
306+ </ Alert >
307+ </ div >
308+ ) }
309+
280310 < Wizard
281311 activeStepIndex = { activeStepIndex }
282312 onNavigate = { onNavigateHandler }
0 commit comments