fix: BIG-148 items entries ordered by index.

This commit is contained in:
a.bouhuolia
2021-10-31 13:24:12 +02:00
parent cbce9f6d50
commit 9211e963c6
16 changed files with 200 additions and 94 deletions

View File

@@ -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) => {

View File

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