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

UIREC-412 Update 'Send claim' action to use pieces.send-claims interface #624

Merged
merged 3 commits into from
Dec 25, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Change history for ui-receiving

## 6.1.0 (IN PROGRESS)
## 7.0.0 (IN PROGRESS)

* Add "Mark late" action to the piece form action menu. Refs UIREC-413.
* Hide "Add piece" action when related order has "Pending" status and "Synchronized" workflow. Refs UIREC-362.
* *Breaking* Update "Send claim" action to use `pieces.send-claims` interface. Refs UIREC-412.

## [6.0.5](https://github.com/folio-org/ui-receiving/tree/v6.0.5) (2024-12-13)
[Full Changelog](https://github.com/folio-org/ui-receiving/compare/v6.0.4...v6.0.5)
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"orders-storage.settings": "1.0",
"organizations.organizations": "1.0",
"pieces": "3.1",
"pieces.send-claims": "1.0",
"receiving": "2.0",
"search": "0.5 0.6 1.0",
"tags": "1.0",
Expand Down Expand Up @@ -158,10 +159,12 @@
"inventory.instances.collection.get",
"inventory.instances.item.get",
"orders.bind-pieces.collection.post",
"orders.pieces.collection.put",
"orders.routing-lists.item.delete",
"orders.routing-lists.item.put",
"orders.routing-lists.item.post",
"orders.titles.item.put",
"pieces.send-claims.collection.post",
"search.instances.collection.get",
"search.facets.collection.get"
]
Expand Down
80 changes: 0 additions & 80 deletions src/Piece/DelayClaimModal/DelayClaimModal.js

This file was deleted.

73 changes: 0 additions & 73 deletions src/Piece/DelayClaimModal/DelayClaimModal.test.js

This file was deleted.

1 change: 0 additions & 1 deletion src/Piece/DelayClaimModal/index.js

This file was deleted.

44 changes: 20 additions & 24 deletions src/Piece/PieceForm/PieceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,25 @@ import {
import { useStripes } from '@folio/stripes/core';
import { ViewMetaData } from '@folio/stripes/smart-components';
import {
DelayClaimsModal,
DeleteHoldingsModal,
getClaimingIntervalFromDate,
handleKeyCommand,
PIECE_FORMAT,
PIECE_STATUS,
useModalToggle,
} from '@folio/stripes-acq-components';

import {
getClaimingIntervalFromDate,
setLocationValueFormMutator,
} from '../../common/utils';
import { setLocationValueFormMutator } from '../../common/utils';
import {
PIECE_ACTION_NAMES,
PIECE_FORM_FIELD_NAMES,
PIECE_FORM_SERVICE_FIELD_NAMES,
PIECE_MODAL_ACCORDION,
PIECE_MODAL_ACCORDION_LABELS,
} from '../constants';
import { DelayClaimModal } from '../DelayClaimModal';
import { DeletePieceModal } from '../DeletePieceModal';
import { ReceivingStatusChangeLog } from '../ReceivingStatusChangeLog';
import { SendClaimModal } from '../SendClaimModal';
import { ItemFields } from './ItemFields';
import { PieceFields } from './PieceFields';
import { PieceFormActionButtons } from './PieceFormActionButtons';
Expand All @@ -60,6 +57,7 @@ const PieceForm = ({
hasValidationErrors,
initialValues,
instanceId,
onClaimSend: onClaimSendProp,
onClose,
onDelete: onDeleteProp,
onUnreceive: onUnreceiveProp,
Expand All @@ -84,10 +82,8 @@ const PieceForm = ({

const {
enumeration,
externalNote,
format,
id,
internalNote,
itemId,
bindItemId,
isBound,
Expand All @@ -110,7 +106,6 @@ const PieceForm = ({
const [isDeleteConfirmation, toggleDeleteConfirmation] = useModalToggle();
const [isDeleteHoldingsConfirmation, toggleDeleteHoldingsConfirmation] = useModalToggle();
const [isClaimDelayModalOpen, toggleClaimDelayModal] = useModalToggle();
const [isClaimSendModalOpen, toggleClaimSendModal] = useModalToggle();

const { protectCreate, protectUpdate, protectDelete } = restrictionsByAcqUnit;
const isEditMode = Boolean(id);
Expand All @@ -124,6 +119,11 @@ const PieceForm = ({
? PIECE_MODAL_ACCORDION.originalItemDetails
: PIECE_MODAL_ACCORDION.itemDetails;

const onDeleteHoldingsModalCancel = useCallback(() => {
change(PIECE_FORM_SERVICE_FIELD_NAMES.postSubmitAction, null);
toggleDeleteHoldingsConfirmation();
}, [change, toggleDeleteHoldingsConfirmation]);

const onChangeDisplayOnHolding = useCallback(({ target: { checked } }) => {
change(PIECE_FORM_FIELD_NAMES.displayOnHolding, checked);

Expand Down Expand Up @@ -191,13 +191,15 @@ const PieceForm = ({
onStatusChange(PIECE_STATUS.claimDelayed);
}, [change, onStatusChange]);

const onClaimSend = useCallback(({ claimingDate, ...rest }) => {
const onClaimSend = useCallback(async () => {
const updatedFields = await onClaimSendProp(formValues);

batch(() => {
change(PIECE_FORM_FIELD_NAMES.claimingInterval, getClaimingIntervalFromDate(claimingDate));
Object.entries(rest).forEach(([field, value]) => change(field, value));
change(PIECE_FORM_SERVICE_FIELD_NAMES.postSubmitAction, PIECE_ACTION_NAMES.sendClaim);
Object.entries(updatedFields).forEach(([field, value]) => change(field, value));
});
onStatusChange(PIECE_STATUS.claimSent);
}, [batch, change, onStatusChange]);
onSave();
}, [batch, change, formValues, onClaimSendProp, onSave]);

const onDelete = useCallback((options) => {
return onDeleteProp({ id, enumeration }, options);
Expand Down Expand Up @@ -232,7 +234,7 @@ const PieceForm = ({
isEditMode={isEditMode}
onCreateAnotherPiece={onCreateAnotherPiece}
onClaimDelay={toggleClaimDelayModal}
onClaimSend={toggleClaimSendModal}
onClaimSend={onClaimSend}
onDelete={toggleDeleteConfirmation}
onReceive={onQuickReceive}
onUnreceivePiece={onUnreceive}
Expand Down Expand Up @@ -364,25 +366,18 @@ const PieceForm = ({
{
isDeleteHoldingsConfirmation && (
<DeleteHoldingsModal
onCancel={toggleDeleteHoldingsConfirmation}
onCancel={onDeleteHoldingsModalCancel}
onKeepHoldings={handleSubmit}
onConfirm={onDeleteHoldings}
/>
)
}

<DelayClaimModal
<DelayClaimsModal
open={isClaimDelayModalOpen}
onCancel={toggleClaimDelayModal}
onSubmit={onClaimDelay}
/>

<SendClaimModal
open={isClaimSendModalOpen}
onCancel={toggleClaimSendModal}
onSubmit={onClaimSend}
initialValues={{ internalNote, externalNote }}
/>
</Pane>
</Paneset>
</HasCommand>
Expand All @@ -400,6 +395,7 @@ PieceForm.propTypes = {
instanceId: PropTypes.string,
locationIds: PropTypes.arrayOf(PropTypes.string).isRequired,
locations: PropTypes.arrayOf(PropTypes.object),
onClaimSend: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
onUnreceive: PropTypes.func.isRequired,
Expand Down
26 changes: 5 additions & 21 deletions src/Piece/PieceForm/PieceForm.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import moment from 'moment';

import user from '@folio/jest-config-stripes/testing-library/user-event';
import {
act,
screen,
waitFor,
} from '@folio/jest-config-stripes/testing-library/react';
import { dayjs } from '@folio/stripes/components';
import {
FieldInventory,
INVENTORY_RECORDS_TYPE,
Expand Down Expand Up @@ -90,7 +89,7 @@ const logs = [
];

const DATE_FORMAT = 'MM/DD/YYYY';
const today = moment();
const today = dayjs();

const renderPieceForm = (props = {}) => renderWithRouter(
<PieceForm
Expand Down Expand Up @@ -345,9 +344,9 @@ describe('PieceForm', () => {

await user.click(dropdownButton);

const unReceiveButton = screen.getByTestId('unReceivable-piece-button');
const unreceivableButton = screen.getByTestId('unreceivable-button');

await user.click(unReceiveButton);
await user.click(unreceivableButton);

expect(defaultProps.onSubmit).toHaveBeenCalled();
});
Expand Down Expand Up @@ -392,7 +391,7 @@ describe('PieceForm', () => {

it('should handle "Delay claim" action', async () => {
await user.click(screen.getByTestId('delay-claim-button'));
await user.type(screen.getByRole('textbox', { name: 'ui-receiving.modal.delayClaim.field.delayTo' }), date.format(DATE_FORMAT));
await user.type(screen.getByRole('textbox', { name: /field.delayTo/ }), date.format(DATE_FORMAT));
await user.click(await findButton('stripes-acq-components.FormFooter.save'));

expect(defaultProps.onSubmit).toHaveBeenCalledWith(
Expand All @@ -404,20 +403,5 @@ describe('PieceForm', () => {
expect.anything(),
);
});

it('should handle "Send claim" action', async () => {
await user.click(screen.getByTestId('send-claim-button'));
await user.type(screen.getByRole('textbox', { name: 'ui-receiving.modal.sendClaim.field.claimExpiryDate' }), date.format(DATE_FORMAT));
await user.click(await findButton('stripes-acq-components.FormFooter.save'));

expect(defaultProps.onSubmit).toHaveBeenCalledWith(
expect.objectContaining({
claimingInterval: 3,
receivingStatus: PIECE_STATUS.claimSent,
}),
expect.anything(),
expect.anything(),
);
});
});
});
Loading
Loading