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

UICHKIN-398-poppy-dcb - Hide fee/fine action menu items when requester is virtual user. #607

Merged
merged 1 commit into from
Nov 24, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change history for ui-checkin

## [9.0.2] IN PROGRESS

* Hide fee/fine action menu items when requester is virtual user. Refs UICHKIN-398.

## [9.0.1] (https://github.com/folio-org/ui-checkin/tree/v9.0.1) (2023-10-23)
[Full Changelog](https://github.com/folio-org/ui-checkin/compare/v9.0.0...v9.0.1)
* Fix circulation timeout issue. Refs UICHKIN-392.
Expand Down
5 changes: 4 additions & 1 deletion src/CheckIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import CheckInFooter from './components/CheckInFooter';
import {
convertToSlipData,
getCheckinSettings,
isDcbUser,
} from './util';

import styles from './checkin.css';
Expand Down Expand Up @@ -308,6 +309,7 @@ class CheckIn extends React.Component {
const isCheckInNote = element => element.noteType === 'Check in';
const checkinNotePresent = get(loan.item, ['circulationNotes'], []).some(isCheckInNote);
const loanOpenRequest = loan?.staffSlipContext?.request ?? {};
const isVirtualUser = isDcbUser(loan?.borrower);

const trigger = ({ getTriggerProps, triggerRef }) => (
<IconButton
Expand Down Expand Up @@ -393,12 +395,13 @@ class CheckIn extends React.Component {
}
<IfPermission perm="accounts.collection.get">
<FeeFineDetailsButton
isVirtualUser={isVirtualUser}
userId={loan.userId}
itemId={loan.itemId}
mutator={this.props.mutator}
/>
</IfPermission>
{loan.userId &&
{loan.userId && !isVirtualUser &&
<Button
role="menuitem"
buttonStyle="dropdownItem"
Expand Down
8 changes: 7 additions & 1 deletion src/components/FeeFineDetailsButton/FeeFineDetailsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const FEE_FINES_STATUSES = {

class FeeFineDetailsButton extends React.Component {
static propTypes = {
isVirtualUser: PropTypes.bool,
userId: PropTypes.string,
itemId: PropTypes.string,
mutator: PropTypes.shape({
Expand Down Expand Up @@ -116,12 +117,13 @@ class FeeFineDetailsButton extends React.Component {
const {
userId,
itemId,
isVirtualUser,
} = this.props;
const {
feeFinesCount,
} = this.state;

return !userId || !itemId || !feeFinesCount;
return isVirtualUser || !userId || !itemId || !feeFinesCount;
};

render() {
Expand All @@ -148,4 +150,8 @@ class FeeFineDetailsButton extends React.Component {
}
}

FeeFineDetailsButton.defaultProps = {
isVirtualUser: false,
};

export default FeeFineDetailsButton;
19 changes: 19 additions & 0 deletions src/components/FeeFineDetailsButton/FeeFineDetailsButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { account as accountFixture } from '../../../test/jest/fixtures/account';
import { loan as loanFixture } from '../../../test/jest/fixtures/loan';
import FeeFineDetailsButton from './FeeFineDetailsButton';
import { DCB_USER } from '../../consts';

const mockedQueryUpdate = jest.fn();
const labelIds = {
Expand Down Expand Up @@ -193,4 +194,22 @@ describe('FeeFineDetailsButton', () => {
});
});
});

describe('when borrower is virtual user', () => {
it('should not render FeeFineDetails button', () => {
const alteredLoanFixture = {
...loanFixture,
loan: {
...loanFixture.loan,
borrower: {
...loanFixture.loan.borrower,
lastName: DCB_USER.lastName,
}
}
};
renderFeeFineDetailsButton(alteredLoanFixture, accountFixture);

expect(screen.queryByText(labelIds.feeFineDetails)).toBeNull();
});
});
});
4 changes: 4 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ export const cancelFeeClaimReturned = {
};

export const MAX_RECORDS = '1000';

export const DCB_USER = {
lastName: 'DcbSystem',
};
7 changes: 6 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
includes,
} from 'lodash';

import { statuses } from './consts';
import {
DCB_USER,
statuses,
} from './consts';

export const escapeValue = (val) => {
if (typeof val === 'string' && val.startsWith('<Barcode>') && val.endsWith('</Barcode>')) {
Expand Down Expand Up @@ -164,4 +167,6 @@ export function shouldConfirmStatusModalBeShown(item) {
], item?.status?.name);
}

export const isDcbUser = (user) => user?.lastName === DCB_USER.lastName;

export default {};
20 changes: 20 additions & 0 deletions src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
escapeValue,
getCheckinSettings,
shouldConfirmStatusModalBeShown,
isDcbUser,
} from './util';

import {
DCB_USER,
statuses,
} from './consts';

Expand Down Expand Up @@ -318,3 +320,21 @@ describe('shouldConfirmStatusModalBeShown', () => {
});
});
});

describe('isDcbUser', () => {
it('should return true when user has lastName as "DcbSystem"', () => {
const user = {
lastName: DCB_USER.lastName,
};

expect(isDcbUser(user)).toBeTruthy();
});

it('should return false when user does not have lastName as "DcbSystem"', () => {
const user = {
lastName: 'test',
};

expect(isDcbUser(user)).toBeFalsy();
});
});
Loading