diff --git a/src/common/journalTypes.js b/src/common/journalTypes.js new file mode 100644 index 000000000..4fffeb112 --- /dev/null +++ b/src/common/journalTypes.js @@ -0,0 +1,8 @@ +import intl from 'react-intl-universal'; + +export const journalTypes = [ + { + name: intl.get('journal'), + value: 'Journal', + }, +]; diff --git a/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.js b/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.js index 9e5e3a783..939e834c9 100644 --- a/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.js +++ b/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.js @@ -4,6 +4,7 @@ import { FormGroup, Position, ControlGroup, + Classes, } from '@blueprintjs/core'; import { FastField, ErrorMessage } from 'formik'; import { DateInput } from '@blueprintjs/datetime'; @@ -11,6 +12,8 @@ import { FormattedMessage as T } from 'components'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; +import { journalTypes } from '../../../common/journalTypes'; +import { FFormGroup } from '../../../components'; import { momentFormatter, compose, @@ -28,12 +31,13 @@ import { } from 'components'; import withSettings from 'containers/Settings/withSettings'; import { useMakeJournalFormContext } from './MakeJournalProvider'; -import { JournalExchangeRateInputField } from './components'; +import { JournalExchangeRateInputField, JournalTypeSelect } from './components'; import withDialogActions from 'containers/Dialog/withDialogActions'; import { currenciesFieldShouldUpdate, useObserveJournalNoSettings, } from './utils'; + /** * Make journal entries header. */ @@ -169,21 +173,18 @@ function MakeJournalEntriesHeader({ {/*------------ Journal type -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - className={classNames('form-group--account-type', CLASSES.FILL)} - inline={true} - > - - - )} - + } + inline={true} + className={classNames('form-group--select-list', Classes.FILL)} + > + + {/*------------ Currency -----------*/} ); } + +/** + * + * @param {*} query + * @param {*} journal + * @param {*} _index + * @param {*} exactMatch + * @returns + */ +const itemPredicate = (query, journal, _index, exactMatch) => { + const normalizedTitle = journal.name.toLowerCase(); + const normalizedQuery = query.toLowerCase(); + + if (exactMatch) { + return normalizedTitle === normalizedQuery; + } else { + return normalizedTitle.indexOf(normalizedQuery) >= 0; + } +}; + +/** + * + * @param {*} item + * @param {*} param1 + * @returns + */ +const itemRenderer = (item, { handleClick, modifiers, query }) => { + return ( + + ); +}; + +const itemSelectProps = { + itemPredicate: itemPredicate, + itemRenderer: itemRenderer, + valueAccessor: 'name', + labelAccessor: 'name', +}; + +export function JournalTypeSelect({ items, ...rest }) { + return ( + + ); +} + +/** + * @param {*} label + * @returns + */ +function itemSelectButton({ label }) { + return ( +