Skip to content

Commit

Permalink
Merge pull request #2207 from daostack/bugfix/CW-2181-common-without-…
Browse files Browse the repository at this point in the history
…picture

when try to create a common with no picture nothin happens #2181
  • Loading branch information
andreymikhadyuk authored Oct 17, 2023
2 parents 7a1884e + 98d1a14 commit fd80c64
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ const ProjectCreationForm: FC<ProjectCreationFormProps> = (props) => {
ref={formRef}
initialValues={initialValues}
onSubmit={isEditing ? handleProjectUpdate : handleProjectCreate}
items={getConfiguration(true, roles, {
existingNames: existingProjectsNames,
items={getConfiguration({
isProject: true,
roles,
shouldBeUnique: {
existingNames: existingProjectsNames,
},
})}
submitButtonText={isEditing ? "Save changes" : "Create Space"}
disabled={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ import {
} from "../../constants";
import styles from "./ProjectCreationForm.module.scss";

export const getConfiguration = (
isProject = true,
roles?: Roles,
shouldBeUnique?: { existingNames: string[] },
): CreationFormItem[] => {
interface Options {
isProject: boolean;
roles?: Roles;
shouldBeUnique?: { existingNames: string[] };
isImageRequired?: boolean;
}

export const getConfiguration = (options: Options): CreationFormItem[] => {
const {
isProject = true,
roles,
shouldBeUnique,
isImageRequired = false,
} = options;
const type = isProject ? "Space" : "Common";

const items: CreationFormItem[] = [
Expand All @@ -22,9 +31,17 @@ export const getConfiguration = (
className: styles.projectImages,
props: {
name: "projectImages",
label: `${type} picture`,
label: `${type} picture${isImageRequired ? " (required)" : ""}`,
maxImagesAmount: 1,
},
validation: isImageRequired
? {
min: {
value: 1,
message: `${type} picture is required`,
},
}
: undefined,
},
{
type: CreationFormItemType.TextField,
Expand Down
6 changes: 5 additions & 1 deletion src/pages/commonCreation/hooks/useCommonForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export const useCommonForm = (
return {
initialValues,
onSubmit,
formItems: getConfiguration(false, roles),
formItems: getConfiguration({
isProject: false,
roles,
isImageRequired: true,
}),
};
};

0 comments on commit fd80c64

Please sign in to comment.