Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subcommunity: updated error mapping in the ui #1170

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@
"This is your community's unique identifier. You will be able to access your community through the URL:"
)}
<br />
{`${formConfig.SITE_UI_URL}/communities/${values["community"]["slug"]}`}
{`${formConfig.SITE_UI_URL}/communities/${values["metadata"]["slug"]}`}
</>
);

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 @@
.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 @@
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,11 +139,20 @@
const { errors, message } = communityErrorSerializer(error);

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

if (errors) {
errors.map(({ field, messages }) => setFieldError(field, messages[0]));
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()}`;
}
setFieldError(field, messages[0]);
});
}
}
};
Expand Down Expand Up @@ -205,7 +214,7 @@
onChange={() => {
this.setState({ hasCommunity: true });
}}
fieldPath="community.hasCommunity"
fieldPath="metadata.hasCommunity"
/>
<RadioField
label={i18next.t("No")}
Expand All @@ -214,7 +223,7 @@
onChange={() => {
this.setState({ hasCommunity: false });
}}
fieldPath="community.hasCommunity"
fieldPath="metadata.hasCommunity"
/>
</Form.Group>
</div>
Expand All @@ -228,7 +237,7 @@
class="block"
/>
}
fieldPath="community.community"
fieldPath="metadata.community"
options={communities}
defaultValue="Loading..."
required
Expand All @@ -239,16 +248,16 @@
<>
<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
Loading