Skip to content

Commit

Permalink
Release v10.1.1 (#2685)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Terala-Priyanka and mkuklis authored May 7, 2024
1 parent 0478d59 commit feb4cce
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@folio/users",
"version": "10.1.0",
"version": "10.1.1",
"description": "User management",
"repository": "folio-org/ui-users",
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Loans/OpenLoans/OpenLoansControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ class OpenLoansControl extends React.Component {
}

export default compose(
injectIntl,
withRenew,
withDeclareLost,
withClaimReturned,
withMarkAsMissing,
injectIntl,
)(OpenLoansControl);
47 changes: 34 additions & 13 deletions src/components/Wrappers/withRenew.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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),
};
}
}
}

Expand Down Expand Up @@ -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 <FormattedMessage
id="ui-users.errors.loanNotRenewedReason"
values={{ message: errors }}
/>;
}

const policyName = this.getPolicyName(errors);
const message = errors.reduce((msg, err) => ((msg) ? `${msg}, ${err.message}` : err.message), '');
Expand Down
52 changes: 52 additions & 0 deletions src/components/Wrappers/withRenew.test.js
Original file line number Diff line number Diff line change
@@ -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 <div>{errorMessages?.[1]?.props?.values?.message ?? ''}</div>;
};

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 }) => (
<button type="button" onClick={() => renew([{ id: 1, reminders: { renewalBlocked: true } }], { barcode: '123' })}>Renew</button>
);
const WrappedComponent = withRenew(Wrapper);
const renderWithRenew = (extraProps = {}) => render(<WrappedComponent {...props} {...extraProps} />);

describe('withRenew', () => {
it('should renew loans', async () => {
renderWithRenew();
userEvent.click(screen.getByText('Renew'));

await waitFor(() => {
expect(screen.getByText('ui-users.errors.renewWithReminders')).toBeInTheDocument();
});
});
});
1 change: 1 addition & 0 deletions translations/ui-users/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit feb4cce

Please sign in to comment.