mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
fix: BIG-148 items entries ordered by index.
This commit is contained in:
@@ -23,7 +23,12 @@ import {
|
||||
} from './PaymentMadeForm.schema';
|
||||
import { compose, orderingLinesIndexes } from 'utils';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import { defaultPaymentMade, transformToEditForm, ERRORS } from './utils';
|
||||
import {
|
||||
defaultPaymentMade,
|
||||
transformToEditForm,
|
||||
ERRORS,
|
||||
transformFormToRequest,
|
||||
} from './utils';
|
||||
|
||||
/**
|
||||
* Payment made form component.
|
||||
@@ -71,15 +76,8 @@ function PaymentMadeForm({
|
||||
{ setSubmitting, resetForm, setFieldError },
|
||||
) => {
|
||||
setSubmitting(true);
|
||||
|
||||
// Filters entries that have no `bill_id` or `payment_amount`.
|
||||
const entries = values.entries
|
||||
.filter((item) => item.bill_id && item.payment_amount)
|
||||
.map((entry) => ({
|
||||
...pick(entry, ['payment_amount', 'bill_id']),
|
||||
}));
|
||||
// Total payment amount of entries.
|
||||
const totalPaymentAmount = sumBy(entries, 'payment_amount');
|
||||
const totalPaymentAmount = sumBy(values.entries, 'payment_amount');
|
||||
|
||||
if (totalPaymentAmount <= 0) {
|
||||
AppToaster.show({
|
||||
@@ -88,7 +86,8 @@ function PaymentMadeForm({
|
||||
});
|
||||
return;
|
||||
}
|
||||
const form = { ...values, entries };
|
||||
// Transformes the form values to request body.
|
||||
const form = transformFormToRequest(values);
|
||||
|
||||
// Triggers once the save request success.
|
||||
const onSaved = (response) => {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import moment from 'moment';
|
||||
import { pick } from 'lodash';
|
||||
import {
|
||||
defaultFastFieldShouldUpdate,
|
||||
safeSumBy,
|
||||
transformToForm,
|
||||
orderingLinesIndexes,
|
||||
} from 'utils';
|
||||
|
||||
export const ERRORS = {
|
||||
@@ -57,7 +59,7 @@ export const transformToNewPageEntries = (entries) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines vendors fast field when update.
|
||||
* Detarmines vendors fast field when update.
|
||||
*/
|
||||
export const vendorsFieldShouldUpdate = (newProps, oldProps) => {
|
||||
return (
|
||||
@@ -75,3 +77,17 @@ export const accountsFieldShouldUpdate = (newProps, oldProps) => {
|
||||
defaultFastFieldShouldUpdate(newProps, oldProps)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transformes the form values to request body.
|
||||
*/
|
||||
export const transformFormToRequest = (form) => {
|
||||
// Filters entries that have no `bill_id` or `payment_amount`.
|
||||
const entries = form.entries
|
||||
.filter((item) => item.bill_id && item.payment_amount)
|
||||
.map((entry) => ({
|
||||
...pick(entry, ['payment_amount', 'bill_id']),
|
||||
}));
|
||||
|
||||
return { ...form, entries: orderingLinesIndexes(entries) };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user