Skip to content

Commit

Permalink
Create/edit forms: remove cancel button
Browse files Browse the repository at this point in the history
  • Loading branch information
Pineirin committed Sep 27, 2022
1 parent e62286c commit a079328
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ErrorMessage } from "../ui_messages/messages";
import isEmpty from "lodash/isEmpty";
import { GenerateForm } from "./GenerateForm";
import { deserializeFieldErrors } from "../components/utils";
import { i18next } from "@translations/invenio_administration/i18next";

export class ActionForm extends Component {
constructor(props) {
Expand Down Expand Up @@ -53,12 +54,6 @@ export class ActionForm extends Component {
}
};

onCancel = () => {
const { resource, actionCancelCallback } = this.props;
this.setState({ formData: resource });
actionCancelCallback();
};

getEndpoint = (actionKey) => {
const { resource } = this.props;
let endpoint;
Expand Down Expand Up @@ -92,11 +87,8 @@ export class ActionForm extends Component {
<ErrorMessage {...error} removeNotification={this.resetErrorState} />
)}
<Modal.Actions>
<Button type="button" onClick={this.onCancel}>
Cancel
</Button>
<Button type="submit" primary loading={loading}>
Save
{i18next.t("Save")}
</Button>
</Modal.Actions>
</SemanticForm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ import { ErrorMessage } from "../ui_messages/messages";
import isEmpty from "lodash/isEmpty";
import { GenerateForm } from "./GenerateForm";
import { deserializeFieldErrors } from "../components/utils";
import { i18next } from "@translations/invenio_administration/i18next";
import mapValues from "lodash/mapValues";

export class AdminForm extends Component {
constructor(props) {
super(props);
const { resource } = props;
const { resource, formFields } = props;

this.state = {
error: undefined,
formData: resource ? resource : {},
formData: resource
? resource
: mapValues(formFields, function (value) {
return "";
}),
};
}

Expand Down Expand Up @@ -67,11 +73,6 @@ export class AdminForm extends Component {
}
};

onCancel = () => {
const { resource } = this.props;
this.setState({ formData: resource });
};

resetErrorState = () => {
this.setState({ error: undefined });
};
Expand All @@ -82,40 +83,34 @@ export class AdminForm extends Component {

return (
<Formik initialValues={formData} onSubmit={this.onSubmit}>
{(props) => (
<SemanticForm
as={Form}
onSubmit={(e) => {
e.preventDefault();
props.handleSubmit();
}}
>
<GenerateForm
formFields={formFields}
jsonSchema={resourceSchema}
create={create}
/>
{!isEmpty(error) && (
<ErrorMessage {...error} removeNotification={this.resetErrorState} />
)}
<Button
type="button"
onClick={this.onCancel}
loading={props.isSubmitting}
disabled={props.isSubmitting}
>
Cancel
</Button>
<Button
type="submit"
primary
loading={props.isSubmitting}
disabled={props.isSubmitting}
{(props) => {
return (
<SemanticForm
as={Form}
onSubmit={(e) => {
e.preventDefault();
props.handleSubmit();
}}
>
Save
</Button>
</SemanticForm>
)}
<GenerateForm
formFields={formFields}
jsonSchema={resourceSchema}
create={create}
/>
{!isEmpty(error) && (
<ErrorMessage {...error} removeNotification={this.resetErrorState} />
)}
<Button
type="submit"
primary
loading={props.isSubmitting}
disabled={props.isSubmitting}
>
{i18next.t("Save")}
</Button>
</SemanticForm>
);
}}
</Formik>
);
}
Expand Down

0 comments on commit a079328

Please sign in to comment.