Skip to content

Commit

Permalink
Merge branch 'master' into UIU-2943
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam authored Sep 12, 2023
2 parents 9fae86c + 04b6c42 commit b950576
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* Sort proxies and sponsors by user display name. Refs UIU-2799.
* Add dropdown to specify user type: Patron or Staff. Refs UIU-2936.
* *BREAKING* bump `react-intl` to `v6.4.4`. Refs UIU-2946.
* Generate "Create request" url for users without barcode. Refs UIU-2869.
* ECS - Filter users by "User Type". Refs UIU-2943.

## [9.0.0](https://github.com/folio-org/ui-users/tree/v9.0.0) (2023-02-20)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import queryString from 'query-string';
import { withRouter } from 'react-router-dom';

import {
Expand All @@ -10,6 +9,8 @@ import {
} from '@folio/stripes/components';
import { IfPermission } from '@folio/stripes/core';

import { getRequestUrl } from '../util';

class RequestFeeFineBlockButtons extends React.Component {
static propTypes = {
barcode: PropTypes.string,
Expand All @@ -25,17 +26,15 @@ class RequestFeeFineBlockButtons extends React.Component {
userId,
location,
} = this.props;
const linkToCreateRequest = barcode ?
`/requests/?${queryString.stringify({ layer: 'create', userBarcode: barcode })}` :
`/requests/?${queryString.stringify({ layer: 'create' })}`;
const createRequestUrl = getRequestUrl(barcode, userId);

return (
<div data-test-actions-menu>
<IfPermission perm="ui-requests.all">
<Button
buttonStyle="dropdownItem"
data-test-actions-menu-create-request
to={linkToCreateRequest}
to={createRequestUrl}
onClick={onToggle}
>
<Icon icon="plus-sign">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
getOpenRequestStatusesFilterString,
getClosedRequestStatusesFilterString,
getRequestUrl,
} from '../../util';

/**
Expand Down Expand Up @@ -119,13 +120,10 @@ class UserRequests extends React.Component {

const requestsLoaded = openRequestsCount >= 0 && closedRequestsCount >= 0;
const displayWhenClosed = requestsLoaded ? (<Badge>{openRequestsCount}</Badge>) : (<Icon icon="spinner-ellipsis" width="10px" />);
const createRequestUrl = getRequestUrl(barcode, id);
const displayWhenOpen = (
<IfPermission perm="ui-requests.all">
<Button to={`/requests/?${queryString.stringify({
layer: 'create',
userBarcode: barcode,
})}`}
>
<Button to={createRequestUrl}>
<FormattedMessage id="ui-users.requests.createRequest" />
</Button>
</IfPermission>
Expand Down
14 changes: 14 additions & 0 deletions src/components/util/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { every, get } from 'lodash';
import queryString from 'query-string';

import { NoValue } from '@folio/stripes/components';

import {
Expand Down Expand Up @@ -185,3 +187,15 @@ export const isConsortiumEnabled = stripes => {
export const getCentralTenantId = stripes => {
return get(stripes, ['user', 'user', 'consortium', 'centralTenantId'], '');
};

export const getRequestUrl = (barcode, userId) => {
return barcode ?
`/requests/?${queryString.stringify({
layer: 'create',
userBarcode: barcode,
})}` :
`/requests/?${queryString.stringify({
layer: 'create',
userId,
})}`;
};
15 changes: 15 additions & 0 deletions src/components/util/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getOpenRequestStatusesFilterString,
getCentralTenantId,
isConsortiumEnabled,
getRequestUrl,
} from './util';

const STRIPES = {
Expand Down Expand Up @@ -402,3 +403,17 @@ describe('getCentralTenantId', () => {
expect(data).toBe('test');
});
});

describe('getRequestUrl', () => {
it('should return url with user barcode', () => {
const userBarcode = 'userBarcode';

expect(getRequestUrl(userBarcode)).toBe(`/requests/?layer=create&userBarcode=${userBarcode}`);
});

it('should return url with user id', () => {
const userId = 'userId';

expect(getRequestUrl(undefined, userId)).toBe(`/requests/?layer=create&userId=${userId}`);
});
});

0 comments on commit b950576

Please sign in to comment.