Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIREQ-789: Replace using of error.message with enum values for transl… #1113

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
* Add "itemId" parameter to "allowed-service-points" endpoint. Refs UIREQ-1030.
* Use current optional dependencies. Refs UIREQ-1031.
* Update Requests error messages. Refs UIREQ-1036.
* Replace using of error.message with enum values for translation keys. Refs UIREQ-789.

## [8.0.2](https://github.com/folio-org/ui-requests/tree/v8.0.2) (2023-03-29)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v8.0.1...v8.0.2)
Expand Down
11 changes: 9 additions & 2 deletions src/ViewRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
REQUEST_LEVEL_TYPES,
requestTypesTranslations,
requestStatusesTranslations,
errorMessageLabels,
REQUEST_LAYERS,
} from './constants';
import {
Expand All @@ -69,6 +68,14 @@ import urls from './routes/urls';

const CREATE_SUCCESS = 'CREATE_SUCCESS';

const REQUEST_ERROR_MESSAGE_CODE = {
REQUEST_ALREADY_CLOSED: 'REQUEST_ALREADY_CLOSED',
};

const REQUEST_ERROR_MESSAGE_TRANSLATION_KEYS = {
[REQUEST_ERROR_MESSAGE_CODE.REQUEST_ALREADY_CLOSED]: 'ui-requests.errors.requestAlreadyClosed',
};

class ViewRequest extends React.Component {
static manifest = {
selectedRequest: {
Expand Down Expand Up @@ -277,7 +284,7 @@ class ViewRequest extends React.Component {
.then(res => {
res.errors.forEach(error => {
this.callout.current.sendCallout({
message: errorMessageLabels[error.message] ? formatMessage({ id: errorMessageLabels[error.message] }) : error.message,
message: REQUEST_ERROR_MESSAGE_TRANSLATION_KEYS[error?.code] ? formatMessage({ id: REQUEST_ERROR_MESSAGE_TRANSLATION_KEYS[error?.code] }) : error.message,
type: 'error',
});
});
Expand Down
4 changes: 0 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,6 @@ export const errorMessages = {
DELETE_REQUEST_ERROR: 'The Request has already been closed',
};

export const errorMessageLabels = {
[errorMessages.DELETE_REQUEST_ERROR]: 'ui-requests.errors.closingAlreadyClosedRequest',
};

export const errorCodes = {
SYNC: 'sync',
UNKNOWN: 'unknown',
Expand Down
2 changes: 1 addition & 1 deletion translations/ui-requests/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"errors.sync.requestQueueBody": "This request queue has been updated by another person or process and may be out of synch.",
"errors.unknown.requestQueueLabel": "Request queue error",
"errors.unknown.requestQueueBody": "Request queue reorder failed",
"errors.closingAlreadyClosedRequest": "Error: The Request has already been closed.",
"errors.requestAlreadyClosed": "Error: The Request has already been closed.",
"errors.requestType.titleLevelRequest": "None available for this title and patron combination",
"errors.requestType.itemLevelRequest": "None available for this item and patron combination",
"errors.requestType.selectItem": "Please select a request type",
Expand Down