fix: accounts list

This commit is contained in:
a.bouhuolia
2021-01-23 18:44:24 +02:00
parent 3f2387b875
commit b7913683c4
5 changed files with 13 additions and 22 deletions

View File

@@ -29,15 +29,10 @@ export default function AccountsTypesSelect({
onTypeSelected && onTypeSelected(accountType); onTypeSelected && onTypeSelected(accountType);
}; };
const items = accountsTypes.map((type) => ({
id: type.id,
label: type.label,
}));
return ( return (
<ListSelect <ListSelect
items={items} items={accountsTypes}
selectedItemProp={'id'} selectedItemProp={'key'}
selectedItem={selectedTypeId} selectedItem={selectedTypeId}
textProp={'label'} textProp={'label'}
defaultText={defaultSelectText} defaultText={defaultSelectText}

View File

@@ -148,7 +148,7 @@ function AccountsDataTable({
{ {
id: 'type', id: 'type',
Header: formatMessage({ id: 'type' }), Header: formatMessage({ id: 'type' }),
accessor: 'type.label', accessor: 'account_type_label',
className: 'type', className: 'type',
width: 140, width: 140,
}, },
@@ -156,7 +156,7 @@ function AccountsDataTable({
id: 'normal', id: 'normal',
Header: formatMessage({ id: 'normal' }), Header: formatMessage({ id: 'normal' }),
Cell: NormalCell, Cell: NormalCell,
accessor: 'type.normal', accessor: 'account_normal',
className: 'normal', className: 'normal',
width: 65, width: 65,
}, },

View File

@@ -8,17 +8,14 @@ import { FormattedMessage as T, useIntl } from 'react-intl';
import classNames from 'classnames'; import classNames from 'classnames';
import { Icon, Money, If, Choose } from 'components'; import { Icon, Money, If, Choose } from 'components';
export function NormalCell({ cell }) { export function NormalCell({ cell: { value } }) {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const arrowDirection = value === 'credit' ? 'down' : 'up';
const account = cell.row.original;
const normal = account?.type?.normal || '';
const arrowDirection = normal === 'credit' ? 'down' : 'up';
return ( return (
<Tooltip <Tooltip
className={Classes.TOOLTIP_INDICATOR} className={Classes.TOOLTIP_INDICATOR}
content={formatMessage({ id: normal })} content={formatMessage({ id: value })}
position={Position.RIGHT} position={Position.RIGHT}
hoverOpenDelay={100} hoverOpenDelay={100}
> >

View File

@@ -9,10 +9,9 @@ const Schema = Yup.object().shape({
.max(DATATYPES_LENGTH.STRING) .max(DATATYPES_LENGTH.STRING)
.label(formatMessage({ id: 'account_name_' })), .label(formatMessage({ id: 'account_name_' })),
code: Yup.string().nullable().min(3).max(6), code: Yup.string().nullable().min(3).max(6),
account_type_id: Yup.number() account_type: Yup.string()
.nullable()
.required() .required()
.label(formatMessage({ id: 'account_type_id' })), .label(formatMessage({ id: 'account_type' })),
description: Yup.string().min(3).max(DATATYPES_LENGTH.TEXT).nullable().trim(), description: Yup.string().min(3).max(DATATYPES_LENGTH.TEXT).nullable().trim(),
parent_account_id: Yup.number().nullable(), parent_account_id: Yup.number().nullable(),
}); });

View File

@@ -42,22 +42,22 @@ function AccountFormDialogFields({
return ( return (
<Form> <Form>
<div className={Classes.DIALOG_BODY}> <div className={Classes.DIALOG_BODY}>
<FastField name={'account_type_id'}> <FastField name={'account_type'}>
{({ form, field: { value }, meta: { error, touched } }) => ( {({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup <FormGroup
label={<T id={'account_type'} />} label={<T id={'account_type'} />}
labelInfo={<FieldRequiredHint />} labelInfo={<FieldRequiredHint />}
className={classNames('form-group--account-type', Classes.FILL)} className={classNames('form-group--account-type', Classes.FILL)}
inline={true} inline={true}
helperText={<ErrorMessage name="account_type_id" />} helperText={<ErrorMessage name="account_type" />}
intent={inputIntent({ error, touched })} intent={inputIntent({ error, touched })}
> >
<AccountsTypesSelect <AccountsTypesSelect
accountsTypes={accountsTypes} accountsTypes={accountsTypes}
selectedTypeId={value} selectedTypeId={value}
defaultSelectText={<T id={'select_account_type'} />} defaultSelectText={<T id={'select_account_type'} />}
onTypeSelected={(account) => { onTypeSelected={(accountType) => {
form.setFieldValue('account_type_id', account.id); form.setFieldValue('account_type', accountType.key);
}} }}
disabled={!isNewMode} disabled={!isNewMode}
popoverProps={{ minimal: true }} popoverProps={{ minimal: true }}