From 66ec3e862af9718485cb590b353fd48f3bd17ae8 Mon Sep 17 00:00:00 2001 From: Artem_Blazhko Date: Thu, 14 Nov 2024 23:59:57 +0200 Subject: [PATCH] Add basic functionality for managing missing data --- CHANGELOG.md | 1 + .../InstanceInformation.js | 18 ++++++++++++++++-- .../ItemInformation/ItemInformation.js | 17 +++++++++++++++-- .../components/RequestForm/RequestForm.js | 19 ++++++++++++------- .../RequesterInformation.js | 15 +++++++++++++-- 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e47b6..ce06ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Add circulation-storage.staff-slips.collection.get for get staff-slips on Send item in transit. Refs UIREQMED-55. * Add Decline Action for Mediated request with status of New - Awaiting confirmation. Refs UIREQMED-42. * Fix DOMPurify import. Refs UIREQMED-56. +* Add functionality for managing missing data related to item, instance, requester. Refs UIREQMED-51. ## [1.1.0](https://github.com/folio-org/ui-requests-mediated/tree/v1.1.0) (2024-10-30) * Update github actions. Refs UIREQMED-14. diff --git a/src/components/MediatedRequestsActivities/components/InstanceInformation/InstanceInformation.js b/src/components/MediatedRequestsActivities/components/InstanceInformation/InstanceInformation.js index 80ad433..13cfcb3 100644 --- a/src/components/MediatedRequestsActivities/components/InstanceInformation/InstanceInformation.js +++ b/src/components/MediatedRequestsActivities/components/InstanceInformation/InstanceInformation.js @@ -39,6 +39,8 @@ class InstanceInformation extends Component { isLoading: PropTypes.bool.isRequired, enterButtonClass: PropTypes.string.isRequired, isInstancePreselected: PropTypes.bool.isRequired, + isEditMode: PropTypes.bool.isRequired, + request: PropTypes.object.isRequired, stripes: PropTypes.object.isRequired, selectedInstance: PropTypes.object, }; @@ -58,11 +60,22 @@ class InstanceInformation extends Component { const { isInstancePreselected, selectedInstance, + isEditMode, + triggerValidation, + request, } = this.props; + const isNewPreselectedValue = isInstancePreselected && isInstancePreselected !== prevProps.isInstancePreselected; - if (selectedInstance && isInstancePreselected && isInstancePreselected !== prevProps.isInstancePreselected) { + if (selectedInstance && isNewPreselectedValue) { this.setState({ validatedId: selectedInstance.hrid }); } + + if (isEditMode && !selectedInstance && isNewPreselectedValue) { + this.setState({ + validatedId: request?.instance?.hrid, + shouldValidate: true, + }, triggerValidation); + } } validate = memoizeValidation(async (instanceId) => { @@ -183,6 +196,7 @@ class InstanceInformation extends Component { isLoading, enterButtonClass, stripes, + isEditMode, } = this.props; const { isInstanceClicked, @@ -211,7 +225,7 @@ class InstanceInformation extends Component { > {({ input, meta }) => { const selectInstanceError = meta.touched && meta.error; - const instanceDoesntExistError = (isInstanceClicked || isInstanceBlurred) && meta.error; + const instanceDoesntExistError = (isInstanceClicked || isInstanceBlurred || (isEditMode && !selectedInstance)) && meta.error; const error = selectInstanceError || instanceDoesntExistError || null; return ( diff --git a/src/components/MediatedRequestsActivities/components/ItemInformation/ItemInformation.js b/src/components/MediatedRequestsActivities/components/ItemInformation/ItemInformation.js index 4dcd957..d978e06 100644 --- a/src/components/MediatedRequestsActivities/components/ItemInformation/ItemInformation.js +++ b/src/components/MediatedRequestsActivities/components/ItemInformation/ItemInformation.js @@ -37,6 +37,7 @@ class ItemInformation extends Component { isItemIdRequest: PropTypes.bool.isRequired, enterButtonClass: PropTypes.string.isRequired, isItemPreselected: PropTypes.bool.isRequired, + isEditMode: PropTypes.bool.isRequired, stripes: PropTypes.shape({ hasPerm: PropTypes.func, }).isRequired, @@ -59,11 +60,22 @@ class ItemInformation extends Component { const { isItemPreselected, selectedItem, + isEditMode, + triggerValidation, + request, } = this.props; + const isNewPreselectedValue = isItemPreselected && isItemPreselected !== prevProps.isItemPreselected; - if (selectedItem && isItemPreselected && isItemPreselected !== prevProps.isItemPreselected) { + if (selectedItem && isNewPreselectedValue) { this.setState({ validatedBarcode: selectedItem.barcode }); } + + if (isEditMode && !selectedItem && isNewPreselectedValue) { + this.setState({ + shouldValidate: true, + validatedBarcode: request?.item?.barcode, + }, triggerValidation); + } } validate = memoizeValidation(async (barcode) => { @@ -186,6 +198,7 @@ class ItemInformation extends Component { selectedLoan, enterButtonClass, stripes, + isEditMode, } = this.props; const { isItemClicked, @@ -213,7 +226,7 @@ class ItemInformation extends Component { > {({ input, meta }) => { const selectItemError = meta.touched && meta.error; - const itemDoesntExistError = (isItemClicked || isItemBlurred) && meta.error; + const itemDoesntExistError = (isItemClicked || isItemBlurred || (isEditMode && !selectedItem)) && meta.error; const error = selectItemError || itemDoesntExistError || null; return ( diff --git a/src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js b/src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js index 4c6a38f..2891a50 100644 --- a/src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js +++ b/src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js @@ -175,7 +175,7 @@ class RequestForm extends React.Component { form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.ITEM_BARCODE, request.item.barcode); } - form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUESTER_BARCODE, request.requester.barcode); + form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUESTER_BARCODE, request.requester?.barcode); form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PATRON_COMMENTS, request.patronComments); Promise.allSettled([ @@ -648,20 +648,22 @@ class RequestForm extends React.Component { const { requestPreferences } = await findResource(RESOURCE_TYPES.REQUEST_PREFERENCES, userId); const preferences = requestPreferences[0]; const fulfillmentPreference = getFulfillmentPreference(preferences, initialValues); + const defaultDeliveryAddressTypeId = preferences?.defaultDeliveryAddressTypeId; + const defaultServicePointId = preferences?.defaultServicePointId; this.setState({ - defaultDeliveryAddressTypeId: preferences.defaultDeliveryAddressTypeId, - defaultServicePointId: preferences.defaultServicePointId, + defaultDeliveryAddressTypeId, + defaultServicePointId, fulfillmentPreference, }); return { ...defaultPreferences, - defaultDeliveryAddressTypeId: preferences.defaultDeliveryAddressTypeId, - defaultServicePointId: preferences.defaultServicePointId, - hasDelivery: Boolean(preferences.delivery), + hasDelivery: Boolean(preferences?.delivery), isDeliverySelected: isDelivery(fulfillmentPreference), - selectedAddress: preferences.defaultDeliveryAddressTypeId, + selectedAddress: defaultDeliveryAddressTypeId, + defaultDeliveryAddressTypeId, + defaultServicePointId, fulfillmentPreference, }; } catch (e) { @@ -952,6 +954,8 @@ class RequestForm extends React.Component { onSetSelectedInstance={onSetSelectedInstance} isLoading={isItemOrInstanceLoading} enterButtonClass={css.enterButton} + isEditMode={isEditMode} + request={request} /> ) @@ -975,6 +979,7 @@ class RequestForm extends React.Component { selectedLoan={selectedLoan} isLoading={isItemOrInstanceLoading} enterButtonClass={css.enterButton} + isEditMode={isEditMode} /> ) diff --git a/src/components/MediatedRequestsActivities/components/RequesterInformation/RequesterInformation.js b/src/components/MediatedRequestsActivities/components/RequesterInformation/RequesterInformation.js index 33614cb..e80131b 100644 --- a/src/components/MediatedRequestsActivities/components/RequesterInformation/RequesterInformation.js +++ b/src/components/MediatedRequestsActivities/components/RequesterInformation/RequesterInformation.js @@ -72,11 +72,22 @@ class RequesterInformation extends Component { const { isUserPreselected, selectedUser, + triggerUserBarcodeValidation, + isEditMode, + request, } = this.props; + const isNewPreselectedValue = isUserPreselected && isUserPreselected !== prevProps.isUserPreselected; - if (selectedUser && isUserPreselected && isUserPreselected !== prevProps.isUserPreselected) { + if (selectedUser && isNewPreselectedValue) { this.setState({ validatedBarcode: selectedUser.barcode }); } + + if (isEditMode && !selectedUser && isNewPreselectedValue) { + this.setState({ + validatedBarcode: request?.requester?.barcode, + shouldValidate: true, + }, triggerUserBarcodeValidation); + } } validate = memoizeValidation(async (barcode) => { @@ -246,7 +257,7 @@ class RequesterInformation extends Component { > {({ input, meta }) => { const selectUserError = meta.touched && !selectedUser?.id && meta.error; - const userDoesntExistError = (isUserClicked || isUserBlurred) && meta.error; + const userDoesntExistError = (isUserClicked || isUserBlurred || (isEditMode && !selectedUser)) && meta.error; const error = selectUserError || userDoesntExistError || null; return (