mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix: quick payment received and payment made form initial values
This commit is contained in:
@@ -10,7 +10,7 @@ import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
import QuickPaymentMadeFormContent from './QuickPaymentMadeFormContent';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { defaultPaymentMade, transformErrors } from './utils';
|
||||
import { defaultPaymentMade, transformBillToForm, transformErrors } from './utils';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
@@ -20,29 +20,24 @@ function QuickPaymentMadeForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
bill,
|
||||
dialogName,
|
||||
createPaymentMadeMutate,
|
||||
} = useQuickPaymentMadeContext();
|
||||
const { bill, dialogName, createPaymentMadeMutate } =
|
||||
useQuickPaymentMadeContext();
|
||||
|
||||
// Initial form values.
|
||||
const initialValues = {
|
||||
...defaultPaymentMade,
|
||||
...bill,
|
||||
...transformBillToForm(bill),
|
||||
};
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setFieldError }) => {
|
||||
const entries = [
|
||||
{
|
||||
payment_amount: values.amount,
|
||||
bill_id: values.id,
|
||||
bill_id: values.bill_id,
|
||||
},
|
||||
];
|
||||
const form = {
|
||||
...omit(values, ['payment_amount']),
|
||||
vendor_id: values?.vendor?.id,
|
||||
amount: values?.payment_amount,
|
||||
...omit(values, ['bill_id']),
|
||||
entries,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import { DialogContent } from '@/components';
|
||||
import {
|
||||
useBill,
|
||||
@@ -11,7 +11,6 @@ import { Features } from '@/constants';
|
||||
import { useFeatureCan } from '@/hooks/state';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
|
||||
const QuickPaymentMadeContext = React.createContext();
|
||||
|
||||
/**
|
||||
@@ -40,13 +39,14 @@ function QuickPaymentMadeFormProvider({ query, billId, dialogName, ...props }) {
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||
|
||||
const paymentBill = useMemo(
|
||||
() => pick(bill, ['id', 'due_amount', 'vendor_id', 'currency_code']),
|
||||
[bill],
|
||||
);
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
bill: {
|
||||
...pick(bill, ['id', 'due_amount', 'vendor', 'currency_code']),
|
||||
vendor_id: bill?.vendor?.display_name,
|
||||
payment_amount: bill?.due_amount,
|
||||
},
|
||||
bill: paymentBill,
|
||||
accounts,
|
||||
branches,
|
||||
dialogName,
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { first } from 'lodash';
|
||||
import { first, pick } from 'lodash';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from '@/components';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
import { PAYMENT_MADE_ERRORS } from '@/containers/Purchases/PaymentMades/constants';
|
||||
|
||||
// Default initial values of payment made.
|
||||
export const defaultPaymentMade = {
|
||||
bill_id: '',
|
||||
vendor_id: '',
|
||||
payment_account_id: '',
|
||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
@@ -20,7 +21,6 @@ export const defaultPaymentMade = {
|
||||
// statement: '',
|
||||
exchange_rate: 1,
|
||||
branch_id: '',
|
||||
entries: [{ bill_id: '', payment_amount: '' }],
|
||||
};
|
||||
|
||||
export const transformErrors = (errors, { setFieldError }) => {
|
||||
@@ -59,3 +59,11 @@ export const useSetPrimaryBranchToForm = () => {
|
||||
}
|
||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||
};
|
||||
|
||||
export const transformBillToForm = (bill) => {
|
||||
return {
|
||||
...pick(bill, ['vendor_id', 'currency_code']),
|
||||
amount: bill.due_amount,
|
||||
bill_id: bill.id,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user