@@ -76,6 +76,13 @@ export function CreateOrganizationDialog({
7676 metadata : { } ,
7777 } ) ;
7878 const [ slugManuallyEdited , setSlugManuallyEdited ] = useState ( false ) ;
79+ const [ touchedFields , setTouchedFields ] = useState < {
80+ name : boolean ;
81+ slug : boolean ;
82+ } > ( {
83+ name : false ,
84+ slug : false ,
85+ } ) ;
7986
8087 // Image upload state
8188 const [ preview , setPreview ] = useState < string | null > ( null ) ;
@@ -106,6 +113,7 @@ export function CreateOrganizationDialog({
106113 setPreview ( null ) ;
107114 setLogoFile ( null ) ;
108115 setSlugManuallyEdited ( false ) ;
116+ setTouchedFields ( { name : false , slug : false } ) ;
109117 resetCropState ( ) ;
110118 setIsCropModalOpen ( false ) ;
111119 } ;
@@ -299,16 +307,19 @@ export function CreateOrganizationDialog({
299307 </ Label >
300308 { ( ( ) => {
301309 const isNameValid = formData . name . trim ( ) . length >= 2 ;
310+ const hasUserTyped = formData . name . length > 0 ;
311+ const shouldShowError = ( touchedFields . name || hasUserTyped ) && ! isNameValid ;
302312 return (
303313 < >
304314 < Input
305315 aria-describedby = "org-name-help"
306- aria-invalid = { ! isNameValid }
316+ aria-invalid = { shouldShowError }
307317 className = { `rounded border-border/50 focus:border-primary/50 focus:ring-primary/20 ${
308- isNameValid ? '' : 'border-destructive '
318+ shouldShowError ? 'border-destructive ' : ''
309319 } `}
310320 id = "org-name"
311321 maxLength = { 100 }
322+ onBlur = { ( ) => setTouchedFields ( prev => ( { ...prev , name : true } ) ) }
312323 onChange = { ( e ) =>
313324 setFormData ( ( prev ) => ( {
314325 ...prev ,
@@ -340,16 +351,19 @@ export function CreateOrganizationDialog({
340351 const isSlugValid =
341352 SLUG_ALLOWED_REGEX . test ( formData . slug || '' ) &&
342353 ( formData . slug || '' ) . trim ( ) . length >= 2 ;
354+ const hasUserTyped = ( formData . slug || '' ) . length > 0 ;
355+ const shouldShowError = ( touchedFields . slug || hasUserTyped ) && ! isSlugValid ;
343356 return (
344357 < >
345358 < Input
346359 aria-describedby = "org-slug-help"
347- aria-invalid = { ! isSlugValid }
360+ aria-invalid = { shouldShowError }
348361 className = { `rounded border-border/50 focus:border-primary/50 focus:ring-primary/20 ${
349- isSlugValid ? '' : 'border-destructive '
362+ shouldShowError ? 'border-destructive ' : ''
350363 } `}
351364 id = "org-slug"
352365 maxLength = { 50 }
366+ onBlur = { ( ) => setTouchedFields ( prev => ( { ...prev , slug : true } ) ) }
353367 onChange = { ( e ) => handleSlugChange ( e . target . value ) }
354368 placeholder = "e.g., acme-corp"
355369 value = { formData . slug }
0 commit comments