-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move reusable claiming code from ui-receiving to the shared library
- Loading branch information
1 parent
a6b569e
commit ff51770
Showing
23 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
lib/claiming/components/FieldClaimingDate/FieldClaimingDate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
33 changes: 33 additions & 0 deletions
33
lib/claiming/components/FieldClaimingDate/FieldClaimingDate.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FieldClaimingDate } from './FieldClaimingDate'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './menu-items'; |
30 changes: 30 additions & 0 deletions
30
lib/claiming/components/menu-items/DelayClaimActionMenuItem/DelayClaimActionMenuItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
1 change: 1 addition & 0 deletions
1
lib/claiming/components/menu-items/DelayClaimActionMenuItem/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem'; |
30 changes: 30 additions & 0 deletions
30
...ng/components/menu-items/MarkUnreceivableActionMenuItem/MarkUnreceivableActionMenuItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
1 change: 1 addition & 0 deletions
1
lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem'; |
30 changes: 30 additions & 0 deletions
30
lib/claiming/components/menu-items/SendClaimActionMenuItem/SendClaimActionMenuItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
1 change: 1 addition & 0 deletions
1
lib/claiming/components/menu-items/SendClaimActionMenuItem/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SendClaimActionMenuItem } from './SendClaimActionMenuItem'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useClaimsSend } from './useClaimsSend'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useClaimsSend } from './useClaimsSend'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './components'; | ||
export * from './hooks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / github-actions-ci
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters