Skip to content

Commit

Permalink
Merge pull request #977 from DGB-UNAM-FOLIO/UNAM
Browse files Browse the repository at this point in the history
Fix UIU-1221
  • Loading branch information
zburke authored Sep 26, 2019
2 parents ee01a08 + de533eb commit fd982d7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Retrieve up to 1000 loans instead of 100. LIBRARIANS LOVE BOOKS! Refs CHAL-29.
* Correctly display checkboxes in the add-servicepoint modal. Refs UIU-1240.
* Retrieve requests-against-patron in batches for a shorter querystring. Refs CHAL-30.
* Fix additional information for patron. Fixes UIU-1221.

## [2.25.1](https://github.com/folio-org/ui-users/tree/v2.25.1) (2019-09-11)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v2.25.0...v2.25.1)
Expand Down
33 changes: 17 additions & 16 deletions src/components/Accounts/Actions/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,28 @@ class Actions extends React.Component {
return this.props.mutator.accounts.PUT(Object.assign(account, newAccount));
}

assembleTagInfo = (values) => {
const { intl: { formatMessage } } = this.props;
const tagStaff = formatMessage({ id: 'ui-users.accounts.actions.tag.staff' });
const tagPatron = formatMessage({ id: 'ui-users.accounts.actions.tag.patron' });
let tagInfo = '';
if (values.comment) {
tagInfo = `${tagStaff} : ${values.comment}`;
}

if (values.patronInfo) {
tagInfo = `${tagInfo} \n ${tagPatron} : ${values.patronInfo}`;
}
return tagInfo;
}

onClickCancellation(values) {
const { intl: { formatMessage } } = this.props;
const canceled = formatMessage({ id: 'ui-users.accounts.cancelError' });
const tagStaff = formatMessage({ id: 'ui-users.accounts.actions.tag.staff' });
const type = this.props.accounts[0] || {};
delete type.rowIndex;
this.props.mutator.activeRecord.update({ id: type.id });
const comment = `${tagStaff} : ${values.comment}`;
this.newAction({}, type.id, canceled, type.amount, comment, 0, 0, type.feeFineOwner);
this.newAction({}, type.id, canceled, type.amount, this.assembleTagInfo(values), 0, 0, type.feeFineOwner);
this.editAccount(type, canceled, 'Closed', 0.00)
.then(() => this.props.handleEdit(1))
.then(() => this.showCalloutMessage(type))
Expand Down Expand Up @@ -278,8 +291,6 @@ class Actions extends React.Component {
const { intl: { formatMessage } } = this.props;
this.props.mutator.activeRecord.update({ id: type.id });
let paymentStatus = _.capitalize(formatMessage({ id: `ui-users.accounts.actions.warning.${action}Action` }));
const tagStaff = formatMessage({ id: 'ui-users.accounts.actions.tag.staff' });
const tagPatron = formatMessage({ id: 'ui-users.accounts.actions.tag.patron' });
const owners = _.get(this.props.resources, ['owners', 'records'], []);
if (amount < type.remaining) {
paymentStatus = `${paymentStatus} ${formatMessage({ id: 'ui-users.accounts.status.partially' })}`;
Expand All @@ -288,18 +299,9 @@ class Actions extends React.Component {
type.status.name = 'Closed';
}
const balance = type.remaining - parseFloat(amount);

let tagInfo = '';
if (values.comment) {
tagInfo = `${tagStaff} : ${values.comment}`;
}
if (values.patronInfo && values.notify) {
tagInfo = `${tagInfo} \n ${tagPatron} : ${values.patronInfo}`;
}
const createdAt = (owners.find(o => o.id === values.ownerId) || {}).owner;

return this.editAccount(type, paymentStatus, type.status.name, balance)
.then(() => this.newAction({ paymentMethod: values.method }, type.id, paymentStatus, amount, tagInfo, balance, values.transaction, createdAt || type.feeFineOwner));
.then(() => this.newAction({ paymentMethod: values.method }, type.id, paymentStatus, amount, this.assembleTagInfo(values), balance, values.transaction, createdAt || type.feeFineOwner));
}

onCloseActionModal() {
Expand Down Expand Up @@ -497,7 +499,6 @@ class Actions extends React.Component {
open={actions.cancellation}
onClose={this.onCloseCancellation}
user={this.props.user}
stripes={this.props.stripes}
account={this.props.accounts[0] || {}}
onSubmit={(values) => { this.onClickCancellation(values); }}
owners={owners}
Expand Down
75 changes: 29 additions & 46 deletions src/components/Accounts/Actions/CancellationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import {
Field,
reduxForm,
reduxForm
} from 'redux-form';

import SafeHTMLMessage from '@folio/react-intl-safe-html';
Expand All @@ -16,7 +16,6 @@ import {
Col,
} from '@folio/stripes/components';

import { isEqual } from 'lodash';
import css from './modal.css';

const validate = (values) => {
Expand All @@ -43,43 +42,12 @@ class CancellationModal extends React.Component {

constructor(props) {
super(props);

this.state = {
notify: false,
showNotify: false,
};
}

componentDidUpdate(prevProps, prevState) {
const {
account,
feefines,
} = this.props;

if (!isEqual(account, prevProps.account) || prevState.showNotify !== this.state.showNotify) {
let showNotify = false;
let notify = false;

const feefine = feefines.find(f => f.id === account.feeFineId) || {};
const owner = this.props.owners.find(o => o.id === account.ownerId) || {};
if (feefine.actionNoticeId || owner.defaultActionNoticeId) {
showNotify = true;
notify = true;
}
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
showNotify,
notify,
});
}
this.state = { notify: true };
}

reset = () => {
this.props.reset();
this.setState({
notify: false,
showNotify: false
});
this.setState({ notify: true });
}

onToggleNotify = () => {
Expand All @@ -88,38 +56,53 @@ class CancellationModal extends React.Component {
}));
}

handleSubmit = () => {
this.props.handleSubmit();
handleSubmit = (values) => {
const { handleSubmit } = this.props;
handleSubmit(values);
this.reset();
}

onClose = () => {
this.props.onClose();
onCloseModal = () => {
const { onClose } = this.props;
onClose();
this.reset();
this.setState({ notify: true });
}

render() {
const defaultAmount = '0.00';
const defaultFeeFineType = 'fee/fine type';
const {
account,
account: {
amount = defaultAmount,
feeFineType = defaultFeeFineType,
},
pristine,
submitting,
feefines,
invalid,
open,
owners,
pristine,
submitting
} = this.props;

let showNotify = false;

const feefine = feefines.find(f => f.id === account.feeFineId) || {};
const owner = owners.find(o => o.id === account.ownerId) || {};

if (feefine.actionNoticeId || owner.defaultActionNoticeId) {
showNotify = true;
}

const submitButtonDisabled = pristine || submitting || invalid;

return (
<Modal
id="error-modal"
label={<FormattedMessage id="ui-users.accounts.cancellation.field.confirmcancelled" />}
open={open}
onClose={this.onClose}
onClose={this.onCloseModal}
size="small"
dismissible
>
Expand Down Expand Up @@ -157,7 +140,7 @@ class CancellationModal extends React.Component {
</FormattedMessage>
</Col>
</Row>
{this.state.showNotify &&
{showNotify &&
<div>
<Row>
<Col xs>
Expand All @@ -174,7 +157,7 @@ class CancellationModal extends React.Component {
</div>
}
<br />
{(this.state.notify && this.state.showNotify) &&
{(this.state.notify && showNotify) &&
<div>
<Row>
<Col xs>
Expand Down Expand Up @@ -204,7 +187,7 @@ class CancellationModal extends React.Component {
<FormattedMessage id="ui-users.accounts.cancellation.field.confirm" />
</Button>
<Button
onClick={this.onClose}
onClick={this.onCloseModal}
buttonClass={css.rightAlignedButton}
>
<FormattedMessage id="ui-users.accounts.cancellation.field.back" />
Expand All @@ -220,5 +203,5 @@ class CancellationModal extends React.Component {
export default reduxForm({
form: 'cancellation',
validate,
fields: [],
enableReinitialize: true,
})(CancellationModal);

0 comments on commit fd982d7

Please sign in to comment.