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>
);
}

View File

@@ -11,7 +11,7 @@ import {
TextArea,
Position,
} from '@blueprintjs/core';
import { FormattedMessage as T } from '@/components';
import { FFormGroup, FormattedMessage as T } from '@/components';
import { DateInput } from '@blueprintjs/datetime';
import { useAutofocus } from '@/hooks';
import {
@@ -23,7 +23,7 @@ import {
BranchSelect,
WarehouseSelect,
BranchSelectButton,
AccountsSuggestField,
FAccountsSuggestField,
} from '@/components';
import {
inputIntent,
@@ -109,13 +109,11 @@ export default function InventoryAdjustmentFormDialogFields() {
{/*------------ Date -----------*/}
<FastField name={'date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
<FFormGroup
name={'date'}
label={<T id={'date'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="date" />}
minimal={true}
className={classNames(CLASSES.FILL, 'form-group--date')}
fill
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
@@ -130,7 +128,7 @@ export default function InventoryAdjustmentFormDialogFields() {
intent={inputIntent({ error, touched })}
inputRef={(ref) => (dateFieldRef.current = ref)}
/>
</FormGroup>
</FFormGroup>
)}
</FastField>
</Col>
@@ -143,12 +141,11 @@ export default function InventoryAdjustmentFormDialogFields() {
field: { value },
meta: { error, touched },
}) => (
<FormGroup
<FFormGroup
name={'type'}
label={<T id={'adjustment_type'} />}
labelInfo={<FieldRequiredHint />}
helperText={<ErrorMessage name="type" />}
intent={inputIntent({ error, touched })}
className={classNames(CLASSES.FILL, 'form-group--type')}
fill
>
<ListSelect
items={adjustmentTypes}
@@ -168,7 +165,7 @@ export default function InventoryAdjustmentFormDialogFields() {
popoverProps={{ minimal: true }}
intent={inputIntent({ error, touched })}
/>
</FormGroup>
</FFormGroup>
)}
</Field>
</Col>
@@ -177,28 +174,20 @@ export default function InventoryAdjustmentFormDialogFields() {
<InventoryAdjustmentQuantityFields />
{/*------------ Adjustment account -----------*/}
<FastField name={'adjustment_account_id'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'adjustment_account'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="adjustment_account_id" />}
className={'form-group--adjustment-account'}
>
<AccountsSuggestField
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('adjustment_account_id', id)
}
inputProps={{
placeholder: intl.get('select_adjustment_account'),
intent: inputIntent({ error, touched }),
}}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'adjustment_account_id'}
label={<T id={'adjustment_account'} />}
labelInfo={<FieldRequiredHint />}
className={'form-group--adjustment-account'}
>
<FAccountsSuggestField
name={'adjustment_account_id'}
items={accounts}
inputProps={{
placeholder: intl.get('select_adjustment_account'),
}}
/>
</FFormGroup>
{/*------------ Reference -----------*/}
<FastField name={'reference_no'}>

View File

@@ -14,7 +14,7 @@ import {
Col,
Row,
FormattedMessage as T,
AccountsSuggestField,
FAccountsSuggestField,
InputPrependText,
MoneyInputGroup,
Icon,
@@ -137,9 +137,9 @@ function QuickPaymentMadeFormFields({
name={'payment_account_id'}
label={<T id={'payment_account'} />}
>
<AccountsSuggestField
<FAccountsSuggestField
name={'payment_account_id'}
accounts={accounts}
items={accounts}
inputProps={{
placeholder: intl.get('select_account'),
}}

View File

@@ -13,7 +13,7 @@ import {
Col,
FieldRequiredHint,
FormattedMessage as T,
AccountsSuggestField,
FAccountsSuggestField,
InputPrependText,
MoneyInputGroup,
Icon,
@@ -143,9 +143,9 @@ function QuickPaymentReceiveFormFields({
name={'deposit_account_id'}
label={<T id={'deposit_to'} />}
>
<AccountsSuggestField
<FAccountsSuggestField
name={'deposit_account_id'}
accounts={accounts}
items={accounts}
inputProps={{
placeholder: intl.get('select_account'),
}}

View File

@@ -21,7 +21,7 @@ import {
Row,
If,
FieldRequiredHint,
AccountsSuggestField,
FAccountsSuggestField,
InputPrependText,
MoneyInputGroup,
FormattedMessage as T,
@@ -29,6 +29,8 @@ import {
BranchSelect,
BranchSelectButton,
FeatureCan,
FInputGroup,
FMoneyInputGroup,
} from '@/components';
import {
inputIntent,
@@ -85,13 +87,11 @@ function RefundCreditNoteFormFields({
{/* ------------- Refund date ------------- */}
<FastField name={'date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
<FFormGroup
name={'date'}
label={<T id={'refund_credit_note.dialog.refund_date'} />}
labelInfo={<FieldRequiredHint />}
className={classNames('form-group--select-list', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="date" />}
// inline={true}
fill
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
@@ -104,77 +104,53 @@ function RefundCreditNoteFormFields({
leftIcon: <Icon icon={'date-range'} />,
}}
/>
</FormGroup>
</FFormGroup>
)}
</FastField>
</Col>
<Col xs={5}>
{/* ------------ Form account ------------ */}
<FastField name={'from_account_id'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'refund_credit_note.dialog.from_account'} />}
className={classNames(
'form-group--from_account_id',
'form-group--select-list',
CLASSES.FILL,
)}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name={'from_account_id'} />}
>
<AccountsSuggestField
selectedAccountId={value}
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('from_account_id', id)
}
inputProps={{
placeholder: intl.get('select_account'),
}}
filterByTypes={[
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.FIXED_ASSET,
]}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'from_account_id'}
label={<T id={'refund_credit_note.dialog.from_account'} />}
labelInfo={<FieldRequiredHint />}
fill
>
<FAccountsSuggestField
name={'from_account_id'}
items={accounts}
inputProps={{
placeholder: intl.get('select_account'),
}}
filterByTypes={[
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.FIXED_ASSET,
]}
/>
</FFormGroup>
</Col>
</Row>
{/* ------------- Amount ------------- */}
<FastField name={'amount'}>
{({
form: { values, setFieldValue },
field: { value },
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'refund_credit_note.dialog.amount'} />}
labelInfo={<FieldRequiredHint />}
className={classNames('form-group--amount', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="amount" />}
>
<ControlGroup>
<InputPrependText text={values.currency_code} />
<MoneyInputGroup
value={value}
minimal={true}
onChange={(amount) => {
setFieldValue('amount', amount);
}}
intent={inputIntent({ error, touched })}
inputRef={(ref) => (amountFieldRef.current = ref)}
/>
</ControlGroup>
</FormGroup>
)}
</FastField>
{/* ------------- Amount ------------- */}
<FFormGroup
name={'amount'}
label={<T id={'refund_credit_note.dialog.amount'} />}
labelInfo={<FieldRequiredHint />}
fill
>
<ControlGroup>
<InputPrependText text={values.currency_code} />
<FMoneyInputGroup
name={'amount'}
minimal={true}
inputRef={(ref) => (amountFieldRef.current = ref)}
/>
</ControlGroup>
</FFormGroup>
{/*------------ exchange rate -----------*/}
<If condition={!isEqual(base_currency, values.currency_code)}>
{/*------------ exchange rate -----------*/}
<ExchangeRateMutedField
name={'exchange_rate'}
fromCurrency={base_currency}
@@ -186,22 +162,9 @@ function RefundCreditNoteFormFields({
</If>
{/* ------------ Reference No. ------------ */}
<FastField name={'reference_no'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reference_no'} />}
className={classNames('form-group--reference', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="reference" />}
>
<InputGroup
intent={inputIntent({ error, touched })}
minimal={true}
{...field}
/>
</FormGroup>
)}
</FastField>
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />} fill>
<FInputGroup name={'reference_no'} minimal fill />
</FFormGroup>
{/* --------- Statement --------- */}
<FastField name={'description'}>

View File

@@ -21,7 +21,7 @@ import {
Row,
If,
FieldRequiredHint,
AccountsSuggestField,
FAccountsSuggestField,
InputPrependText,
MoneyInputGroup,
FormattedMessage as T,
@@ -83,12 +83,11 @@ function RefundVendorCreditFormFields({
{/* ------------- Refund date ------------- */}
<FastField name={'refund_date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
<FFormGroup
name={'refund_date'}
label={<T id={'refund_vendor_credit.dialog.refund_date'} />}
labelInfo={<FieldRequiredHint />}
className={classNames('form-group--select-list', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="refund_date" />}
fill
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
@@ -101,46 +100,32 @@ function RefundVendorCreditFormFields({
leftIcon: <Icon icon={'date-range'} />,
}}
/>
</FormGroup>
</FFormGroup>
)}
</FastField>
</Col>
<Col xs={5}>
{/* ------------ Form account ------------ */}
<FastField name={'deposit_account_id'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={
<T id={'refund_vendor_credit.dialog.deposit_to_account'} />
}
className={classNames(
'form-group--deposit_account_id',
'form-group--select-list',
CLASSES.FILL,
)}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name={'deposit_account_id'} />}
>
<AccountsSuggestField
selectedAccountId={value}
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('deposit_account_id', id)
}
inputProps={{
placeholder: intl.get('select_account'),
}}
filterByTypes={[
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.FIXED_ASSET,
]}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'deposit_account_id'}
label={<T id={'refund_vendor_credit.dialog.deposit_to_account'} />}
labelInfo={<FieldRequiredHint />}
fill
>
<FAccountsSuggestField
name={'deposit_account_id'}
items={accounts}
inputProps={{
placeholder: intl.get('select_account'),
}}
filterByTypes={[
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.FIXED_ASSET,
]}
/>
</FFormGroup>
</Col>
</Row>