Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UINV-498: add inactive status for account numbers #730

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/invoices/InvoiceLineForm/InvoiceLineForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useMemo, useRef } from 'react';
import { FormattedMessage } from 'react-intl';
import { FormattedMessage, useIntl } from 'react-intl';
import PropTypes from 'prop-types';
import { Field } from 'react-final-form';
import { useHistory } from 'react-router';
Expand Down Expand Up @@ -45,12 +45,11 @@ import { useFundDistributionValidation } from '../../common/hooks';
import { StatusValue } from '../../common/components';
import {
calculateTotalAmount,
getAccountNumberOptions,
IS_EDIT_POST_APPROVAL,
} from '../../common/utils';
import {
convertToInvoiceLineFields,
getActiveAccountNumbers,
getActiveAccountNumberOptions,
} from '../utils';
import AdjustmentsForm from '../AdjustmentsForm';
import {
Expand All @@ -74,6 +73,7 @@ const InvoiceLineForm = ({
}) => {
const history = useHistory();
const accordionStatusRef = useRef();
const { formatMessage } = useIntl();
const { validateFundDistributionTotal } = useFundDistributionValidation({
formValues,
currency: invoice.currency,
Expand Down Expand Up @@ -169,16 +169,13 @@ const InvoiceLineForm = ({
/>
);

const accountNumbers = useMemo(() => {
return getActiveAccountNumbers({
const activeAccountOptions = useMemo(() => {
return getActiveAccountNumberOptions({
accounts,
initialAccountNumber: accountNumber,
formatMessage,
});
}, [accounts, accountNumber]);

const activeAccountOptions = useMemo(() => {
return getAccountNumberOptions(accountNumbers);
}, [accountNumbers]);
}, [accounts, accountNumber, formatMessage]);

const accountNumberDisabled = useMemo(() => {
const hasCurrentAccountNumber = accounts.some(({ accountNo }) => accountNo === currentAccountNumber);
Expand Down
13 changes: 10 additions & 3 deletions src/invoices/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import {
PAYMENT_STATUS,
RECEIPT_STATUS,
} from '@folio/stripes-acq-components';

import { ACCOUNT_STATUS } from './constants';

const { ACTIVE, INACTIVE } = ACCOUNT_STATUS;

export const getAdjustmentFromPreset = ({
description,
prorate,
Expand Down Expand Up @@ -120,10 +123,14 @@ export const getCommonInvoiceLinesFormatter = (currency, ordersMap, orderlinesMa
),
});

export const getActiveAccountNumbers = ({ accounts = [], initialAccountNumber }) => {
export const getActiveAccountNumberOptions = ({ accounts = [], initialAccountNumber, formatMessage }) => {
const message = ` - ${formatMessage({ id: 'ui-invoice.inactive' })}`;
const activeAccounts = accounts.filter(({ accountStatus, accountNo }) => {
return accountStatus === ACCOUNT_STATUS.ACTIVE || accountNo === initialAccountNumber;
return accountStatus === ACTIVE || accountNo === initialAccountNumber;
});

return uniq(activeAccounts.map(({ accountNo }) => accountNo).filter(Boolean));
return uniq(activeAccounts.map(({ name, accountNo, accountStatus }) => ({
label: `${name} (${accountNo}) ${accountStatus === INACTIVE ? message : ''}`,
value: accountNo,
})));
};
19 changes: 14 additions & 5 deletions src/invoices/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
convertToInvoiceLineFields,
getActiveAccountNumbers,
getActiveAccountNumberOptions,
} from './utils';

const mockFormatMessage = jest.fn(({ id }) => id);

const mockAccounts = [
{
'name': 'Monographic ordering unit account',
Expand Down Expand Up @@ -65,16 +67,23 @@ describe('Invoice utils', () => {
});
});

describe('getActiveAccountNumbers', () => {
describe('getActiveAccountNumberOptions', () => {
it('should return active account numbers', () => {
const initialAccountNumber = mockAccounts[1].accountNo;

expect(getActiveAccountNumbers({
expect(getActiveAccountNumberOptions({
accounts: mockAccounts,
initialAccountNumber,
formatMessage: mockFormatMessage,
})).toEqual([
mockAccounts[0].accountNo,
initialAccountNumber,
{
'label': 'Monographic ordering unit account (1234) ',
'value': '1234',
},
{
'label': 'Amazon Test account (00000001) - ui-invoice.inactive',
'value': '00000001',
},
]);
});
});
Expand Down
1 change: 1 addition & 0 deletions translations/ui-invoice/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

"showTags": "Show tags",
"addTagFor": "Add tag for: {filterValue}",
"inactive": "Inactive",

"invoiceLine.adminData": "Invoice line admin data",
"invoiceLine.adjustments": "Invoice line adjustments",
Expand Down