diff --git a/CHANGELOG.md b/CHANGELOG.md index d889c0ca..0cae5387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * [UITEN-298] (https://issues.folio.org/browse/UITEN-298) Update translation ids for reading room. * [UITEN-301] (https://issues.folio.org/browse/UITEN-301) Display Reading room access in alphabetical order on settings page. * [UITEN-212](https://folio-org.atlassian.net/browse/UITEN-212) Permission changes for service point management. +* [UITEN-299](https://folio-org.atlassian.net/browse/UITEN-299) Rewrite class components to functional ones (ui-tenant-settings module). ## [8.1.0](https://github.com/folio-org/ui-tenant-settings/tree/v8.1.0)(2024-03-19) [Full Changelog](https://github.com/folio-org/ui-tenant-settings/compare/v8.0.0...v8.1.0) diff --git a/package.json b/package.json index 3098caaa..dda50338 100644 --- a/package.json +++ b/package.json @@ -304,6 +304,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-intl": "^6.4.4", + "react-query": "^3.6.0", "react-router-dom": "^5.2.0" } } diff --git a/src/components/Period/Period.js b/src/components/Period/Period.js index 9f999028..65d6b441 100644 --- a/src/components/Period/Period.js +++ b/src/components/Period/Period.js @@ -1,31 +1,24 @@ -import React from 'react'; +import React, { useRef } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; - -import { - Field, -} from 'react-final-form'; - -import { - get, - isEmpty, - isNumber, -} from 'lodash'; +import { Field } from 'react-final-form'; +import { get, isEmpty, isNumber } from 'lodash'; import { Col, Row, Select, TextField, - Label, + Label } from '@folio/stripes/components'; -import css from './Period.css'; import { shortTermExpiryPeriod, shortTermClosedDateManagementMenu, longTermClosedDateManagementMenu } from '../../settings/ServicePoints/constants'; +import css from './Period.css'; + const validateDuration = value => { if (typeof value !== 'number') { @@ -39,32 +32,19 @@ const validateDuration = value => { return undefined; }; -class Period extends React.Component { - static propTypes = { - fieldLabel: PropTypes.string.isRequired, - selectPlaceholder: PropTypes.string.isRequired, - dependentValuePath: PropTypes.string.isRequired, - inputValuePath: PropTypes.string.isRequired, - selectValuePath: PropTypes.string.isRequired, - entity: PropTypes.object.isRequired, - intervalPeriods: PropTypes.arrayOf(PropTypes.object), - changeFormValue: PropTypes.func.isRequired, - }; - - constructor(props) { - super(props); - - this.inputRef = React.createRef(); - } - - onInputBlur = () => { - const { - inputValuePath, - selectValuePath, - entity, - changeFormValue, - } = this.props; - +const Period = ({ + fieldLabel, + selectPlaceholder, + dependentValuePath, + inputValuePath, + selectValuePath, + entity, + intervalPeriods, + changeFormValue +}) => { + const inputRef = useRef(null); + + const onInputBlur = () => { const inputValue = get(entity, inputValuePath); if (isNumber(inputValue)) { @@ -74,22 +54,11 @@ class Period extends React.Component { changeFormValue(selectValuePath, ''); }; - onInputClear = () => { - const { - inputValuePath, - changeFormValue, - } = this.props; - + const onInputClear = () => { changeFormValue(inputValuePath, ''); }; - onSelectChange = (e) => { - const { - selectValuePath, - changeFormValue, - dependentValuePath, - } = this.props; - + const onSelectChange = (e) => { changeFormValue(selectValuePath, e.target.value); const holdShelfClosedLibraryDateManagementValue = shortTermExpiryPeriod.findIndex(item => item === e.target.value) > -1 @@ -97,10 +66,10 @@ class Period extends React.Component { : longTermClosedDateManagementMenu[0].value; changeFormValue(dependentValuePath, holdShelfClosedLibraryDateManagementValue); - this.inputRef.current.focus(); + inputRef.current.focus(); }; - transformInputValue = (value) => { + const transformInputValue = (value) => { if (isEmpty(value)) { return ''; } @@ -108,12 +77,7 @@ class Period extends React.Component { return Number(value); }; - generateOptions = () => { - const { - intervalPeriods, - selectValuePath, - } = this.props; - + const generateOptions = () => { return intervalPeriods.map(({ value, label }) => (