1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: update validateProjectId

This commit is contained in:
Youssef 2022-01-25 12:30:55 +01:00
parent 8c7acdc43d
commit 52fddb2069
4 changed files with 14 additions and 16 deletions

View File

@ -26,7 +26,6 @@ const CreateProject = () => {
clearErrors,
validateIdUniqueness,
validateName,
validateProjectId,
errors,
} = useProjectForm();
@ -36,10 +35,9 @@ const CreateProject = () => {
e.preventDefault();
clearErrors();
const validName = validateName();
const validProjectId = validateProjectId();
const validId = await validateIdUniqueness();
if (validName && validId && validProjectId) {
if (validName && validId) {
const payload = getProjectPayload();
try {
await createProject(payload);
@ -67,7 +65,7 @@ const CreateProject = () => {
};
const handleCancel = () => {
history.push('/projects');
history.goBack();
};
return (
@ -92,10 +90,7 @@ const CreateProject = () => {
clearErrors={clearErrors}
validateIdUniqueness={validateIdUniqueness}
>
<PermissionButton
permission={CREATE_PROJECT}
type="submit"
>
<PermissionButton permission={CREATE_PROJECT} type="submit">
Create project
</PermissionButton>
</ProjectForm>

View File

@ -39,6 +39,10 @@ const useProjectForm = (
const NAME_EXISTS_ERROR = 'Error: A project with this id already exists.';
const validateIdUniqueness = async () => {
if (projectId.length === 0) {
setErrors(prev => ({ ...prev, id: 'Id can not be empty.' }));
return false;
}
try {
await validateId(getProjectPayload());
return true;

View File

@ -75,11 +75,9 @@ const CreateTagType = () => {
setTagDesc={setTagDesc}
mode="Create"
clearErrors={clearErrors}
validateNameUniqueness={validateNameUniqueness}
>
<PermissionButton
permission={UPDATE_TAG_TYPE}
type="submit"
>
<PermissionButton permission={UPDATE_TAG_TYPE} type="submit">
Create type
</PermissionButton>
</TagTypeForm>

View File

@ -16,6 +16,7 @@ interface ITagTypeForm {
errors: { [key: string]: string };
mode: string;
clearErrors: () => void;
validateNameUniqueness?: () => void;
}
const TagTypeForm: React.FC<ITagTypeForm> = ({
@ -28,6 +29,7 @@ const TagTypeForm: React.FC<ITagTypeForm> = ({
setTagDesc,
errors,
mode,
validateNameUniqueness,
clearErrors,
}) => {
const styles = useStyles();
@ -49,11 +51,10 @@ const TagTypeForm: React.FC<ITagTypeForm> = ({
errorText={errors.name}
onFocus={() => clearErrors()}
disabled={mode === EDIT}
onBlur={validateNameUniqueness}
/>
<p className={styles.inputDescription}>
What is this role for?
</p>
<p className={styles.inputDescription}>What is this tag for?</p>
<TextField
className={styles.input}
label="Tag description"