Skip to content

Commit b25e9e6

Browse files
committed
subcommunity: updated fieldpaths and error handling
1 parent 89f80d6 commit b25e9e6

File tree

1 file changed

+17
-15
lines changed
  • invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity

1 file changed

+17
-15
lines changed

invenio_communities/assets/semantic-ui/js/invenio_communities/subcommunity/new.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ const IdentifierField = ({ formConfig }) => {
4242
return (
4343
<TextField
4444
required
45-
id="community.slug"
45+
id="metadata.slug"
4646
label={
4747
<FieldLabel
48-
htmlFor="community.slug"
48+
htmlFor="metadata.slug"
4949
icon="barcode"
5050
label={i18next.t("Identifier")}
5151
/>
5252
}
53-
fieldPath="community.slug"
53+
fieldPath="metadata.slug"
5454
helpText={helpText}
5555
fluid
5656
className="text-muted"
@@ -84,7 +84,7 @@ class CommunityCreateForm extends Component {
8484
.filter((item) => !item?.parent?.id)
8585
.filter((item) => !item?.children?.allow === true)
8686
.map((item) => ({
87-
text: item.community.title,
87+
text: item.metadata.title,
8888
value: item.id,
8989
key: item.id,
9090
})),
@@ -112,12 +112,12 @@ class CommunityCreateForm extends Component {
112112
let payload = {};
113113
let slug = "";
114114
if (hasCommunity) {
115-
payload = { community_id: values["community"]["community"] };
115+
payload = { community_id: values["metadata"]["community"] };
116116
} else {
117-
slug = values["community"]["slug"];
117+
slug = values["metadata"]["slug"];
118118
payload = {
119119
community: {
120-
title: values["community"]["title"],
120+
title: values["metadata"]["title"],
121121
slug: slug,
122122
},
123123
};
@@ -139,15 +139,17 @@ class CommunityCreateForm extends Component {
139139
const { errors, message } = communityErrorSerializer(error);
140140

141141
if (message) {
142-
this.setGlobalError("The form contains errors or missing fields. Please verify before submitting");
142+
this.setGlobalError(
143+
"The form contains errors or missing fields. Please verify before submitting"
144+
);
143145
}
144146

145147
if (errors) {
146148
errors.map(({ field, messages }) => {
147149
// Check if the field is already prefixed with "metadata"
148150
if (!field.startsWith("metadata")) {
149151
// Add "metadata" prefix if not already present
150-
field = `metadata.${field.split('.').pop()}`;
152+
field = `metadata.${field.split(".").pop()}`;
151153
}
152154
setFieldError(field, messages[0]);
153155
});
@@ -212,7 +214,7 @@ class CommunityCreateForm extends Component {
212214
onChange={() => {
213215
this.setState({ hasCommunity: true });
214216
}}
215-
fieldPath="community.hasCommunity"
217+
fieldPath="metadata.hasCommunity"
216218
/>
217219
<RadioField
218220
label={i18next.t("No")}
@@ -221,7 +223,7 @@ class CommunityCreateForm extends Component {
221223
onChange={() => {
222224
this.setState({ hasCommunity: false });
223225
}}
224-
fieldPath="community.hasCommunity"
226+
fieldPath="metadata.hasCommunity"
225227
/>
226228
</Form.Group>
227229
</div>
@@ -235,7 +237,7 @@ class CommunityCreateForm extends Component {
235237
class="block"
236238
/>
237239
}
238-
fieldPath="community.community"
240+
fieldPath="metadata.community"
239241
options={communities}
240242
defaultValue="Loading..."
241243
required
@@ -246,16 +248,16 @@ class CommunityCreateForm extends Component {
246248
<>
247249
<TextField
248250
required
249-
id="community.title"
251+
id="metadata.title"
250252
fluid
251-
fieldPath="community.title"
253+
fieldPath="metadata.title"
252254
// Prevent submitting before the value is updated:
253255
onKeyDown={(e) => {
254256
e.key === "Enter" && e.preventDefault();
255257
}}
256258
label={
257259
<FieldLabel
258-
htmlFor="community.title"
260+
htmlFor="metadata.title"
259261
icon="book"
260262
label={i18next.t("Community name")}
261263
/>

0 commit comments

Comments
 (0)