From feb4ccef354c7512f024c3ca6ee8a2ee80ac0c72 Mon Sep 17 00:00:00 2001 From: Priyanka Terala <104053200+Terala-Priyanka@users.noreply.github.com> Date: Tue, 7 May 2024 15:36:51 +0530 Subject: [PATCH] Release v10.1.1 (#2685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * UICIRC-1077: Allow override for reminder fees with renewal blocked (#2674) * UICIRC-1077: Allow override for reminder fees with renewal blocked * Cleanup * Add tests * Cleanup * Release 10.1.1 --------- Co-authored-by: MichaƂ Kuklis --- CHANGELOG.md | 4 +- package.json | 2 +- .../Loans/OpenLoans/OpenLoansControl.js | 2 +- src/components/Wrappers/withRenew.js | 47 ++++++++++++----- src/components/Wrappers/withRenew.test.js | 52 +++++++++++++++++++ translations/ui-users/en.json | 1 + 6 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 src/components/Wrappers/withRenew.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa9e5edc..53a3e6f10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Change history for ui-users -## [10.2.0] IN PROGRESS +## [10.1.1](https://github.com/folio-org/ui-users/tree/v10.1.1) (2024-05-07) +[Full Changelog](https://github.com/folio-org/ui-users/compare/v10.1.0...v10.1.1) +* Allow override for reminder fees with renewal blocked. Refs UICIRC-1077. ## [10.1.0](https://github.com/folio-org/ui-users/tree/v10.1.0) (2024-03-20) [Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.4...v10.1.0) diff --git a/package.json b/package.json index f8c56513c..ce05d8fcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/users", - "version": "10.1.0", + "version": "10.1.1", "description": "User management", "repository": "folio-org/ui-users", "publishConfig": { diff --git a/src/components/Loans/OpenLoans/OpenLoansControl.js b/src/components/Loans/OpenLoans/OpenLoansControl.js index e5596b3d9..bea3dd3b4 100644 --- a/src/components/Loans/OpenLoans/OpenLoansControl.js +++ b/src/components/Loans/OpenLoans/OpenLoansControl.js @@ -393,9 +393,9 @@ class OpenLoansControl extends React.Component { } export default compose( + injectIntl, withRenew, withDeclareLost, withClaimReturned, withMarkAsMissing, - injectIntl, )(OpenLoansControl); diff --git a/src/components/Wrappers/withRenew.js b/src/components/Wrappers/withRenew.js index 37ec6fd5c..f9c4f0b14 100644 --- a/src/components/Wrappers/withRenew.js +++ b/src/components/Wrappers/withRenew.js @@ -18,6 +18,7 @@ import { // HOC used to manage renew const withRenew = WrappedComponent => class WithRenewComponent extends React.Component { static propTypes = { + intl: PropTypes.object, loans: PropTypes.arrayOf(PropTypes.object), patronBlocks: PropTypes.arrayOf(PropTypes.object), mutator: PropTypes.shape({ @@ -143,21 +144,34 @@ const withRenew = WrappedComponent => class WithRenewComponent extends React.Com const bulkRenewal = (loansSize > 1); for (const [index, loan] of loans.entries()) { - try { - // We actually want to execute it in a sequence so turning off eslint warning - // https://issues.folio.org/browse/UIU-1299 - // eslint-disable-next-line no-await-in-loop - renewSuccess.push( - await this.renewItem(loan, patron, bulkRenewal, index !== loansSize - 1, additionalInfo) - ); - } catch (errors) { - const errorMessage = this.getMessage(errors); - + // Allow override for reminder fees with renewal blocked + // https://folio-org.atlassian.net/browse/UICIRC-1077 + if (loan?.reminders?.renewalBlocked) { renewFailure.push(loan); + const error = this.props.intl.formatMessage({ id: 'ui-users.errors.renewWithReminders' }); + errorMsg[loan.id] = { - ...errorMessage, - ...isOverridePossible(errors), + ...this.getMessage(error), + overridable: true, + autoNewDueDate: true, }; + } else { + try { + // We actually want to execute it in a sequence so turning off eslint warning + // https://issues.folio.org/browse/UIU-1299 + // eslint-disable-next-line no-await-in-loop + renewSuccess.push( + await this.renewItem(loan, patron, bulkRenewal, index !== loansSize - 1, additionalInfo) + ); + } catch (errors) { + const errorMessage = this.getMessage(errors); + + renewFailure.push(loan); + errorMsg[loan.id] = { + ...errorMessage, + ...isOverridePossible(errors), + }; + } } } @@ -205,7 +219,14 @@ const withRenew = WrappedComponent => class WithRenewComponent extends React.Com // eslint-disable-next-line class-methods-use-this getMessage = (errors) => { - if (!errors || !errors.length) return ''; + if (!errors) return ''; + + if (!Array.isArray(errors)) { + return ; + } const policyName = this.getPolicyName(errors); const message = errors.reduce((msg, err) => ((msg) ? `${msg}, ${err.message}` : err.message), ''); diff --git a/src/components/Wrappers/withRenew.test.js b/src/components/Wrappers/withRenew.test.js new file mode 100644 index 000000000..9442e628a --- /dev/null +++ b/src/components/Wrappers/withRenew.test.js @@ -0,0 +1,52 @@ +import React from 'react'; +import { render, screen, waitFor } from '@folio/jest-config-stripes/testing-library/react'; +import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; + +import '__mock__/currencyData.mock'; +import '__mock__/stripesCore.mock'; +import '__mock__/intl.mock'; +import buildStripes from '__mock__/stripes.mock'; +import withRenew from './withRenew'; + +const BulkRenewalDialogMock = ({ errorMessages }) => { + return
{errorMessages?.[1]?.props?.values?.message ?? ''}
; +}; + +jest.mock('../BulkRenewalDialog', () => BulkRenewalDialogMock); + +const mutator = { + loanPolicies: { + GET: jest.fn(), + reset: jest.fn(), + }, + renew: { + POST: jest.fn().mockReturnValue(Promise.resolve()), + }, + requests: { + GET: jest.fn().mockReturnValue(Promise.resolve()), + reset: jest.fn(), + }, +}; + +const props = { + mutator, + intl: { formatMessage: ({ id }) => id }, + stripes: buildStripes({ connect: (Component) => Component }), +}; + +const Wrapper = ({ renew }) => ( + +); +const WrappedComponent = withRenew(Wrapper); +const renderWithRenew = (extraProps = {}) => render(); + +describe('withRenew', () => { + it('should renew loans', async () => { + renderWithRenew(); + userEvent.click(screen.getByText('Renew')); + + await waitFor(() => { + expect(screen.getByText('ui-users.errors.renewWithReminders')).toBeInTheDocument(); + }); + }); +}); diff --git a/translations/ui-users/en.json b/translations/ui-users/en.json index f719545bf..19cb405b5 100644 --- a/translations/ui-users/en.json +++ b/translations/ui-users/en.json @@ -395,6 +395,7 @@ "errors.personal.dateOfBirth": "Please enter correct birth date", "errors.extended.dateEnrolled": "Please enter correct enrolled date", "errors.expirationDate": "Please enter correct expiration date", + "errors.renewWithReminders": "Renewals not allowed for loans with reminders.", "hide": "Hide", "show": "Show", "active": "Active",