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-557: Improve error message when attempting to save an invoice line when no budget for the fiscal year exists #809

Merged
merged 12 commits into from
Oct 8, 2024
Merged
6 changes: 3 additions & 3 deletions .github/workflows/build-npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
comment_title: Jest Unit Test Statistics

- name: Publish Jest coverage report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: jest-coverage-report
Expand All @@ -170,15 +170,15 @@ jobs:
comment_title: BigTest Unit Test Statistics

- name: Publish BigTest coverage report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: bigtest-coverage-report
path: ${{ env.BIGTEST_COVERAGE_REPORT_DIR }}
retention-days: 30

- name: Publish yarn.lock
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: yarn.lock
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
comment_title: Jest Unit Test Statistics

- name: Publish Jest coverage report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: jest-coverage-report
Expand All @@ -113,15 +113,15 @@ jobs:
comment_title: BigTest Unit Test Statistics

- name: Publish BigTest coverage report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: bigtest-coverage-report
path: ${{ env.BIGTEST_COVERAGE_REPORT_DIR }}
retention-days: 30

- name: Publish yarn.lock
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: yarn.lock
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Use Save & close button label stripes-component translation key. Refs UINV-540.
* Add indexes to improve the performance of getting composite orders by poNumber. Refs UINV-546.
* Duplicate invoice and invoice lines. Refs UINV-552.
* Improve error message when attempting to save an invoice line when no budget for the fiscal year exists. Refs UINV-557.

## [6.0.4](https://github.com/folio-org/ui-invoice/tree/v6.0.4) (2024-08-21)
[Full Changelog](https://github.com/folio-org/ui-invoice/compare/v6.0.3...v6.0.4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,7 @@ exports[`AdjustmentsForm should render correct structure with defined adjustment
id="downshift-:r1:-menu"
role="listbox"
style="max-height: 174px;"
>
<li
class="groupLabel"
>
<div
class="optionSegment"
data-test-selection-option-segment="true"
/>
</li>
</ul>
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -500,7 +491,6 @@ exports[`AdjustmentsForm should render correct structure with defined adjustment
</div>
</div>
</form>
<div />
</DocumentFragment>
`;

Expand Down Expand Up @@ -594,16 +584,7 @@ exports[`AdjustmentsForm should render correct structure without adjustments 1`]
id="downshift-:r3:-menu"
role="listbox"
style="max-height: 174px;"
>
<li
class="groupLabel"
>
<div
class="optionSegment"
data-test-selection-option-segment="true"
/>
</li>
</ul>
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -632,6 +613,5 @@ exports[`AdjustmentsForm should render correct structure without adjustments 1`]
</div>
</div>
</form>
<div />
</DocumentFragment>
`;
88 changes: 50 additions & 38 deletions src/invoices/InvoiceDetails/InvoiceDetailsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
import ReactRouterPropTypes from 'react-router-prop-types';

import { LoadingPane } from '@folio/stripes/components';
import { stripesConnect } from '@folio/stripes/core';
import {
stripesConnect,
useOkapiKy,
} from '@folio/stripes/core';
import {
baseManifest,
batchFetch,
Expand Down Expand Up @@ -56,6 +59,7 @@ export function InvoiceDetailsContainer({
// eslint-disable-next-line react-hooks/exhaustive-deps
const mutator = useMemo(() => originMutator, [id]);
const showCallout = useShowCallout();
const ky = useOkapiKy();
const [isLoading, setIsLoading] = useState(true);
const [invoice, setInvoice] = useState({});
const [invoiceLines, setInvoiceLines] = useState({});
Expand Down Expand Up @@ -221,14 +225,15 @@ export function InvoiceDetailsContainer({
}, Promise.resolve());
await fetchInvoiceData();
} catch (response) {
showUpdateInvoiceError(
showUpdateInvoiceError({
response,
showCallout,
'saveLine',
'ui-invoice.invoice.actions.saveLine.error',
mutator.expenseClass,
mutator.fund,
);
action: 'saveLine',
defaultErrorMessageId: 'ui-invoice.invoice.actions.saveLine.error',
expenseClassMutator: mutator.expenseClass,
fundMutator: mutator.fund,
ky,
});
}

setIsLoading(false);
Expand Down Expand Up @@ -277,14 +282,15 @@ export function InvoiceDetailsContainer({

return fetchInvoiceData();
}, ({ response }) => (
showUpdateInvoiceError(
showUpdateInvoiceError({
response,
showCallout,
'cancel',
'ui-invoice.invoice.actions.cancel.error',
mutator.expenseClass,
mutator.fund,
)
action: 'cancel',
defaultErrorMessageId: 'ui-invoice.invoice.actions.cancel.error',
expenseClassMutator: mutator.expenseClass,
fundMutator: mutator.fund,
ky,
})
))
.finally(setIsLoading);
},
Expand All @@ -305,14 +311,15 @@ export function InvoiceDetailsContainer({

return fetchInvoiceData();
}, ({ response }) => (
showUpdateInvoiceError(
showUpdateInvoiceError({
response,
showCallout,
'approve',
'ui-invoice.invoice.actions.approve.error',
mutator.expenseClass,
mutator.fund,
)
action: 'approve',
defaultErrorMessageId: 'ui-invoice.invoice.actions.approve.error',
expenseClassMutator: mutator.expenseClass,
fundMutator: mutator.fund,
ky,
})
))
.finally(setIsLoading);
},
Expand All @@ -332,14 +339,15 @@ export function InvoiceDetailsContainer({
refreshList();

return fetchInvoiceData();
}, ({ response }) => showUpdateInvoiceError(
}, ({ response }) => showUpdateInvoiceError({
response,
showCallout,
'pay',
'ui-invoice.invoice.actions.pay.error',
mutator.expenseClass,
mutator.fund,
))
action: 'pay',
defaultErrorMessageId: 'ui-invoice.invoice.actions.pay.error',
expenseClassMutator: mutator.expenseClass,
fundMutator: mutator.fund,
ky,
}))
.finally(setIsLoading);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -356,14 +364,15 @@ export function InvoiceDetailsContainer({
return mutateInvoice({ ...invoiceResponse, status: INVOICE_STATUS.paid });
})
.catch(({ response }) => {
showUpdateInvoiceError(
showUpdateInvoiceError({
response,
showCallout,
'approveAndPay',
'ui-invoice.invoice.actions.approveAndPay.error',
mutator.expenseClass,
mutator.fund,
);
action: 'approveAndPay',
defaultErrorMessageId: 'ui-invoice.invoice.actions.approveAndPay.error',
expenseClassMutator: mutator.expenseClass,
fundMutator: mutator.fund,
ky,
});

throw new Error('approveAndPay error');
})
Expand Down Expand Up @@ -398,6 +407,7 @@ export function InvoiceDetailsContainer({
fund: mutator.fund,
},
showCallout,
ky,
})).then(async ({ invoiceId: newInvoiceId }) => {
showCallout({ messageId: 'ui-invoice.invoice.actions.duplicate.success.message' });
refreshList();
Expand All @@ -408,14 +418,15 @@ export function InvoiceDetailsContainer({
});
})
.catch((error) => {
showUpdateInvoiceError(
error?.response,
showUpdateInvoiceError({
response: error?.response,
showCallout,
'duplicate',
'ui-invoice.invoice.actions.duplicate.error.message',
mutator.expenseClass,
mutator.fund,
);
action: 'duplicate',
defaultErrorMessageId: 'ui-invoice.invoice.actions.duplicate.error.message',
expenseClassMutator: mutator.expenseClass,
fundMutator: mutator.fund,
ky,
});
})
.finally(() => setIsLoading(false));
}, [
Expand All @@ -429,6 +440,7 @@ export function InvoiceDetailsContainer({
refreshList,
history,
location.search,
ky,
]);

const updateInvoice = useCallback(
Expand Down
4 changes: 4 additions & 0 deletions src/invoices/InvoiceDetails/InvoiceDetailsContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { createInvoiceLineFromPOL, showUpdateInvoiceError } from './utils';
import InvoiceDetails from './InvoiceDetails';
import { InvoiceDetailsContainer } from './InvoiceDetailsContainer';

jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
useOkapiKy: jest.fn().mockReturnValue({}),
}));
jest.mock('../../common/hooks', () => ({
useInvoiceMutation: jest.fn().mockReturnValue({}),
useInvoiceLineMutation: jest.fn().mockReturnValue({}),
Expand Down
Loading
Loading