mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
feat(payment receive & made): handle error.
This commit is contained in:
@@ -2,7 +2,8 @@ import React from 'react';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { first, isEqual } from 'lodash';
|
import { first, isEqual } from 'lodash';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||||
|
|
||||||
@@ -31,6 +32,12 @@ export const transformErrors = (errors, { setFieldError }) => {
|
|||||||
intl.get('the_payment_amount_bigger_than_invoice_due_amount'),
|
intl.get('the_payment_amount_bigger_than_invoice_due_amount'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (getError('WITHDRAWAL_ACCOUNT_CURRENCY_INVALID')) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('payment_made.error.withdrawal_account_currency_invalid'),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSetPrimaryBranchToForm = () => {
|
export const useSetPrimaryBranchToForm = () => {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import React from 'react';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { first } from 'lodash';
|
import { first } from 'lodash';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
||||||
@@ -39,6 +41,12 @@ export const transformErrors = (errors, { setFieldError }) => {
|
|||||||
intl.get('the_payment_amount_bigger_than_invoice_due_amount'),
|
intl.get('the_payment_amount_bigger_than_invoice_due_amount'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (getError('PAYMENT_ACCOUNT_CURRENCY_INVALID')) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('payment_Receive.error.payment_account_currency_invalid'),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSetPrimaryBranchToForm = () => {
|
export const useSetPrimaryBranchToForm = () => {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
|||||||
import {
|
import {
|
||||||
defaultPaymentMade,
|
defaultPaymentMade,
|
||||||
transformToEditForm,
|
transformToEditForm,
|
||||||
ERRORS,
|
transformErrors,
|
||||||
transformFormToRequest,
|
transformFormToRequest,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
@@ -111,14 +111,10 @@ function PaymentMadeForm({
|
|||||||
data: { errors },
|
data: { errors },
|
||||||
},
|
},
|
||||||
}) => {
|
}) => {
|
||||||
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
if (errors) {
|
||||||
|
transformErrors(errors, { setFieldError });
|
||||||
if (getError(ERRORS.PAYMENT_NUMBER_NOT_UNIQUE)) {
|
|
||||||
setFieldError(
|
|
||||||
'payment_number',
|
|
||||||
intl.get('payment_number_is_not_unique'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
import { isEqual, isUndefined } from 'lodash';
|
import { isEqual, isUndefined } from 'lodash';
|
||||||
|
import { Features } from 'common';
|
||||||
|
import { useFeatureCan } from 'hooks/state';
|
||||||
import {
|
import {
|
||||||
useAccounts,
|
useAccounts,
|
||||||
useVendors,
|
useVendors,
|
||||||
@@ -18,11 +20,21 @@ const PaymentMadeFormContext = createContext();
|
|||||||
/**
|
/**
|
||||||
* Payment made form provider.
|
* Payment made form provider.
|
||||||
*/
|
*/
|
||||||
function PaymentMadeFormProvider({ paymentMadeId, baseCurrency, ...props }) {
|
function PaymentMadeFormProvider({
|
||||||
|
query,
|
||||||
|
paymentMadeId,
|
||||||
|
baseCurrency,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
const [submitPayload, setSubmitPayload] = React.useState({});
|
const [submitPayload, setSubmitPayload] = React.useState({});
|
||||||
const [paymentVendorId, setPaymentVendorId] = React.useState(null);
|
const [paymentVendorId, setPaymentVendorId] = React.useState(null);
|
||||||
const [selectVendor, setSelectVendor] = React.useState(null);
|
const [selectVendor, setSelectVendor] = React.useState(null);
|
||||||
|
|
||||||
|
// Features guard.
|
||||||
|
const { featureCan } = useFeatureCan();
|
||||||
|
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
|
|
||||||
// Handle fetch accounts data.
|
// Handle fetch accounts data.
|
||||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||||
|
|
||||||
@@ -53,7 +65,8 @@ function PaymentMadeFormProvider({ paymentMadeId, baseCurrency, ...props }) {
|
|||||||
data: branches,
|
data: branches,
|
||||||
isLoading: isBranchesLoading,
|
isLoading: isBranchesLoading,
|
||||||
isSuccess: isBranchesSuccess,
|
isSuccess: isBranchesSuccess,
|
||||||
} = useBranches();
|
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||||
|
|
||||||
|
|
||||||
// Fetch payment made settings.
|
// Fetch payment made settings.
|
||||||
useSettings();
|
useSettings();
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
import { pick, first } from 'lodash';
|
import { pick, first } from 'lodash';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||||
import {
|
import {
|
||||||
defaultFastFieldShouldUpdate,
|
defaultFastFieldShouldUpdate,
|
||||||
@@ -111,3 +114,20 @@ export const useSetPrimaryBranchToForm = () => {
|
|||||||
}
|
}
|
||||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the response errors types.
|
||||||
|
*/
|
||||||
|
export const transformErrors = (errors, { setFieldError }) => {
|
||||||
|
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
||||||
|
|
||||||
|
if (getError('PAYMENT_NUMBER_NOT_UNIQUE')) {
|
||||||
|
setFieldError('payment_number', intl.get('payment_number_is_not_unique'));
|
||||||
|
}
|
||||||
|
if (getError('WITHDRAWAL_ACCOUNT_CURRENCY_INVALID')) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('payment_made.error.withdrawal_account_currency_invalid'),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import {
|
|||||||
defaultPaymentReceive,
|
defaultPaymentReceive,
|
||||||
transformToEditForm,
|
transformToEditForm,
|
||||||
transformFormToRequest,
|
transformFormToRequest,
|
||||||
|
transformErrors,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,19 +136,8 @@ function PaymentReceiveForm({
|
|||||||
data: { errors },
|
data: { errors },
|
||||||
},
|
},
|
||||||
}) => {
|
}) => {
|
||||||
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
if (errors) {
|
||||||
|
transformErrors(errors, { setFieldError });
|
||||||
if (getError('PAYMENT_RECEIVE_NO_EXISTS')) {
|
|
||||||
setFieldError(
|
|
||||||
'payment_receive_no',
|
|
||||||
intl.get('payment_number_is_not_unique'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (getError('PAYMENT_RECEIVE_NO_REQUIRED')) {
|
|
||||||
setFieldError(
|
|
||||||
'payment_receive_no',
|
|
||||||
intl.get('payment_receive.field.error.payment_receive_no_required'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
|
import {isEqual, isUndefined } from 'lodash';
|
||||||
|
import { Features } from 'common';
|
||||||
|
import { useFeatureCan } from 'hooks/state';
|
||||||
import { DashboardInsider } from 'components';
|
import { DashboardInsider } from 'components';
|
||||||
import {
|
import {
|
||||||
useSettingsPaymentReceives,
|
useSettingsPaymentReceives,
|
||||||
@@ -19,6 +20,7 @@ const PaymentReceiveFormContext = createContext();
|
|||||||
* Payment receive form provider.
|
* Payment receive form provider.
|
||||||
*/
|
*/
|
||||||
function PaymentReceiveFormProvider({
|
function PaymentReceiveFormProvider({
|
||||||
|
query,
|
||||||
paymentReceiveId,
|
paymentReceiveId,
|
||||||
baseCurrency,
|
baseCurrency,
|
||||||
...props
|
...props
|
||||||
@@ -28,6 +30,10 @@ function PaymentReceiveFormProvider({
|
|||||||
|
|
||||||
const [selectCustomer, setSelectCustomer] = React.useState(null);
|
const [selectCustomer, setSelectCustomer] = React.useState(null);
|
||||||
|
|
||||||
|
// Features guard.
|
||||||
|
const { featureCan } = useFeatureCan();
|
||||||
|
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
// Fetches payment recevie details.
|
// Fetches payment recevie details.
|
||||||
const {
|
const {
|
||||||
data: {
|
data: {
|
||||||
@@ -56,7 +62,7 @@ function PaymentReceiveFormProvider({
|
|||||||
data: branches,
|
data: branches,
|
||||||
isLoading: isBranchesLoading,
|
isLoading: isBranchesLoading,
|
||||||
isSuccess: isBranchesSuccess,
|
isSuccess: isBranchesSuccess,
|
||||||
} = useBranches();
|
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||||
|
|
||||||
// Detarmines whether the new mode.
|
// Detarmines whether the new mode.
|
||||||
const isNewMode = !paymentReceiveId;
|
const isNewMode = !paymentReceiveId;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useFormikContext } from 'formik';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
import { omit, pick, first } from 'lodash';
|
import { omit, pick, first } from 'lodash';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import { AppToaster } from 'components';
|
||||||
import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider';
|
import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider';
|
||||||
import {
|
import {
|
||||||
defaultFastFieldShouldUpdate,
|
defaultFastFieldShouldUpdate,
|
||||||
@@ -182,3 +185,31 @@ export const useSetPrimaryBranchToForm = () => {
|
|||||||
}
|
}
|
||||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the response errors types.
|
||||||
|
*/
|
||||||
|
export const transformErrors = (errors, { setFieldError }) => {
|
||||||
|
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
||||||
|
|
||||||
|
if (getError('PAYMENT_RECEIVE_NO_EXISTS')) {
|
||||||
|
setFieldError(
|
||||||
|
'payment_receive_no',
|
||||||
|
intl.get('payment_number_is_not_unique'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (getError('PAYMENT_RECEIVE_NO_REQUIRED')) {
|
||||||
|
setFieldError(
|
||||||
|
'payment_receive_no',
|
||||||
|
intl.get('payment_receive.field.error.payment_receive_no_required'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (getError('PAYMENT_ACCOUNT_CURRENCY_INVALID')) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get(
|
||||||
|
'payment_Receive.error.payment_account_currency_invalid',
|
||||||
|
),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1914,5 +1914,7 @@
|
|||||||
"warehouse.error.warehouse_code_not_unique": "رمز المخزن ليس فريدًا ",
|
"warehouse.error.warehouse_code_not_unique": "رمز المخزن ليس فريدًا ",
|
||||||
"warehouse.error.warehouse_has_associated_transactions": "لا يمكنك حذف هذا المخزن لأنه لديه معاملات مرتبطة به. ",
|
"warehouse.error.warehouse_has_associated_transactions": "لا يمكنك حذف هذا المخزن لأنه لديه معاملات مرتبطة به. ",
|
||||||
"branche.error.warehouse_code_not_unique": "رمز الفرع ليس فريدًا ",
|
"branche.error.warehouse_code_not_unique": "رمز الفرع ليس فريدًا ",
|
||||||
"branche.error.branch_has_associated_transactions": "لا يمكنك حذف هذا الفرع لأنه لديه معاملات مرتبطة به."
|
"branche.error.branch_has_associated_transactions": "لا يمكنك حذف هذا الفرع لأنه لديه معاملات مرتبطة به.",
|
||||||
|
"payment_Receive.error.payment_account_currency_invalid":"يجب أن تكون عملة حساب الإيداع هي نفس عملة العميل أو العملة الأساسية للمنشأة.",
|
||||||
|
"payment_made.error.withdrawal_account_currency_invalid":"يجب أن تكون عملة حساب السحب هي نفس عملة المورد أو العملة الأساسية للمنشأة."
|
||||||
}
|
}
|
||||||
@@ -1909,5 +1909,7 @@
|
|||||||
"warehouse.error.warehouse_code_not_unique": "Warehouse code not unique",
|
"warehouse.error.warehouse_code_not_unique": "Warehouse code not unique",
|
||||||
"warehouse.error.warehouse_has_associated_transactions": "You could not delete the warehouse that has associated transactions.",
|
"warehouse.error.warehouse_has_associated_transactions": "You could not delete the warehouse that has associated transactions.",
|
||||||
"branche.error.warehouse_code_not_unique": "Branch code not unique",
|
"branche.error.warehouse_code_not_unique": "Branch code not unique",
|
||||||
"branche.error.branch_has_associated_transactions": "You could not delete the branch that has associated transactions."
|
"branche.error.branch_has_associated_transactions": "You could not delete the branch that has associated transactions.",
|
||||||
|
"payment_Receive.error.payment_account_currency_invalid":"The deposit account currency should be same customer currency or organization base currency.",
|
||||||
|
"payment_made.error.withdrawal_account_currency_invalid":"The withdrawal account currency should be same vendor currency or organization base currency."
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user