mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: copy feature double validation popup (#1117)
* fix: copy feature double validation popup * fix: add aria-required, validate on submit * refactor: rename variable to be more consistent with codebase
This commit is contained in:
		
							parent
							
								
									853d763194
								
							
						
					
					
						commit
						38cfc549f2
					
				| @ -1,10 +1,4 @@ | |||||||
| import { | import { useState, FormEventHandler, ChangeEventHandler } from 'react'; | ||||||
|     useState, |  | ||||||
|     useRef, |  | ||||||
|     useEffect, |  | ||||||
|     FormEventHandler, |  | ||||||
|     ChangeEventHandler, |  | ||||||
| } from 'react'; |  | ||||||
| import { Link, useNavigate } from 'react-router-dom'; | import { Link, useNavigate } from 'react-router-dom'; | ||||||
| import { | import { | ||||||
|     Button, |     Button, | ||||||
| @ -31,16 +25,11 @@ export const CopyFeatureToggle = () => { | |||||||
|     const [nameError, setNameError] = useState<string | undefined>(); |     const [nameError, setNameError] = useState<string | undefined>(); | ||||||
|     const [newToggleName, setNewToggleName] = useState<string>(); |     const [newToggleName, setNewToggleName] = useState<string>(); | ||||||
|     const { cloneFeatureToggle, validateFeatureToggleName } = useFeatureApi(); |     const { cloneFeatureToggle, validateFeatureToggleName } = useFeatureApi(); | ||||||
|     const inputRef = useRef<HTMLInputElement>(); |  | ||||||
|     const featureId = useRequiredPathParam('featureId'); |     const featureId = useRequiredPathParam('featureId'); | ||||||
|     const projectId = useRequiredPathParam('projectId'); |     const projectId = useRequiredPathParam('projectId'); | ||||||
|     const { feature } = useFeature(projectId, featureId); |     const { feature } = useFeature(projectId, featureId); | ||||||
|     const navigate = useNavigate(); |     const navigate = useNavigate(); | ||||||
| 
 | 
 | ||||||
|     useEffect(() => { |  | ||||||
|         inputRef.current?.focus(); |  | ||||||
|     }, []); |  | ||||||
| 
 |  | ||||||
|     const setValue: ChangeEventHandler<HTMLInputElement> = event => { |     const setValue: ChangeEventHandler<HTMLInputElement> = event => { | ||||||
|         const value = trim(event.target.value); |         const value = trim(event.target.value); | ||||||
|         setNewToggleName(value); |         setNewToggleName(value); | ||||||
| @ -53,17 +42,20 @@ export const CopyFeatureToggle = () => { | |||||||
|     const onValidateName = async () => { |     const onValidateName = async () => { | ||||||
|         try { |         try { | ||||||
|             await validateFeatureToggleName(newToggleName); |             await validateFeatureToggleName(newToggleName); | ||||||
| 
 |  | ||||||
|             setNameError(undefined); |             setNameError(undefined); | ||||||
|  |             return true; | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|             setNameError(formatUnknownError(error)); |             setNameError(formatUnknownError(error)); | ||||||
|         } |         } | ||||||
|  |         return false; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     const onSubmit: FormEventHandler = async event => { |     const onSubmit: FormEventHandler = async event => { | ||||||
|         event.preventDefault(); |         event.preventDefault(); | ||||||
| 
 | 
 | ||||||
|         if (nameError) { |         const isValidName = await onValidateName(); | ||||||
|  | 
 | ||||||
|  |         if (!isValidName) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -113,8 +105,8 @@ export const CopyFeatureToggle = () => { | |||||||
|                         helperText={nameError} |                         helperText={nameError} | ||||||
|                         variant="outlined" |                         variant="outlined" | ||||||
|                         size="small" |                         size="small" | ||||||
|                         inputRef={inputRef} |                         aria-required | ||||||
|                         required |                         autoFocus | ||||||
|                     /> |                     /> | ||||||
|                     <FormControlLabel |                     <FormControlLabel | ||||||
|                         control={ |                         control={ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user