Skip to content

Commit

Permalink
wip show DOI error in the top level
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Dec 5, 2024
1 parent a461679 commit db738be
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "../../api/DepositFormSubmitContext";
import { DRAFT_PUBLISH_STARTED } from "../../state/types";
import { scrollTop } from "../../utils";
import { DRAFT_PUBLISH_FAILED_WITH_VALIDATION_ERRORS } from "../../state/types";

class PublishButtonComponent extends Component {
state = { isConfirmModalOpen: false };
Expand All @@ -31,18 +32,20 @@ class PublishButtonComponent extends Component {

handlePublish = (event, handleSubmit, publishWithoutCommunity) => {
const { setSubmitContext } = this.context;
const { formik } = this.props;
const { formik, raiseDOINeededButNotReserved } = this.props;
const noINeedOne = formik?.values?.noINeedOne;
// TODO
// - You need to check if DOI is enabled here, otherwise you will not see field
// - The error message is not shown on the field, maybe missing an error label
// - Maybe show it also in the global?
if (noINeedOne && Object.keys(formik?.values?.pids).length === 0) {
formik.setErrors({
const errors = {
pids: {
doi: "No DOI was reserved and one was needed.",
},
});
};
formik.setErrors(errors);
raiseDOINeededButNotReserved(formik?.values, errors);
this.closeConfirmModal();
// scroll top to show the global error
scrollTop();
Expand Down Expand Up @@ -156,6 +159,7 @@ PublishButtonComponent.propTypes = {
formik: PropTypes.object.isRequired,
publishModalExtraContent: PropTypes.string,
filesState: PropTypes.object,
raiseDOINeededButNotReserved: PropTypes.func.isRequired,
};

PublishButtonComponent.defaultProps = {
Expand All @@ -172,7 +176,13 @@ const mapStateToProps = (state) => ({
filesState: state.files,
});

export const PublishButton = connect(
mapStateToProps,
null
)(connectFormik(PublishButtonComponent));
export const PublishButton = connect(mapStateToProps, (dispatch) => {
return {
raiseDOINeededButNotReserved: (data, errors) =>
dispatch({
// TODO: maybe you need another error because the message is misleading
type: DRAFT_PUBLISH_FAILED_WITH_VALIDATION_ERRORS,
payload: { data: data, errors: errors },
}),
};
})(connectFormik(PublishButtonComponent));

0 comments on commit db738be

Please sign in to comment.