-
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.
- Loading branch information
1 parent
4ca7e50
commit c05b8e2
Showing
6 changed files
with
150 additions
and
80 deletions.
There are no files selected for viewing
111 changes: 52 additions & 59 deletions
111
src/Settings/BankingAccountTypeSettings/BankingAccountTypeSettings.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 |
---|---|---|
@@ -1,69 +1,62 @@ | ||
import React, { Component } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { stripesShape } from '@folio/stripes/core'; | ||
import { stripesConnect, stripesShape } from '@folio/stripes/core'; | ||
import { ControlledVocab } from '@folio/stripes/smart-components'; | ||
import { getControlledVocabTranslations } from '@folio/stripes-acq-components'; | ||
|
||
class BankingAccountTypeSettings extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.connectedControlledVocab = props.stripes.connect(ControlledVocab); | ||
} | ||
|
||
render() { | ||
const { stripes } = this.props; | ||
const columnMapping = { | ||
value: <FormattedMessage id="ui-organizations.settings.name" />, | ||
action: <FormattedMessage id="ui-organizations.settings.action" />, | ||
}; | ||
|
||
const hasEditPerms = stripes.hasPerm('ui-organizations.settings'); | ||
const actionSuppressor = { | ||
edit: () => !hasEditPerms, | ||
delete: () => !hasEditPerms, | ||
}; | ||
|
||
const ConnectedComponent = this.connectedControlledVocab; | ||
|
||
const setUniqValidation = (value, index, items) => { | ||
const errors = {}; | ||
|
||
const isAccountTypeExist = items.some(({ id, name }) => { | ||
return name?.toLowerCase() === value?.name?.toLowerCase() && id !== value?.id; | ||
}); | ||
|
||
if (isAccountTypeExist) { | ||
errors.name = <FormattedMessage id="ui-organizations.settings.accountTypes.save.error.accountTypeMustBeUnique" />; | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
return ( | ||
<ConnectedComponent | ||
actionSuppressor={actionSuppressor} | ||
canCreate={hasEditPerms} | ||
stripes={stripes} | ||
baseUrl="organizations-storage/banking-account-types" | ||
records="bankingAccountTypes" | ||
label={<FormattedMessage id="ui-organizations.settings.accountTypes" />} | ||
translations={getControlledVocabTranslations('ui-organizations.settings.accountTypes')} | ||
objectLabel="BankingAccountTypes" | ||
visibleFields={['name']} | ||
columnMapping={columnMapping} | ||
hiddenFields={['lastUpdated', 'numberOfObjects']} | ||
nameKey="bankingAccountTypes" | ||
id="bankingAccountTypes" | ||
validate={setUniqValidation} | ||
sortby="name" | ||
/> | ||
); | ||
} | ||
} | ||
import { BANKING_ACCOUNT_TYPES_API } from '../constants'; | ||
|
||
const BankingAccountTypeSettings = ({ stripes }) => { | ||
const ConnectedComponent = stripes.connect(ControlledVocab); | ||
|
||
const columnMapping = { | ||
value: <FormattedMessage id="ui-organizations.settings.name" />, | ||
action: <FormattedMessage id="ui-organizations.settings.action" />, | ||
}; | ||
|
||
const hasEditPerms = stripes.hasPerm('ui-organizations.settings'); | ||
const actionSuppressor = { | ||
edit: () => !hasEditPerms, | ||
delete: () => !hasEditPerms, | ||
}; | ||
|
||
const setUniqValidation = (value, index, items) => { | ||
const errors = {}; | ||
|
||
const isBankingAccountTypeExist = items.some(({ id, name }) => { | ||
return name?.toLowerCase() === value?.name?.toLowerCase() && id !== value?.id; | ||
}); | ||
|
||
if (isBankingAccountTypeExist) { | ||
errors.name = <FormattedMessage id="ui-organizations.settings.accountTypes.save.error.accountTypeMustBeUnique" />; | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
return ( | ||
<ConnectedComponent | ||
actionSuppressor={actionSuppressor} | ||
canCreate={hasEditPerms} | ||
stripes={stripes} | ||
baseUrl={BANKING_ACCOUNT_TYPES_API} | ||
records="bankingAccountTypes" | ||
label={<FormattedMessage id="ui-organizations.settings.bankingAccountTypes" />} | ||
translations={getControlledVocabTranslations('ui-organizations.settings.bankingAccountTypes')} | ||
objectLabel="BankingAccountTypes" | ||
visibleFields={['name']} | ||
columnMapping={columnMapping} | ||
hiddenFields={['lastUpdated', 'numberOfObjects']} | ||
nameKey="bankingAccountTypes" | ||
id="bankingAccountTypes" | ||
validate={setUniqValidation} | ||
sortby="name" | ||
/> | ||
); | ||
}; | ||
|
||
BankingAccountTypeSettings.propTypes = { | ||
stripes: stripesShape.isRequired, | ||
}; | ||
|
||
export default BankingAccountTypeSettings; | ||
export default stripesConnect(BankingAccountTypeSettings); |
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,4 @@ | ||
export const SETTINGS_API = 'organizations-storage/settings'; | ||
export const BANKING_ACCOUNT_TYPES_API = 'organizations-storage/banking-account-types'; | ||
|
||
export const MAX_LIMIT = 1; |
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 { useQuery } from 'react-query'; | ||
import { get } from 'lodash'; | ||
|
||
import { | ||
useNamespace, | ||
useOkapiKy, | ||
} from '@folio/stripes/core'; | ||
|
||
import { MAX_LIMIT, SETTINGS_API } from '../constants'; | ||
|
||
export const useBankingInformation = () => { | ||
const ky = useOkapiKy(); | ||
const [namespace] = useNamespace({ key: 'banking-information-settings' }); | ||
|
||
const searchParams = { | ||
limit: MAX_LIMIT, | ||
query: 'key=BANKING_INFORMATION_ENABLED', | ||
}; | ||
|
||
const { isLoading, data } = useQuery( | ||
[namespace], | ||
() => ky.get(SETTINGS_API, { searchParams }).json().catch(() => null), | ||
); | ||
|
||
const bankingInformation = get(data, 'settings[0]', {}); | ||
|
||
return ({ | ||
id: bankingInformation.id, | ||
enabled: bankingInformation.value === 'true', | ||
key: bankingInformation.key, | ||
isLoading, | ||
}); | ||
}; |
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