diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a109361..18f6c496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/FindRecords/index.js b/lib/FindRecords/index.js index 4fb1a2de..57e12b82 100644 --- a/lib/FindRecords/index.js +++ b/lib/FindRecords/index.js @@ -1 +1,2 @@ export * from './FindRecords'; +export { useRecordsSelect } from './hooks'; diff --git a/lib/claiming/components/FieldClaimingDate/FieldClaimingDate.js b/lib/claiming/components/FieldClaimingDate/FieldClaimingDate.js new file mode 100644 index 00000000..dd152e05 --- /dev/null +++ b/lib/claiming/components/FieldClaimingDate/FieldClaimingDate.js @@ -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 ( + + ); +}; + +FieldClaimingDate.propTypes = { + name: PropTypes.string, + required: PropTypes.bool, +}; + +FieldClaimingDate.defaultProps = { + name: 'claimingDate', + required: true, +}; diff --git a/lib/claiming/components/FieldClaimingDate/FieldClaimingDate.test.js b/lib/claiming/components/FieldClaimingDate/FieldClaimingDate.test.js new file mode 100644 index 00000000..f839362c --- /dev/null +++ b/lib/claiming/components/FieldClaimingDate/FieldClaimingDate.test.js @@ -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 }) =>
{children}
); + +const renderFieldClaimingDate = (props = {}, formProps = {}) => render( + + + , + { wrapper: MemoryRouter }, +); + +describe('FieldClaimingDate', () => { + it('should render field', () => { + renderFieldClaimingDate(); + + expect(screen.getByText(defaultProps.label)).toBeInTheDocument(); + }); +}); diff --git a/lib/claiming/components/FieldClaimingDate/index.js b/lib/claiming/components/FieldClaimingDate/index.js new file mode 100644 index 00000000..b3918dee --- /dev/null +++ b/lib/claiming/components/FieldClaimingDate/index.js @@ -0,0 +1 @@ +export { FieldClaimingDate } from './FieldClaimingDate'; diff --git a/lib/claiming/components/FieldClaimingDate/utils.js b/lib/claiming/components/FieldClaimingDate/utils.js new file mode 100644 index 00000000..789b69ec --- /dev/null +++ b/lib/claiming/components/FieldClaimingDate/utils.js @@ -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)) + ? + : undefined; +}; + +export const excludePreviousDays = (day) => { + return isSameOrBeforeDay(day); +}; diff --git a/lib/claiming/components/index.js b/lib/claiming/components/index.js new file mode 100644 index 00000000..7c64335c --- /dev/null +++ b/lib/claiming/components/index.js @@ -0,0 +1 @@ +export * from './menu-items'; diff --git a/lib/claiming/components/menu-items/DelayClaimActionMenuItem/DelayClaimActionMenuItem.js b/lib/claiming/components/menu-items/DelayClaimActionMenuItem/DelayClaimActionMenuItem.js new file mode 100644 index 00000000..822ec7ca --- /dev/null +++ b/lib/claiming/components/menu-items/DelayClaimActionMenuItem/DelayClaimActionMenuItem.js @@ -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 ( + + ); +}; + +DelayClaimActionMenuItem.propTypes = { + disabled: PropTypes.bool, + onClick: PropTypes.func.isRequired, +}; diff --git a/lib/claiming/components/menu-items/DelayClaimActionMenuItem/index.js b/lib/claiming/components/menu-items/DelayClaimActionMenuItem/index.js new file mode 100644 index 00000000..283eb6a9 --- /dev/null +++ b/lib/claiming/components/menu-items/DelayClaimActionMenuItem/index.js @@ -0,0 +1 @@ +export { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem'; diff --git a/lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/MarkUnreceivableActionMenuItem.js b/lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/MarkUnreceivableActionMenuItem.js new file mode 100644 index 00000000..9eea27ea --- /dev/null +++ b/lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/MarkUnreceivableActionMenuItem.js @@ -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 ( + + ); +}; + +MarkUnreceivableActionMenuItem.propTypes = { + disabled: PropTypes.bool, + onClick: PropTypes.func.isRequired, +}; diff --git a/lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/index.js b/lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/index.js new file mode 100644 index 00000000..3951ec2b --- /dev/null +++ b/lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/index.js @@ -0,0 +1 @@ +export { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem'; diff --git a/lib/claiming/components/menu-items/SendClaimActionMenuItem/SendClaimActionMenuItem.js b/lib/claiming/components/menu-items/SendClaimActionMenuItem/SendClaimActionMenuItem.js new file mode 100644 index 00000000..5f291e0d --- /dev/null +++ b/lib/claiming/components/menu-items/SendClaimActionMenuItem/SendClaimActionMenuItem.js @@ -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 ( + + ); +}; + +SendClaimActionMenuItem.propTypes = { + disabled: PropTypes.bool, + onClick: PropTypes.func.isRequired, +}; diff --git a/lib/claiming/components/menu-items/SendClaimActionMenuItem/index.js b/lib/claiming/components/menu-items/SendClaimActionMenuItem/index.js new file mode 100644 index 00000000..fefefcb8 --- /dev/null +++ b/lib/claiming/components/menu-items/SendClaimActionMenuItem/index.js @@ -0,0 +1 @@ +export { SendClaimActionMenuItem } from './SendClaimActionMenuItem'; diff --git a/lib/claiming/components/menu-items/index.js b/lib/claiming/components/menu-items/index.js new file mode 100644 index 00000000..57057248 --- /dev/null +++ b/lib/claiming/components/menu-items/index.js @@ -0,0 +1,3 @@ +export { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem'; +export { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem'; +export { SendClaimActionMenuItem } from './SendClaimActionMenuItem'; diff --git a/lib/claiming/hooks/index.js b/lib/claiming/hooks/index.js new file mode 100644 index 00000000..d9d4766b --- /dev/null +++ b/lib/claiming/hooks/index.js @@ -0,0 +1 @@ +export { useClaimsSend } from './useClaimsSend'; diff --git a/lib/claiming/hooks/useClaimsSend/index.js b/lib/claiming/hooks/useClaimsSend/index.js new file mode 100644 index 00000000..d9d4766b --- /dev/null +++ b/lib/claiming/hooks/useClaimsSend/index.js @@ -0,0 +1 @@ +export { useClaimsSend } from './useClaimsSend'; diff --git a/lib/claiming/hooks/useClaimsSend/useClaimsSend.js b/lib/claiming/hooks/useClaimsSend/useClaimsSend.js new file mode 100644 index 00000000..9df355b4 --- /dev/null +++ b/lib/claiming/hooks/useClaimsSend/useClaimsSend.js @@ -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, + }; +}; diff --git a/lib/claiming/index.js b/lib/claiming/index.js new file mode 100644 index 00000000..f76fd6f1 --- /dev/null +++ b/lib/claiming/index.js @@ -0,0 +1,2 @@ +export * from './components'; +export * from './hooks'; diff --git a/lib/constants/api.js b/lib/constants/api.js index ef5dbb98..c3fff00b 100644 --- a/lib/constants/api.js +++ b/lib/constants/api.js @@ -32,6 +32,7 @@ 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'; @@ -39,6 +40,7 @@ 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'; diff --git a/lib/hooks/index.js b/lib/hooks/index.js index 19723f7f..91a50365 100644 --- a/lib/hooks/index.js +++ b/lib/hooks/index.js @@ -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'; diff --git a/lib/hooks/usePiecesStatusBatchUpdate/index.js b/lib/hooks/usePiecesStatusBatchUpdate/index.js new file mode 100644 index 00000000..47b5c696 --- /dev/null +++ b/lib/hooks/usePiecesStatusBatchUpdate/index.js @@ -0,0 +1 @@ +export { usePiecesStatusBatchUpdate } from './usePiecesStatusBatchUpdate'; diff --git a/lib/index.js b/lib/index.js index f297f1d4..04b78ef0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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'; diff --git a/translations/stripes-acq-components/en.json b/translations/stripes-acq-components/en.json index bf175ba7..4d68d25c 100644 --- a/translations/stripes-acq-components/en.json +++ b/translations/stripes-acq-components/en.json @@ -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",