From d7ffc8f1a0339f373aec6d6352dcfa2e3ff1c38a Mon Sep 17 00:00:00 2001 From: Artem_Blazhko Date: Mon, 11 Sep 2023 16:25:12 +0300 Subject: [PATCH] Generate "Create request" url for users without barcode --- CHANGELOG.md | 1 + .../RequestFeeFineBlockButtons.js | 9 ++++----- .../UserRequests/UserRequests.js | 8 +++----- src/components/util/util.js | 13 +++++++++++++ src/components/util/util.test.js | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cca98975..ba50d82d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ * User can't pay the fee/fine. Refs UIU-2930. * Sort proxies and sponsors by user display name. Refs UIU-2799. * Add dropdown to specify user type: Patron or Staff. Refs UIU-2936. +* Generate "Create request" url for users without barcode. Refs UIU-2869. ## [9.0.0](https://github.com/folio-org/ui-users/tree/v9.0.0) (2023-02-20) [Full Changelog](https://github.com/folio-org/ui-users/compare/v8.1.0...v9.0.0) diff --git a/src/components/RequestFeeFineBlockButtons/RequestFeeFineBlockButtons.js b/src/components/RequestFeeFineBlockButtons/RequestFeeFineBlockButtons.js index ee5759b24..3545ebbb4 100644 --- a/src/components/RequestFeeFineBlockButtons/RequestFeeFineBlockButtons.js +++ b/src/components/RequestFeeFineBlockButtons/RequestFeeFineBlockButtons.js @@ -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 { @@ -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, @@ -25,9 +26,7 @@ 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 (
@@ -35,7 +34,7 @@ class RequestFeeFineBlockButtons extends React.Component { diff --git a/src/components/util/util.js b/src/components/util/util.js index b9521a6c3..52d58b736 100644 --- a/src/components/util/util.js +++ b/src/components/util/util.js @@ -1,6 +1,7 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; import { every } from 'lodash'; +import queryString from 'query-string'; import { NoValue } from '@folio/stripes/components'; import { @@ -181,3 +182,15 @@ export const getContributors = (account, instance) => { export const isConsortiumEnabled = stripes => { return stripes.hasInterface('consortia'); }; + +export const getRequestUrl = (barcode, userId) => { + return barcode ? + `/requests/?${queryString.stringify({ + layer: 'create', + userBarcode: barcode, + })}` : + `/requests/?${queryString.stringify({ + layer: 'create', + userId, + })}`; +}; diff --git a/src/components/util/util.test.js b/src/components/util/util.test.js index 705901d82..1279351ab 100644 --- a/src/components/util/util.test.js +++ b/src/components/util/util.test.js @@ -18,6 +18,7 @@ import { retrieveNoteReferredEntityDataFromLocationState, getClosedRequestStatusesFilterString, getOpenRequestStatusesFilterString, + getRequestUrl, } from './util'; describe('accountsMatchStatus', () => { @@ -364,3 +365,17 @@ describe('getContributors', () => { expect(data).toStrictEqual('requestStatus.Open - Awaiting pickup,requestStatus.Open - Awaiting delivery,requestStatus.Open - In transit,requestStatus.Open - Not yet filled'); }); }); + +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}`); + }); +});