-
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
b8aa6d8
commit ab5e6cc
Showing
6 changed files
with
79 additions
and
83 deletions.
There are no files selected for viewing
110 changes: 49 additions & 61 deletions
110
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,72 +1,60 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { stripesShape } from '@folio/stripes/core'; | ||
import { useStripes } from '@folio/stripes/core'; | ||
import { ControlledVocab } from '@folio/stripes/smart-components'; | ||
import { getControlledVocabTranslations } from '@folio/stripes-acq-components'; | ||
|
||
import { BANKING_ACCOUNT_TYPES_API } from '../constants'; | ||
|
||
class BankingAccountTypeSettings extends React.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 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; | ||
}; | ||
|
||
const ConnectedComponent = this.connectedControlledVocab; | ||
|
||
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, | ||
const BankingAccountTypeSettings = () => { | ||
const stripes = useStripes(); | ||
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" | ||
/> | ||
); | ||
}; | ||
|
||
export default 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
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