Skip to content

Commit

Permalink
UIREQ-789: Replace using of error.message with enum values for transl…
Browse files Browse the repository at this point in the history
…ation keys
  • Loading branch information
Dmitriy-Litvinenko committed Oct 9, 2023
1 parent e5015c5 commit d20d865
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* Create Jest/RTL test for RequestsFilters.js. Refs UIREQ-937.
* Add "itemId" parameter to "allowed-service-points" endpoint. Refs UIREQ-1030.
* Use current optional dependencies. Refs UIREQ-1031.
* 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

0 comments on commit d20d865

Please sign in to comment.