fix: accounts suggest field

This commit is contained in:
Ahmed Bouhuolia
2025-12-21 16:03:15 +02:00
parent b22328cff9
commit 31f5cbf335
22 changed files with 1189 additions and 2224 deletions

View File

@@ -1,7 +1,11 @@
// @ts-nocheck
import React from 'react';
import { FastField, ErrorMessage } from 'formik';
import { FormattedMessage as T } from '@/components';
import {
FMoneyInputGroup,
FTextArea,
FormattedMessage as T,
} from '@/components';
import { useAutofocus } from '@/hooks';
import {
@@ -17,7 +21,7 @@ import { CLASSES } from '@/constants/classes';
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
import { inputIntent } from '@/utils';
import {
AccountsSuggestField,
FAccountsSuggestField,
InputPrependText,
MoneyInputGroup,
FieldRequiredHint,
@@ -31,7 +35,7 @@ import { useBadDebtContext } from './BadDebtFormProvider';
function BadDebtFormFields() {
const amountfieldRef = useAutofocus();
const { accounts ,invoice } = useBadDebtContext();
const { accounts, invoice } = useBadDebtContext();
return (
<div className={Classes.DIALOG_BODY}>
@@ -42,79 +46,45 @@ function BadDebtFormFields() {
</Callout>
{/*------------ Written-off amount -----------*/}
<FastField name={'amount'}>
{({
form: { values, setFieldValue },
field: { value },
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'bad_debt.dialog.written_off_amount'} />}
labelInfo={<FieldRequiredHint />}
className={classNames('form-group--amount', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="amount" />}
>
<ControlGroup>
<InputPrependText text={invoice.currency_code} />
<FFormGroup
name={'amount'}
label={<T id={'bad_debt.dialog.written_off_amount'} />}
labelInfo={<FieldRequiredHint />}
fill
>
<ControlGroup>
<InputPrependText text={invoice.currency_code} />
<FMoneyInputGroup
name={'amount'}
minimal={true}
inputRef={(ref) => (amountfieldRef.current = ref)}
/>
</ControlGroup>
</FFormGroup>
<MoneyInputGroup
value={value}
minimal={true}
onChange={(amount) => {
setFieldValue('amount', amount);
}}
intent={inputIntent({ error, touched })}
disabled={amountfieldRef}
/>
</ControlGroup>
</FormGroup>
)}
</FastField>
{/*------------ Expense account -----------*/}
<FastField name={'expense_account_id'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'expense_account_id'} />}
className={classNames(
'form-group--expense_account_id',
'form-group--select-list',
CLASSES.FILL,
)}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name={'expense_account_id'} />}
>
<AccountsSuggestField
selectedAccountId={value}
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('expense_account_id', id)
}
filterByTypes={[ACCOUNT_TYPE.EXPENSE]}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'expense_account_id'}
label={<T id={'expense_account_id'} />}
labelInfo={<FieldRequiredHint />}
fill
>
<FAccountsSuggestField
name={'expense_account_id'}
items={accounts}
filterByTypes={[ACCOUNT_TYPE.EXPENSE]}
/>
</FFormGroup>
{/*------------ reason -----------*/}
<FastField name={'reason'}>
{({ field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reason'} />}
labelInfo={<FieldRequiredHint />}
className={'form-group--reason'}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name={'reason'} />}
>
<TextArea
growVertically={true}
large={true}
intent={inputIntent({ error, touched })}
{...field}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'reason'}
label={<T id={'reason'} />}
labelInfo={<FieldRequiredHint />}
fill
>
<FTextArea name={'reason'} growVertically={true} large={true} fill />
</FFormGroup>
</div>
);
}