// @ts-nocheck import React, { useMemo } from 'react'; import classNames from 'classnames'; import styled from 'styled-components'; import { FormGroup, InputGroup, Position, Classes, ControlGroup, Button, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { isEmpty, toSafeInteger } from 'lodash'; import { FastField, useFormikContext, ErrorMessage } from 'formik'; import { FeatureCan, CustomersSelect, FormattedMessage as T, FMoneyInputGroup, } from '@/components'; import { CLASSES } from '@/constants/classes'; import { safeSumBy, momentFormatter, tansformDateValue, handleDateChange, inputIntent, } from '@/utils'; import { FFormGroup, AccountsSelect, FieldRequiredHint, Icon, InputPrependText, CustomerDrawerLink, Hint, Money, } from '@/components'; import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider'; import { ACCOUNT_TYPE } from '@/constants/accountTypes'; import { ProjectsSelect } from '@/containers/Projects/components'; import { PaymentReceiveExchangeRateInputField, PaymentReceiveProjectSelectButton, } from './components'; import { amountPaymentEntries, fullAmountPaymentEntries, customersFieldShouldUpdate, accountsFieldShouldUpdate, } from './utils'; import { Features } from '@/constants'; import { PaymentReceivePaymentNoField } from './PaymentReceivePaymentNoField'; /** * Payment receive header fields. */ export default function PaymentReceiveHeaderFields() { // Payment receive form context. const { accounts, projects } = usePaymentReceiveFormContext(); // Formik form context. const { values: { entries, currency_code }, setFieldValue, } = useFormikContext(); // Calculates the full-amount received. const totalDueAmount = useMemo( () => safeSumBy(entries, 'due_amount'), [entries], ); // Handle receive full-amount link click. const handleReceiveFullAmountClick = () => { const newEntries = fullAmountPaymentEntries(entries); const fullAmount = safeSumBy(newEntries, 'payment_amount'); setFieldValue('entries', newEntries); setFieldValue('amount', fullAmount); }; // Handles the full-amount field blur. const onFullAmountBlur = (value) => { const newEntries = amountPaymentEntries(toSafeInteger(value), entries); setFieldValue('entries', newEntries); }; return (