Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UICIRC-1077: Allow override for reminder fees with renewal blocked #2674

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Trim input values and delete properties with empty string when user record save. Refs UIU-2049.
* Update username field validation to trim leading and trailing spaces. Refs UIU-3099.
* Fix "Total paid amount" value that set as "$NaN" on "Refund fee/fine" modal. Refs UIU-3094.
* 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 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
Loading