@@ -27,6 +27,7 @@ import type { ModalProps } from '#contexts/Modal/modal-context.ts';
2727import { useImportAgent } from '#modules/agents/hooks/useImportAgent.ts' ;
2828import type { ImportAgentFormValues } from '#modules/agents/types.ts' ;
2929import { ProviderSource } from '#modules/providers/types.ts' ;
30+ import { isValidUrl } from '#utils/url.ts' ;
3031
3132import classes from './ImportAgentsModal.module.scss' ;
3233
@@ -43,10 +44,10 @@ export function ImportAgentsModal({ onRequestClose, ...modalProps }: ModalProps)
4344 register,
4445 handleSubmit,
4546 resetField,
46- formState : { isValid } ,
47+ formState : { isValid, errors } ,
4748 control,
4849 } = useForm < ImportAgentFormValues > ( {
49- mode : 'onChange ' ,
50+ mode : 'onTouched ' ,
5051 defaultValues : {
5152 source : featureFlags . ProviderBuilds ? ProviderSource . GitHub : ProviderSource . Docker ,
5253 } ,
@@ -139,25 +140,34 @@ export function ImportAgentsModal({ onRequestClose, ...modalProps }: ModalProps)
139140 < RadioButton labelText = "Container image URL" value = { ProviderSource . Docker } />
140141 </ RadioButtonGroup >
141142
142- { sourceField . value === ProviderSource . GitHub ? (
143- < TextInput
144- id = { `${ id } :location` }
145- size = "lg"
146- labelText = "GitHub repository URL"
147- placeholder = "Enter your agent’s GitHub repository URL"
148- hideLabel
149- { ...register ( 'location' , { required : true , disabled : isPending } ) }
150- />
151- ) : (
152- < TextInput
153- id = { `${ id } :location` }
154- size = "lg"
155- labelText = "Container image URL"
156- placeholder = "Enter your agent’s container image URL"
157- hideLabel
158- { ...register ( 'location' , { required : true , disabled : isPending } ) }
159- />
160- ) }
143+ < TextInput
144+ id = { `${ id } :location` }
145+ size = "lg"
146+ hideLabel
147+ invalid = { Boolean ( errors . location ) }
148+ invalidText = { errors . location ?. message }
149+ { ...( sourceField . value === ProviderSource . GitHub
150+ ? {
151+ labelText : 'GitHub repository URL' ,
152+ placeholder : 'Enter your agent’s GitHub repository URL' ,
153+ }
154+ : {
155+ labelText : 'Container image URL' ,
156+ placeholder : 'Enter your agent’s container image URL' ,
157+ } ) }
158+ { ...register ( 'location' , {
159+ required : 'Enter your agent’s location.' ,
160+ disabled : isPending ,
161+ setValueAs : ( value : string ) => value . trim ( ) ,
162+ validate : ( value : string ) => {
163+ if ( sourceField . value === ProviderSource . GitHub ) {
164+ return isValidUrl ( value ) || 'Enter a valid GitHub repository URL.' ;
165+ }
166+
167+ return true ;
168+ } ,
169+ } ) }
170+ />
161171 </ div >
162172 ) }
163173
0 commit comments