Skip to content

Commit

Permalink
doi: handle UI for optional DOI feature
Browse files Browse the repository at this point in the history
* closes CERNDocumentServer/cds-rdm#163

Co-authored-by: Zacharias Zacharodimos <zacharias.zacharodimos@cern.ch>
  • Loading branch information
anikachurilova and zzacharo committed Dec 13, 2024
1 parent 731ac68 commit 47712af
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export class RDMDepositApiClient extends DepositApiClient {
);
return new DepositApiClientResponse(data, errors);
} catch (error) {
const errorData = error.response.data;
let errorData = error.response.data;
const errors = this.recordSerializer.deserializeErrors(
error.response.data.errors || []
);
// this is to serialize raised error from the backend on publish
if (errors) errorData = errors;
throw new DepositApiClientResponse({}, errorData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
DepositFormSubmitContext,
} 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 @@ -30,14 +32,28 @@ class PublishButtonComponent extends Component {

handlePublish = (event, handleSubmit, publishWithoutCommunity) => {
const { setSubmitContext } = this.context;

setSubmitContext(
publishWithoutCommunity
? DepositFormSubmitActions.PUBLISH_WITHOUT_COMMUNITY
: DepositFormSubmitActions.PUBLISH
);
handleSubmit(event);
this.closeConfirmModal();
const { formik, raiseDOINeededButNotReserved } = this.props;
const noINeedOne = formik?.values?.noINeedOne;
if (noINeedOne && Object.keys(formik?.values?.pids).length === 0) {
const errors = {
pids: {
doi: i18next.t("DOI is needed. Please click on the button to reserve it."),
},
};
formik.setErrors(errors);
raiseDOINeededButNotReserved(formik?.values, errors);
this.closeConfirmModal();
// scroll top to show the global error
scrollTop();
} else {
setSubmitContext(
publishWithoutCommunity
? DepositFormSubmitActions.PUBLISH_WITHOUT_COMMUNITY
: DepositFormSubmitActions.PUBLISH
);
handleSubmit(event);
this.closeConfirmModal();
}
};

isDisabled = (values, isSubmitting, filesState) => {
Expand Down Expand Up @@ -139,6 +155,7 @@ PublishButtonComponent.propTypes = {
formik: PropTypes.object.isRequired,
publishModalExtraContent: PropTypes.string,
filesState: PropTypes.object,
raiseDOINeededButNotReserved: PropTypes.func.isRequired,
};

PublishButtonComponent.defaultProps = {
Expand All @@ -155,7 +172,12 @@ 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({
type: DRAFT_PUBLISH_FAILED_WITH_VALIDATION_ERRORS,
payload: { data: data, errors: errors },
}),
};
})(connectFormik(PublishButtonComponent));
Loading

0 comments on commit 47712af

Please sign in to comment.