Skip to content

Commit

Permalink
Move reusable claiming code from ui-receiving to the shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Dec 17, 2024
1 parent a6b569e commit ff51770
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 0 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 @@
* Move reusable version history components to the ACQ lib. Refs UISACQCOMP-230.
* Move reusable helper function to support version history functionality. Refs UISACQCOMP-232.
* Move reusable version history hook useVersionHistoryValueResolvers to the ACQ lib. Refs UISACQCOMP-235.
* Move reusable claiming code from `ui-receiving` to the shared library. Refs UISACQCOMP-236.

## [6.0.2](https://github.com/folio-org/stripes-acq-components/tree/v6.0.2) (2024-12-04)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v6.0.1...v6.0.2)
Expand Down
1 change: 1 addition & 0 deletions lib/FindRecords/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './FindRecords';
export { useRecordsSelect } from './hooks';
42 changes: 42 additions & 0 deletions lib/claiming/components/FieldClaimingDate/FieldClaimingDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import PropTypes from 'prop-types';

import { FieldDatepickerFinal } from '../../../FieldDatepicker';
import { validateRequired } from '../../../utils';
import {
excludePreviousDays,
validateClaimingDate,
} from './utils';

export const FieldClaimingDate = ({
name,
required,
...props
}) => {
const validate = (value) => {
return (
(required && validateRequired(value))
|| validateClaimingDate(value)
);
};

return (
<FieldDatepickerFinal
usePortal
name={name}
required={required}
validate={validate}
exclude={excludePreviousDays}
{...props}
/>
);
};

FieldClaimingDate.propTypes = {
name: PropTypes.string,
required: PropTypes.bool,
};

FieldClaimingDate.defaultProps = {
name: 'claimingDate',
required: true,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MemoryRouter } from 'react-router-dom';

import { render, screen } from '@testing-library/react';
import stripesFinalForm from '@folio/stripes/final-form';

import { FieldClaimingDate } from './FieldClaimingDate';

const defaultProps = {
label: 'Label',
};

const FormComponent = stripesFinalForm({})(({ children }) => <form>{children}</form>);

const renderFieldClaimingDate = (props = {}, formProps = {}) => render(
<FormComponent
onSubmit={jest.fn}
{...formProps}
>
<FieldClaimingDate
{...defaultProps}
{...props}
/>
</FormComponent>,
{ wrapper: MemoryRouter },
);

describe('FieldClaimingDate', () => {
it('should render field', () => {
renderFieldClaimingDate();

expect(screen.getByText(defaultProps.label)).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions lib/claiming/components/FieldClaimingDate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FieldClaimingDate } from './FieldClaimingDate';
19 changes: 19 additions & 0 deletions lib/claiming/components/FieldClaimingDate/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FormattedMessage } from 'react-intl';

import { dayjs } from '@folio/stripes/components';

const isSameOrBeforeDay = (day) => {
const today = dayjs().startOf('day');

return day.isSameOrBefore(today, 'day');
};

export const validateClaimingDate = (value) => {
return isSameOrBeforeDay(dayjs(value))
? <FormattedMessage id="stripes-acq-components.validation.dateAfter" />
: undefined;
};

export const excludePreviousDays = (day) => {
return isSameOrBeforeDay(day);
};
1 change: 1 addition & 0 deletions lib/claiming/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './menu-items';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

import {
Button,
Icon,
} from '@folio/stripes/components';

export const DelayClaimActionMenuItem = ({
disabled,
onClick,
}) => {
return (
<Button
data-testid="delay-claim-button"
disabled={disabled}
buttonStyle="dropdownItem"
onClick={onClick}
>
<Icon icon="calendar">
<FormattedMessage id="stripes-acq-components.claiming.action.delayClaim" />
</Icon>
</Button>
);
};

DelayClaimActionMenuItem.propTypes = {
disabled: PropTypes.bool,
onClick: PropTypes.func.isRequired,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

import {
Button,
Icon,
} from '@folio/stripes/components';

export const MarkUnreceivableActionMenuItem = ({
disabled,
onClick,
}) => {
return (
<Button
data-testid="unreceivable-button"
disabled={disabled}
buttonStyle="dropdownItem"
onClick={onClick}
>
<Icon icon="cancel">
<FormattedMessage id="stripes-acq-components.claiming.action.unreceivable" />
</Icon>
</Button>
);
};

MarkUnreceivableActionMenuItem.propTypes = {
disabled: PropTypes.bool,
onClick: PropTypes.func.isRequired,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

import {
Button,
Icon,
} from '@folio/stripes/components';

export const SendClaimActionMenuItem = ({
disabled,
onClick,
}) => {
return (
<Button
disabled={disabled}
buttonStyle="dropdownItem"
data-testid="send-claim-button"
onClick={onClick}
>
<Icon icon="envelope">
<FormattedMessage id="stripes-acq-components.claiming.action.sendClaim" />
</Icon>
</Button>
);
};

SendClaimActionMenuItem.propTypes = {
disabled: PropTypes.bool,
onClick: PropTypes.func.isRequired,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SendClaimActionMenuItem } from './SendClaimActionMenuItem';
3 changes: 3 additions & 0 deletions lib/claiming/components/menu-items/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem';
export { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem';
export { SendClaimActionMenuItem } from './SendClaimActionMenuItem';
1 change: 1 addition & 0 deletions lib/claiming/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useClaimsSend } from './useClaimsSend';
1 change: 1 addition & 0 deletions lib/claiming/hooks/useClaimsSend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useClaimsSend } from './useClaimsSend';
24 changes: 24 additions & 0 deletions lib/claiming/hooks/useClaimsSend/useClaimsSend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useCallback } from 'react';
import { useMutation } from 'react-query';

import { useOkapiKy } from '@folio/stripes/core';

import { SEND_CLAIMS_API } from '../../../constants';

export const useClaimsSend = () => {
const ky = useOkapiKy();

const mutationFn = useCallback(({ data }) => {
return ky.post(SEND_CLAIMS_API, { json: data });
}, [ky]);

const {
mutateAsync,
isLoading,
} = useMutation({ mutationFn });

return {
isLoading,
sendClaims: mutateAsync,
};
};
2 changes: 2 additions & 0 deletions lib/claiming/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './components';
export * from './hooks';
2 changes: 2 additions & 0 deletions lib/constants/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export const MATERIAL_TYPE_API = 'material-types';
export const ORDERS_API = 'orders/composite-orders';
export const ORDER_PIECES_API = 'orders/pieces';
export const ORDERS_STORAGE_SETTINGS_API = 'orders-storage/settings';
export const PIECES_BATCH_STATUS_API = 'orders/pieces-batch/status';
export const PREFIXES_API = 'orders/configuration/prefixes';
export const PRIVILEGED_CONTACTS_API = 'organizations-storage/privileged-contacts';
export const PUBLICATIONS_API = 'publications';
export const REQUESTS_API = 'circulation/requests';
export const RECEIVING_TITLES_API = 'orders/titles';
export const ROUTING_LIST_API = 'orders/routing-lists';
export const SEARCH_API = 'search';
export const SEND_CLAIMS_API = 'pieces/claim';
export const SUFFIXES_API = 'orders/configuration/suffixes';
export const TAGS_API = 'tags';
export const TRANSACTIONS_API = 'finance/transactions';
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from './useModalToggle';
export * from './useOrderLine';
export * from './useOrganization';
export * from './usePaneFocus';
export * from './usePiecesStatusBatchUpdate';
export * from './useReceivingTenantIdsAndLocations';
export * from './useShowCallout';
export * from './useTags';
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/usePiecesStatusBatchUpdate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { usePiecesStatusBatchUpdate } from './usePiecesStatusBatchUpdate';

Check failure on line 1 in lib/hooks/usePiecesStatusBatchUpdate/index.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unable to resolve path to module './usePiecesStatusBatchUpdate'

Check failure on line 1 in lib/hooks/usePiecesStatusBatchUpdate/index.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unable to resolve path to module './usePiecesStatusBatchUpdate'
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './AffiliationsSelection';
export * from './AmountWithCurrencyField';
export * from './apiHooks';
export * from './BooleanFilter';
export * from './claiming';
export * from './ConsortiumFieldInventory';
export * from './constants';
export * from './contexts';
Expand Down
4 changes: 4 additions & 0 deletions translations/stripes-acq-components/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
"receiving.itemStatus.Order closed": "Order closed",
"receiving.itemStatus.Undefined": "Undefined",

"claiming.action.sendClaim": "Send claim",
"claiming.action.delayClaim": "Delay claim",
"claiming.action.unreceivable": "Unreceivable",

"referenceNumbers.addReferenceNumbers": "Add vendor reference number",
"referenceNumbers.refNumber": "Vendor reference number",
"referenceNumbers.refNumberType": "Vendor reference type",
Expand Down

0 comments on commit ff51770

Please sign in to comment.