From 4ca7e505a4c442790b5541484418a272c9c6ab39 Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Wed, 18 Oct 2023 17:16:16 +0500 Subject: [PATCH] feat: add CRUD for banking account types --- src/Settings/AccountTypeSettings/index.js | 1 - .../BankingAccountTypeSettings.js} | 35 +++++++++++++------ .../BankingAccountTypeSettings/index.js | 1 + .../BankingInformationSettings.js | 1 - src/Settings/SettingsPage.js | 4 +-- translations/ui-organizations/en.json | 5 +-- 6 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 src/Settings/AccountTypeSettings/index.js rename src/Settings/{AccountTypeSettings/AccountTypeSettings.js => BankingAccountTypeSettings/BankingAccountTypeSettings.js} (62%) create mode 100644 src/Settings/BankingAccountTypeSettings/index.js diff --git a/src/Settings/AccountTypeSettings/index.js b/src/Settings/AccountTypeSettings/index.js deleted file mode 100644 index db0e3b28..00000000 --- a/src/Settings/AccountTypeSettings/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as AccountTypeSettings } from './AccountTypeSettings'; diff --git a/src/Settings/AccountTypeSettings/AccountTypeSettings.js b/src/Settings/BankingAccountTypeSettings/BankingAccountTypeSettings.js similarity index 62% rename from src/Settings/AccountTypeSettings/AccountTypeSettings.js rename to src/Settings/BankingAccountTypeSettings/BankingAccountTypeSettings.js index 4488e0e2..25462f17 100644 --- a/src/Settings/AccountTypeSettings/AccountTypeSettings.js +++ b/src/Settings/BankingAccountTypeSettings/BankingAccountTypeSettings.js @@ -5,7 +5,7 @@ import { stripesShape } from '@folio/stripes/core'; import { ControlledVocab } from '@folio/stripes/smart-components'; import { getControlledVocabTranslations } from '@folio/stripes-acq-components'; -class AccountTypeSettings extends Component { +class BankingAccountTypeSettings extends Component { constructor(props) { super(props); this.connectedControlledVocab = props.stripes.connect(ControlledVocab); @@ -26,29 +26,44 @@ class AccountTypeSettings extends Component { 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 = ; + } + + return errors; + }; + return ( } translations={getControlledVocabTranslations('ui-organizations.settings.accountTypes')} - objectLabel="Categories" - visibleFields={['value']} + objectLabel="BankingAccountTypes" + visibleFields={['name']} columnMapping={columnMapping} hiddenFields={['lastUpdated', 'numberOfObjects']} - nameKey="categories" - id="categories" - sortby="value" + nameKey="bankingAccountTypes" + id="bankingAccountTypes" + validate={setUniqValidation} + sortby="name" /> ); } } -AccountTypeSettings.propTypes = { +BankingAccountTypeSettings.propTypes = { stripes: stripesShape.isRequired, }; -export default AccountTypeSettings; +export default BankingAccountTypeSettings; diff --git a/src/Settings/BankingAccountTypeSettings/index.js b/src/Settings/BankingAccountTypeSettings/index.js new file mode 100644 index 00000000..52570c07 --- /dev/null +++ b/src/Settings/BankingAccountTypeSettings/index.js @@ -0,0 +1 @@ +export { default as BankingAccountTypeSettings } from './BankingAccountTypeSettings'; diff --git a/src/Settings/BankingInformationSettings/BankingInformationSettings.js b/src/Settings/BankingInformationSettings/BankingInformationSettings.js index f39e1f12..47c23eab 100644 --- a/src/Settings/BankingInformationSettings/BankingInformationSettings.js +++ b/src/Settings/BankingInformationSettings/BankingInformationSettings.js @@ -3,7 +3,6 @@ import { Field, Form } from 'react-final-form'; import { Button, - Checkbox, Col, Headline, Pane, diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index 60be7242..646cd404 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -6,7 +6,7 @@ import { Settings } from '@folio/stripes/smart-components'; import { CategorySettings } from './CategorySettings'; import { TypeSettings } from './TypeSettings'; import { BankingInformationSettings } from './BankingInformationSettings'; -import { AccountTypeSettings } from './AccountTypeSettings'; +import { BankingAccountTypeSettings } from './BankingAccountTypeSettings'; const pages = [ { @@ -28,7 +28,7 @@ const pages = [ route: 'banking-information', }, { - component: AccountTypeSettings, + component: BankingAccountTypeSettings, label: , perm: 'settings.organizations.enabled', route: 'account-types', diff --git a/translations/ui-organizations/en.json b/translations/ui-organizations/en.json index d7f9bfcc..e943b434 100644 --- a/translations/ui-organizations/en.json +++ b/translations/ui-organizations/en.json @@ -443,9 +443,10 @@ "settings.typeStatus.Active": "Active", "settings.typeStatus.Inactive": "Inactive", "settings.bankingInformation": "Banking information", - "settings.bankingInformation.enabled": "Enabled", - "settings.bankingInformation.disabled": "Disabled", + "settings.bankingInformation.enabled": "Enable", + "settings.bankingInformation.disabled": "Disable", "settings.accountTypes": "Account types", + "settings.accountTypes.save.error.accountTypeMustBeUnique": "Account type must be uniq", "permission.view": "Organizations: View", "permission.edit": "Organizations: View, edit",