mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: update validateProjectId
This commit is contained in:
		
							parent
							
								
									8c7acdc43d
								
							
						
					
					
						commit
						52fddb2069
					
				@ -26,7 +26,6 @@ const CreateProject = () => {
 | 
				
			|||||||
        clearErrors,
 | 
					        clearErrors,
 | 
				
			||||||
        validateIdUniqueness,
 | 
					        validateIdUniqueness,
 | 
				
			||||||
        validateName,
 | 
					        validateName,
 | 
				
			||||||
        validateProjectId,
 | 
					 | 
				
			||||||
        errors,
 | 
					        errors,
 | 
				
			||||||
    } = useProjectForm();
 | 
					    } = useProjectForm();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -36,10 +35,9 @@ const CreateProject = () => {
 | 
				
			|||||||
        e.preventDefault();
 | 
					        e.preventDefault();
 | 
				
			||||||
        clearErrors();
 | 
					        clearErrors();
 | 
				
			||||||
        const validName = validateName();
 | 
					        const validName = validateName();
 | 
				
			||||||
        const validProjectId = validateProjectId();
 | 
					 | 
				
			||||||
        const validId = await validateIdUniqueness();
 | 
					        const validId = await validateIdUniqueness();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (validName && validId && validProjectId) {
 | 
					        if (validName && validId) {
 | 
				
			||||||
            const payload = getProjectPayload();
 | 
					            const payload = getProjectPayload();
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                await createProject(payload);
 | 
					                await createProject(payload);
 | 
				
			||||||
@ -67,7 +65,7 @@ const CreateProject = () => {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const handleCancel = () => {
 | 
					    const handleCancel = () => {
 | 
				
			||||||
        history.push('/projects');
 | 
					        history.goBack();
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
@ -92,10 +90,7 @@ const CreateProject = () => {
 | 
				
			|||||||
                clearErrors={clearErrors}
 | 
					                clearErrors={clearErrors}
 | 
				
			||||||
                validateIdUniqueness={validateIdUniqueness}
 | 
					                validateIdUniqueness={validateIdUniqueness}
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
                <PermissionButton
 | 
					                <PermissionButton permission={CREATE_PROJECT} type="submit">
 | 
				
			||||||
                    permission={CREATE_PROJECT}
 | 
					 | 
				
			||||||
                    type="submit"
 | 
					 | 
				
			||||||
                >
 | 
					 | 
				
			||||||
                    Create project
 | 
					                    Create project
 | 
				
			||||||
                </PermissionButton>
 | 
					                </PermissionButton>
 | 
				
			||||||
            </ProjectForm>
 | 
					            </ProjectForm>
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,10 @@ const useProjectForm = (
 | 
				
			|||||||
    const NAME_EXISTS_ERROR = 'Error: A project with this id already exists.';
 | 
					    const NAME_EXISTS_ERROR = 'Error: A project with this id already exists.';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const validateIdUniqueness = async () => {
 | 
					    const validateIdUniqueness = async () => {
 | 
				
			||||||
 | 
					        if (projectId.length === 0) {
 | 
				
			||||||
 | 
					            setErrors(prev => ({ ...prev, id: 'Id can not be empty.' }));
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            await validateId(getProjectPayload());
 | 
					            await validateId(getProjectPayload());
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
 | 
				
			|||||||
@ -75,11 +75,9 @@ const CreateTagType = () => {
 | 
				
			|||||||
                setTagDesc={setTagDesc}
 | 
					                setTagDesc={setTagDesc}
 | 
				
			||||||
                mode="Create"
 | 
					                mode="Create"
 | 
				
			||||||
                clearErrors={clearErrors}
 | 
					                clearErrors={clearErrors}
 | 
				
			||||||
 | 
					                validateNameUniqueness={validateNameUniqueness}
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
                <PermissionButton
 | 
					                <PermissionButton permission={UPDATE_TAG_TYPE} type="submit">
 | 
				
			||||||
                    permission={UPDATE_TAG_TYPE}
 | 
					 | 
				
			||||||
                    type="submit"
 | 
					 | 
				
			||||||
                >
 | 
					 | 
				
			||||||
                    Create type
 | 
					                    Create type
 | 
				
			||||||
                </PermissionButton>
 | 
					                </PermissionButton>
 | 
				
			||||||
            </TagTypeForm>
 | 
					            </TagTypeForm>
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,7 @@ interface ITagTypeForm {
 | 
				
			|||||||
    errors: { [key: string]: string };
 | 
					    errors: { [key: string]: string };
 | 
				
			||||||
    mode: string;
 | 
					    mode: string;
 | 
				
			||||||
    clearErrors: () => void;
 | 
					    clearErrors: () => void;
 | 
				
			||||||
 | 
					    validateNameUniqueness?: () => void;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TagTypeForm: React.FC<ITagTypeForm> = ({
 | 
					const TagTypeForm: React.FC<ITagTypeForm> = ({
 | 
				
			||||||
@ -28,6 +29,7 @@ const TagTypeForm: React.FC<ITagTypeForm> = ({
 | 
				
			|||||||
    setTagDesc,
 | 
					    setTagDesc,
 | 
				
			||||||
    errors,
 | 
					    errors,
 | 
				
			||||||
    mode,
 | 
					    mode,
 | 
				
			||||||
 | 
					    validateNameUniqueness,
 | 
				
			||||||
    clearErrors,
 | 
					    clearErrors,
 | 
				
			||||||
}) => {
 | 
					}) => {
 | 
				
			||||||
    const styles = useStyles();
 | 
					    const styles = useStyles();
 | 
				
			||||||
@ -49,11 +51,10 @@ const TagTypeForm: React.FC<ITagTypeForm> = ({
 | 
				
			|||||||
                    errorText={errors.name}
 | 
					                    errorText={errors.name}
 | 
				
			||||||
                    onFocus={() => clearErrors()}
 | 
					                    onFocus={() => clearErrors()}
 | 
				
			||||||
                    disabled={mode === EDIT}
 | 
					                    disabled={mode === EDIT}
 | 
				
			||||||
 | 
					                    onBlur={validateNameUniqueness}
 | 
				
			||||||
                />
 | 
					                />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <p className={styles.inputDescription}>
 | 
					                <p className={styles.inputDescription}>What is this tag for?</p>
 | 
				
			||||||
                    What is this role for?
 | 
					 | 
				
			||||||
                </p>
 | 
					 | 
				
			||||||
                <TextField
 | 
					                <TextField
 | 
				
			||||||
                    className={styles.input}
 | 
					                    className={styles.input}
 | 
				
			||||||
                    label="Tag description"
 | 
					                    label="Tag description"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user