Skip to content

Commit

Permalink
UIU-1786 - fetch contributors list from the instance instead of loan.
Browse files Browse the repository at this point in the history
  • Loading branch information
maximdidenkoepam authored and zburke committed Aug 12, 2020
1 parent 96ef822 commit cfb5982
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
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-users

## 4.0.7 (IN PROGRESS)

* Manual charge with item should not be associated with loan. Fixes UIU-1786.

## [4.0.6](https://github.com/folio-org/ui-users/tree/v4.0.6) (2020-07-15)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v4.0.5...v4.0.6)

Expand Down
38 changes: 33 additions & 5 deletions src/routes/AccountDetailsContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { first } from 'lodash';
import { FormattedMessage } from 'react-intl';

import { stripesConnect } from '@folio/stripes/core';
Expand Down Expand Up @@ -40,16 +41,25 @@ class AccountDetailsContainer extends React.Component {
},
activeRecord: {
accountId: '0',
instanceId: '',
},
loans: {
type: 'okapi',
records: 'loans',
path: 'circulation/loans?query=(userId=:{id})&limit=1000',
},
instance: {
type: 'okapi',
path: 'instance-storage/instances/%{activeRecord.instanceId}',
}
});

static propTypes = {
resources: PropTypes.shape({
loans: PropTypes.object,
activeRecord: PropTypes.shape({
instanceId: PropTypes.string,
}),
accountHistory: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
Expand All @@ -59,13 +69,21 @@ class AccountDetailsContainer extends React.Component {
selUser: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
instance: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
}),
match: PropTypes.shape({
params: PropTypes.shape({
accountid: PropTypes.string,
id: PropTypes.string,
})
}),
mutator: PropTypes.shape({
activeRecord: PropTypes.shape({
update: PropTypes.func.isRequired
}).isRequired
}),
}

getUser = () => {
Expand Down Expand Up @@ -95,13 +113,23 @@ class AccountDetailsContainer extends React.Component {
}

getItemDetails = () => {
const { resources } = this.props;
const {
mutator: {
activeRecord: {
update: updateInstanceId,
}
},
resources,
} = this.props;

const account = this.getAccount();
if (account?.instanceId && account.instanceId !== resources.activeRecord.instanceId) {
updateInstanceId({ instanceId: account.instanceId });
}

const instance = first(resources?.instance?.records || []) || { contributors: [] };
const loanRecords = resources?.loans?.records ?? [];
const itemId = account?.itemId;
const item = loanRecords.filter((loan) => loan.itemId === itemId);
const contributorRecords = item[0]?.item?.contributors ?? [];
const contributors = contributorRecords.map(({ name }) => name.split(',').reverse().join(', ')) || [];
const contributors = instance.contributors.map(({ name }) => name.split(',').reverse().join(', '));
const loanId = account?.loanId;

if (loanId === '0') return { contributors };
Expand Down

0 comments on commit cfb5982

Please sign in to comment.