@@ -16,7 +16,6 @@ import { ROUTES } from 'routes';
1616import { useApplyRunMutation } from 'services/run' ;
1717
1818import { OfferList } from 'pages/Offers/List' ;
19- import { convertMiBToGB , renderRange , round } from 'pages/Offers/List/helpers' ;
2019
2120import { getRunSpecFromYaml } from './helpers/getRunSpecFromYaml' ;
2221import { useGenerateYaml } from './hooks/useGenerateYaml' ;
@@ -27,6 +26,7 @@ import styles from './styles.module.scss';
2726
2827const requiredFieldError = 'This is required field' ;
2928const namesFieldError = 'Only latin characters, dashes, and digits' ;
29+ const urlFormatError = 'Only URLs' ;
3030
3131const ideOptions = [
3232 {
@@ -49,6 +49,16 @@ const envValidationSchema = yup.object({
4949 name : yup . string ( ) . matches ( / ^ [ a - z ] [ a - z 0 - 9 - ] { 1 , 40 } $ / , namesFieldError ) ,
5050 ide : yup . string ( ) . required ( requiredFieldError ) ,
5151 config_yaml : yup . string ( ) . required ( requiredFieldError ) ,
52+
53+ image : yup . string ( ) . when ( 'docker' , {
54+ is : true ,
55+ then : yup . string ( ) . required ( requiredFieldError ) ,
56+ } ) ,
57+
58+ repo_url : yup . string ( ) . when ( 'repo_enabled' , {
59+ is : true ,
60+ then : yup . string ( ) . url ( urlFormatError ) . required ( requiredFieldError ) ,
61+ } ) ,
5262} ) ;
5363
5464// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -94,8 +104,6 @@ export const CreateDevEnvironment: React.FC = () => {
94104 const navigate = useNavigate ( ) ;
95105 const [ pushNotification ] = useNotifications ( ) ;
96106 const [ activeStepIndex , setActiveStepIndex ] = useState ( 0 ) ;
97- const [ isEnabledRepo , setIsEnabledRepo ] = useState ( false ) ;
98- const [ activeTab , setActiveTab ] = useState ( DockerPythonTabs . DOCKER ) ;
99107 const [ selectedOffers , setSelectedOffers ] = useState < IGpu [ ] > ( [ ] ) ;
100108 const [ selectedProject , setSelectedProject ] = useState < IProject [ 'project_name' ] | null > (
101109 ( ) => searchParams . get ( 'project_name' ) ?? null ,
@@ -121,6 +129,8 @@ export const CreateDevEnvironment: React.FC = () => {
121129 resolver,
122130 defaultValues : {
123131 ide : 'cursor' ,
132+ docker : true ,
133+ repo_enabled : false ,
124134 } ,
125135 } ) ;
126136 const { handleSubmit, control, trigger, setValue, watch, formState, getValues } = formMethods ;
@@ -134,24 +144,22 @@ export const CreateDevEnvironment: React.FC = () => {
134144 return await trigger ( [ 'offer' ] ) ;
135145 } ;
136146
137- const validateName = async ( ) => {
138- return await trigger ( [ 'name' , 'ide' ] ) ;
147+ const validateSecondStep = async ( ) => {
148+ return await trigger ( [ 'name' , 'ide' , 'docker' , 'image' , 'python' , 'repo_enabled' , 'repo_url' , 'repo_local_path' ] ) ;
139149 } ;
140150
141151 const validateConfig = async ( ) => {
142152 return await trigger ( [ 'config_yaml' ] ) ;
143153 } ;
144154
145- const emptyValidator = async ( ) => Promise . resolve ( true ) ;
146-
147155 const onNavigate = ( {
148156 requestedStepIndex,
149157 reason,
150158 } : {
151159 requestedStepIndex : number ;
152160 reason : WizardProps . NavigationReason ;
153161 } ) => {
154- const stepValidators = [ validateOffer , validateName , validateConfig , emptyValidator ] ;
162+ const stepValidators = [ validateOffer , validateSecondStep , validateConfig ] ;
155163
156164 if ( reason === 'next' ) {
157165 stepValidators [ activeStepIndex ] ?.( ) . then ( ( isValid ) => {
@@ -171,7 +179,7 @@ export const CreateDevEnvironment: React.FC = () => {
171179 } ;
172180
173181 const toggleRepo : ToggleProps [ 'onChange' ] = ( { detail } ) => {
174- setIsEnabledRepo ( detail . checked ) ;
182+ setValue ( 'repo_enabled' , detail . checked ) ;
175183
176184 if ( ! detail . checked ) {
177185 setValue ( 'repo_url' , '' ) ;
@@ -187,6 +195,8 @@ export const CreateDevEnvironment: React.FC = () => {
187195 if ( detail . activeTabId === DockerPythonTabs . PYTHON ) {
188196 setValue ( 'image' , '' ) ;
189197 }
198+
199+ setValue ( 'docker' , detail . activeTabId === DockerPythonTabs . DOCKER ) ;
190200 } ;
191201
192202 const onChangeOffer : CardsProps < IGpu > [ 'onSelectionChange' ] = ( { detail } ) => {
@@ -360,11 +370,11 @@ export const CreateDevEnvironment: React.FC = () => {
360370 ] }
361371 />
362372
363- < Toggle checked = { isEnabledRepo } onChange = { toggleRepo } >
373+ < Toggle checked = { ! ! formValues . repo_enabled } onChange = { toggleRepo } >
364374 { t ( 'runs.dev_env.wizard.repo' ) }
365375 </ Toggle >
366376
367- { isEnabledRepo && (
377+ { formValues . repo_enabled && (
368378 < >
369379 < FormInput
370380 label = { t ( 'runs.dev_env.wizard.repo_url' ) }
0 commit comments