From d20d865534b0b490d10fa94e654fc53a0d9552bb Mon Sep 17 00:00:00 2001 From: Dmitriy-Litvinenko Date: Mon, 9 Oct 2023 19:01:06 +0300 Subject: [PATCH] UIREQ-789: Replace using of error.message with enum values for translation keys --- CHANGELOG.md | 1 + src/ViewRequest.js | 11 +++++++++-- src/constants.js | 4 ---- translations/ui-requests/en.json | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6812c4c..79d55ad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/ViewRequest.js b/src/ViewRequest.js index 0a9b0b89..a7883e35 100644 --- a/src/ViewRequest.js +++ b/src/ViewRequest.js @@ -54,7 +54,6 @@ import { REQUEST_LEVEL_TYPES, requestTypesTranslations, requestStatusesTranslations, - errorMessageLabels, REQUEST_LAYERS, } from './constants'; import { @@ -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: { @@ -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', }); }); diff --git a/src/constants.js b/src/constants.js index 74ab2fa9..488c5ed9 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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', diff --git a/translations/ui-requests/en.json b/translations/ui-requests/en.json index 799ec98e..37d729c5 100644 --- a/translations/ui-requests/en.json +++ b/translations/ui-requests/en.json @@ -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",