Skip to content

Commit

Permalink
doi: add error handling on the component
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova committed Dec 6, 2024
1 parent db738be commit b3dd407
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ class PublishButtonComponent extends Component {
const { setSubmitContext } = this.context;
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) {
const errors = {
pids: {
doi: "No DOI was reserved and one was needed.",
doi: "DOI is needed. Please click on the button to reserve it.",
},
};
formik.setErrors(errors);
Expand Down Expand Up @@ -180,7 +176,6 @@ 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 },
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getFieldErrors = (form, fieldPath) => {
*/
class ReservePIDBtn extends Component {
render() {
const { disabled, handleReservePID, label, loading } = this.props;
const { disabled, handleReservePID, label, loading, fieldError } = this.props;
return (
<Field>
{({ form: formik }) => (
Expand All @@ -44,6 +44,7 @@ class ReservePIDBtn extends Component {
disabled={disabled || loading}
onClick={(e) => handleReservePID(e, formik)}
content={label}
error={fieldError}
/>
)}
</Field>
Expand All @@ -54,13 +55,15 @@ class ReservePIDBtn extends Component {
ReservePIDBtn.propTypes = {
disabled: PropTypes.bool,
handleReservePID: PropTypes.func.isRequired,
fieldError: PropTypes.object,
label: PropTypes.string.isRequired,
loading: PropTypes.bool,
};

ReservePIDBtn.defaultProps = {
disabled: false,
loading: false,
fieldError: null,
};

/**
Expand Down Expand Up @@ -215,6 +218,8 @@ class ManagedIdentifierComponent extends Component {
identifier,
pidPlaceholder,
pidType,
form,
fieldPath,
} = this.props;
const hasIdentifier = identifier !== "";

Expand All @@ -226,6 +231,7 @@ class ManagedIdentifierComponent extends Component {
actionState === RESERVE_PID_STARTED && actionStateExtra.pidType === pidType
}
handleReservePID={this.handleReservePID}
fieldError={getFieldErrors(form, fieldPath)}
/>
);

Expand Down Expand Up @@ -270,6 +276,8 @@ ManagedIdentifierComponent.propTypes = {
btnLabelDiscardPID: PropTypes.string.isRequired,
pidPlaceholder: PropTypes.string.isRequired,
pidType: PropTypes.string.isRequired,
form: PropTypes.object.isRequired,
fieldPath: PropTypes.string.isRequired,
/* from Redux */
actionState: PropTypes.string,
actionStateExtra: PropTypes.object,
Expand Down Expand Up @@ -480,6 +488,7 @@ class CustomPIDField extends Component {
form.setFieldValue("pids", {});
form.setFieldValue("noINeedOne", true);
} else if (userSelectedNoNeed) {
form.setFieldValue("pids", {});
form.setFieldValue("noINeedOne", false);
} else {
this.onExternalIdentifierChanged("");
Expand All @@ -501,6 +510,7 @@ class CustomPIDField extends Component {
btnLabelDiscardPID={btnLabelDiscardPID}
btnLabelGetPID={btnLabelGetPID}
form={form}
fieldPath={fieldPath}
identifier={managedIdentifier}
helpText={managedHelpText}
pidPlaceholder={pidPlaceholder}
Expand Down

0 comments on commit b3dd407

Please sign in to comment.