Skip to content

Commit

Permalink
subcommunity: updated fieldpaths and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Jun 28, 2024
1 parent 89f80d6 commit b25e9e6
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ const IdentifierField = ({ formConfig }) => {
return (
<TextField
required
id="community.slug"
id="metadata.slug"
label={
<FieldLabel
htmlFor="community.slug"
htmlFor="metadata.slug"
icon="barcode"
label={i18next.t("Identifier")}
/>
}
fieldPath="community.slug"
fieldPath="metadata.slug"
helpText={helpText}
fluid
className="text-muted"
Expand Down Expand Up @@ -84,7 +84,7 @@ class CommunityCreateForm extends Component {
.filter((item) => !item?.parent?.id)
.filter((item) => !item?.children?.allow === true)
.map((item) => ({
text: item.community.title,
text: item.metadata.title,
value: item.id,
key: item.id,
})),
Expand Down Expand Up @@ -112,12 +112,12 @@ class CommunityCreateForm extends Component {
let payload = {};
let slug = "";
if (hasCommunity) {
payload = { community_id: values["community"]["community"] };
payload = { community_id: values["metadata"]["community"] };
} else {
slug = values["community"]["slug"];
slug = values["metadata"]["slug"];
payload = {
community: {
title: values["community"]["title"],
title: values["metadata"]["title"],
slug: slug,
},
};
Expand All @@ -139,15 +139,17 @@ class CommunityCreateForm extends Component {
const { errors, message } = communityErrorSerializer(error);

if (message) {
this.setGlobalError("The form contains errors or missing fields. Please verify before submitting");
this.setGlobalError(
"The form contains errors or missing fields. Please verify before submitting"
);
}

if (errors) {
errors.map(({ field, messages }) => {

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.10, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.11, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.10, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.11, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function

Check warning on line 148 in invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2)

Array.prototype.map() expects a return value from arrow function
// Check if the field is already prefixed with "metadata"
if (!field.startsWith("metadata")) {
// Add "metadata" prefix if not already present
field = `metadata.${field.split('.').pop()}`;
field = `metadata.${field.split(".").pop()}`;
}
setFieldError(field, messages[0]);
});
Expand Down Expand Up @@ -212,7 +214,7 @@ class CommunityCreateForm extends Component {
onChange={() => {
this.setState({ hasCommunity: true });
}}
fieldPath="community.hasCommunity"
fieldPath="metadata.hasCommunity"
/>
<RadioField
label={i18next.t("No")}
Expand All @@ -221,7 +223,7 @@ class CommunityCreateForm extends Component {
onChange={() => {
this.setState({ hasCommunity: false });
}}
fieldPath="community.hasCommunity"
fieldPath="metadata.hasCommunity"
/>
</Form.Group>
</div>
Expand All @@ -235,7 +237,7 @@ class CommunityCreateForm extends Component {
class="block"
/>
}
fieldPath="community.community"
fieldPath="metadata.community"
options={communities}
defaultValue="Loading..."
required
Expand All @@ -246,16 +248,16 @@ class CommunityCreateForm extends Component {
<>
<TextField
required
id="community.title"
id="metadata.title"
fluid
fieldPath="community.title"
fieldPath="metadata.title"
// Prevent submitting before the value is updated:
onKeyDown={(e) => {
e.key === "Enter" && e.preventDefault();
}}
label={
<FieldLabel
htmlFor="community.title"
htmlFor="metadata.title"
icon="book"
label={i18next.t("Community name")}
/>
Expand Down

0 comments on commit b25e9e6

Please sign in to comment.