-
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.
UIORGS-390 Implement base components and hooks for banking informatio…
…n (no logic)
- Loading branch information
1 parent
7b6029e
commit 92d7a99
Showing
16 changed files
with
301 additions
and
9 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
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
101 changes: 101 additions & 0 deletions
101
...zationForm/OrganizationBankingInfoForm/BankingInformationField/BankingInformationField.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,101 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Field } from 'react-final-form'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { | ||
Card, | ||
Col, | ||
Row, | ||
TextField, | ||
} from '@folio/stripes/components'; | ||
import { FieldSelectionFinal } from '@folio/stripes-acq-components'; | ||
|
||
import { FieldIsPrimary } from '../../../../common/components'; | ||
|
||
export const BankingInformationField = ({ | ||
bankingAccountTypeOptions, | ||
fields, | ||
index, | ||
name, | ||
}) => { | ||
const cardHeader = ( | ||
<FieldIsPrimary | ||
fields={fields} | ||
fieldIndex={index} | ||
fieldPrefix={name} | ||
labelId="ui-organizations.data.bankingInformation.isPrimary" | ||
/> | ||
); | ||
|
||
return ( | ||
<Card headerStart={cardHeader}> | ||
<Row> | ||
<Col xs={12} md={4}> | ||
<Field | ||
label={<FormattedMessage id="ui-organizations.data.bankingInformation.bankName" />} | ||
name={`${name}.bankName`} | ||
component={TextField} | ||
fullWidth | ||
validateFields={[]} | ||
/> | ||
</Col> | ||
<Col xs={12} md={4}> | ||
<Field | ||
label={<FormattedMessage id="ui-organizations.data.bankingInformation.bankAccountNumber" />} | ||
name={`${name}.bankAccountNumber`} | ||
component={TextField} | ||
fullWidth | ||
validateFields={[]} | ||
/> | ||
</Col> | ||
<Col xs={12} md={4}> | ||
<Field | ||
label={<FormattedMessage id="ui-organizations.data.bankingInformation.transitNumber" />} | ||
name={`${name}.transitNumber`} | ||
component={TextField} | ||
fullWidth | ||
validateFields={[]} | ||
/> | ||
</Col> | ||
<Col xs={12} md={4}> | ||
<FieldSelectionFinal | ||
label={<FormattedMessage id="ui-organizations.data.bankingInformation.address" />} | ||
name={`${name}.addressId`} | ||
// TODO: refine address field | ||
dataOptions={[]} | ||
validateFields={[]} | ||
/> | ||
</Col> | ||
<Col xs={12} md={4}> | ||
<FieldSelectionFinal | ||
label={<FormattedMessage id="ui-organizations.data.bankingInformation.accountType" />} | ||
name={`${name}.accountTypeId`} | ||
dataOptions={bankingAccountTypeOptions} | ||
fullWidth | ||
validateFields={[]} | ||
/> | ||
</Col> | ||
<Col xs={12} md={4}> | ||
<Field | ||
label={<FormattedMessage id="ui-organizations.data.bankingInformation.notes" />} | ||
name={`${name}.notes`} | ||
id={`${name}.notes`} | ||
component={TextField} | ||
fullWidth | ||
validateFields={[]} | ||
/> | ||
</Col> | ||
</Row> | ||
</Card> | ||
); | ||
}; | ||
|
||
BankingInformationField.propTypes = { | ||
bankingAccountTypeOptions: PropTypes.arrayOf(PropTypes.shape({ | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
})).isRequired, | ||
fields: PropTypes.object.isRequired, | ||
index: PropTypes.number.isRequired, | ||
name: PropTypes.string.isRequired, | ||
}; |
1 change: 1 addition & 0 deletions
1
...ganizations/OrganizationForm/OrganizationBankingInfoForm/BankingInformationField/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 { BankingInformationField } from './BankingInformationField'; |
54 changes: 54 additions & 0 deletions
54
...Organizations/OrganizationForm/OrganizationBankingInfoForm/OrganizationBankingInfoForm.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,54 @@ | ||
import { useMemo } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { FieldArray } from 'react-final-form-arrays'; | ||
|
||
import { Loading } from '@folio/stripes/components'; | ||
import { RepeatableFieldWithValidation } from '@folio/stripes-acq-components'; | ||
|
||
import { useBankingAccountTypes } from '../../../common/hooks'; | ||
import { | ||
createAddNewItem, | ||
removeItem, | ||
} from '../../../common/utils'; | ||
import { validatePrimary } from '../../../common/validation'; | ||
import { BankingInformationField } from './BankingInformationField'; | ||
|
||
const renderField = (props) => (name, index, fields) => ( | ||
<BankingInformationField | ||
{...props} | ||
name={name} | ||
index={index} | ||
fields={fields} | ||
/> | ||
); | ||
|
||
export const OrganizationBankingInfoForm = () => { | ||
const { | ||
bankingAccountTypes, | ||
isFetching, | ||
} = useBankingAccountTypes(); | ||
|
||
const bankingAccountTypeOptions = useMemo(() => { | ||
return bankingAccountTypes.map(({ id, name }) => ({ | ||
label: name, | ||
value: id, | ||
})); | ||
}, [bankingAccountTypes]); | ||
|
||
if (isFetching) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<FieldArray | ||
addLabel={<FormattedMessage id="ui-organizations.button.bankingInformation.add" />} | ||
component={RepeatableFieldWithValidation} | ||
id="bankingInformation" | ||
name="bankingInformation" | ||
onAdd={createAddNewItem()} | ||
onRemove={removeItem} | ||
renderField={renderField({ bankingAccountTypeOptions })} | ||
validate={validatePrimary} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/Organizations/OrganizationForm/OrganizationBankingInfoForm/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 { OrganizationBankingInfoForm } from './OrganizationBankingInfoForm'; |
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
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,7 +1,9 @@ | ||
export * from './useAcqMethods'; | ||
export * from './useBankingAccountTypes'; | ||
export * from './useBankingInformationSettings'; | ||
export * from './useIntegrationConfig'; | ||
export * from './useIntegrationConfigMutation'; | ||
export * from './useLinkedAgreements'; | ||
export * from './useOrganizationBankingInformation'; | ||
export * from './useTranslatedCategories'; | ||
export * from './useTypes'; |
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 { useBankingAccountTypes } from './useBankingAccountTypes'; |
40 changes: 40 additions & 0 deletions
40
src/common/hooks/useBankingAccountTypes/useBankingAccountTypes.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,40 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import { | ||
useNamespace, | ||
useOkapiKy, | ||
} from '@folio/stripes/core'; | ||
import { LIMIT_MAX } from '@folio/stripes-acq-components'; | ||
|
||
import { BANKING_ACCOUNT_TYPES_API } from '../../constants'; | ||
|
||
const DEFAULT_DATA = []; | ||
|
||
export const useBankingAccountTypes = () => { | ||
const ky = useOkapiKy(); | ||
const [namespace] = useNamespace({ key: 'banking-account-types' }); | ||
|
||
const { | ||
data, | ||
isFetching, | ||
isLoading, | ||
refetch, | ||
} = useQuery( | ||
[namespace], | ||
() => { | ||
const searchParams = { | ||
limit: LIMIT_MAX, | ||
}; | ||
|
||
return ky.get(BANKING_ACCOUNT_TYPES_API, { searchParams }).json(); | ||
}, | ||
); | ||
|
||
return ({ | ||
bankingAccountTypes: data?.bankingAccountTypes || DEFAULT_DATA, | ||
totalRecords: data?.totalRecords, | ||
isFetching, | ||
isLoading, | ||
refetch, | ||
}); | ||
}; |
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 { useOrganizationBankingInformation } from './useOrganizationBankingInformation'; |
Oops, something went wrong.