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

UIU-2701: Return appropriate error message when item for manual fee/fine can't be found #2847

Merged
merged 4 commits into from
Jan 25, 2025
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 @@ -11,6 +11,7 @@
* Update fee/fine actions column UX for accessibility. Refs UIU-3027.
* Change import of `exportToCsv` from `stripes-util` to `stripes-components`. Refs UIU-3202.
* Provide `itemToString` to create unique `key` attributes. Refs UIU-3312.
* Return appropriate error message when item for manual fee/fine can't be found. Refs UIU-2701.

## [11.0.11](https://github.com/folio-org/ui-users/tree/v11.0.11) (2025-01-15)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v11.0.10...v11.0.11)
Expand Down
32 changes: 25 additions & 7 deletions src/components/Accounts/ChargeFeeFine/ChargeFeeFine.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
loadServicePoints,
deleteOptionalActionFields,
} from '../accountFunctions';
import { SHARED_OWNER } from '../../../constants';
import {
SHARED_OWNER,
NEW_FEE_FINE_FIELD_NAMES,
} from '../../../constants';

class ChargeFeeFine extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -72,6 +75,7 @@ class ChargeFeeFine extends React.Component {
showConfirmDialog: false,
notify: null,
paymentNotify: null,
itemBarcode: '',
};
this.chargeAction = this.chargeAction.bind(this);
this.payAction = this.payAction.bind(this);
Expand Down Expand Up @@ -232,7 +236,10 @@ class ChargeFeeFine extends React.Component {

onClickSelectItem(barcode) {
if (barcode !== '') {
this.props.mutator.activeRecord.update({ barcode });
this.props.mutator.activeRecord.update({
barcode,
isBarcodeValidated: true,
});
if ((this.props.resources.activeRecord || {}).barcode === barcode) {
this.setState({
lookup: true,
Expand All @@ -241,7 +248,7 @@ class ChargeFeeFine extends React.Component {
}
}

onChangeOwner(ownerId) {
onChangeOwner(ownerId, itemBarcode = '') {
const {
resources,
mutator,
Expand All @@ -253,7 +260,11 @@ class ChargeFeeFine extends React.Component {
mutator.activeRecord.update({ shared });
}
mutator.activeRecord.update({ ownerId });
this.setState({ ownerId });

this.setState({
ownerId,
itemBarcode,
});
}

onChangeItem(item) {
Expand Down Expand Up @@ -395,7 +406,12 @@ class ChargeFeeFine extends React.Component {
);
}

onSubmitCharge = (data) => {
onSubmitCharge = (dataToSend) => {
const data = _.cloneDeep(dataToSend);

_.unset(data, NEW_FEE_FINE_FIELD_NAMES.ITEM_BARCODE);
_.unset(data, NEW_FEE_FINE_FIELD_NAMES.KEY_OF_ITEM_BARCODE);

if (data.pay) {
delete data.pay;
this.type.remaining = data.amount;
Expand Down Expand Up @@ -433,6 +449,7 @@ class ChargeFeeFine extends React.Component {
ownerId,
feeFineTypeId,
pay,
itemBarcode,
} = this.state;
this.item = _.get(resources, ['items', 'records', [0]], {});
const feefines = _.get(resources, ['allfeefines', 'records'], []);
Expand Down Expand Up @@ -461,7 +478,7 @@ class ChargeFeeFine extends React.Component {
parseFloat(selected).toFixed(2);
let item;

if (this.item && (loanid || barcode)) {
if (this.item && (loanid || barcode || !resources.activeRecord?.isBarcodeValidated)) {
item = {
id: this.item.id || '',
instance: this.item.title || '',
Expand Down Expand Up @@ -490,7 +507,8 @@ class ChargeFeeFine extends React.Component {
ownerId: initialOwnerId,
notify: !!(selectedFeeFine?.chargeNoticeId || selectedOwner?.defaultChargeNoticeId),
feeFineId: '',
amount: ''
amount: '',
itemBarcode,
};

const initialActionValues = {
Expand Down
77 changes: 77 additions & 0 deletions src/components/Accounts/ChargeFeeFine/ChargeFeeFine.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
screen,
render,
} from '@folio/jest-config-stripes/testing-library/react';
import userEvent from '@folio/jest-config-stripes/testing-library/user-event';

import ChargeFeeFine from './ChargeFeeFine';
import ChargeForm from './ChargeForm';

const basicProps = {
resources: {
activeRecord: {
isBarcodeValidated: true,
},
},
mutator: {
activeRecord: {
update: jest.fn(),
},
},
user: {},
stripes: {},
location: {},
history: {},
intl: {},
match: {
params: {},
},
okapi: {
currentUser: {},
},
};
const testIds = {
selectItem: 'selectItem',
};
const itemBarcode = 'itemBarcode';

jest.mock('./ChargeForm', () => jest.fn(({
onClickSelectItem,
}) => (
<>
<button
type="button"
data-testid={testIds.selectItem}
onClick={() => onClickSelectItem(itemBarcode)}
>
Enter
</button>
</>
)));
jest.mock('./ItemLookup', () => jest.fn(() => <div />));
jest.mock('../Actions/ActionModal', () => jest.fn(() => <div />));

describe('ChargeFeeFine', () => {
afterEach(() => {
jest.clearAllMocks();
});

beforeEach(() => {
render(<ChargeFeeFine {...basicProps} />);
});

it('should trigger ChargeForm', () => {
expect(ChargeForm).toHaveBeenCalled();
});

it('should update activeRecord', async () => {
const selectItemButton = screen.getByTestId(testIds.selectItem);

await userEvent.click(selectItemButton);

expect(basicProps.mutator.activeRecord.update).toHaveBeenCalledWith({
barcode: itemBarcode,
isBarcodeValidated: true,
});
});
});
18 changes: 15 additions & 3 deletions src/components/Accounts/ChargeFeeFine/ChargeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import { effectiveCallNumber } from '@folio/stripes/util';
import UserInfo from './UserInfo';
import FeeFineInfo from './FeeFineInfo';
import ItemInfo from './ItemInfo';
import { SHARED_OWNER } from '../../../constants';
import {
SHARED_OWNER,
NEW_FEE_FINE_FIELD_NAMES,
} from '../../../constants';
import { formatCurrencyAmount } from '../../util';

function showValidationErrors({ feeFineId, ownerId, amount }) {
Expand Down Expand Up @@ -62,6 +65,7 @@ class ChargeForm extends React.Component {
handleSubmit: PropTypes.func.isRequired,
onClickSelectItem: PropTypes.func.isRequired,
onFindShared: PropTypes.func.isRequired,
values: PropTypes.object.isRequired,
pristine: PropTypes.bool,
submitting: PropTypes.bool,
invalid: PropTypes.bool,
Expand Down Expand Up @@ -122,9 +126,17 @@ class ChargeForm extends React.Component {
}

onChangeOwner(ownerId) {
const { form: { change, reset } } = this.props;
const {
form: {
change,
reset,
},
values,
onChangeOwner,
} = this.props;

reset();
this.props.onChangeOwner(ownerId);
onChangeOwner(ownerId, values[NEW_FEE_FINE_FIELD_NAMES.ITEM_BARCODE]);
let showNotify = false;
const owner = this.props.owners.find(o => o.id === ownerId) || {};
if (owner?.defaultChargeNoticeId) {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Accounts/ChargeFeeFine/ChargeForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ const propData = {
ownerId: '109155d9-3b60-4a3d-a6b1-066cf1b1356b',
metadata: { createdDate: '2022-03-01T03:22:48.262+00:00', updatedDate: '2022-03-01T03:22:48.262+00:00' },
}],
resources: {
items: {},
},
};

describe('ChargeForm component', () => {
Expand Down
Loading
Loading