mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +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 intl from 'react-intl-universal';
|
||||
import { first, isEqual } from 'lodash';
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
|
||||
@@ -31,6 +32,12 @@ export const transformErrors = (errors, { setFieldError }) => {
|
||||
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 = () => {
|
||||
|
||||
@@ -2,6 +2,8 @@ import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { first } from 'lodash';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { useFormikContext } from 'formik';
|
||||
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
||||
@@ -39,6 +41,12 @@ export const transformErrors = (errors, { setFieldError }) => {
|
||||
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 = () => {
|
||||
|
||||
@@ -27,7 +27,7 @@ import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import {
|
||||
defaultPaymentMade,
|
||||
transformToEditForm,
|
||||
ERRORS,
|
||||
transformErrors,
|
||||
transformFormToRequest,
|
||||
} from './utils';
|
||||
|
||||
@@ -111,14 +111,10 @@ function PaymentMadeForm({
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
||||
|
||||
if (getError(ERRORS.PAYMENT_NUMBER_NOT_UNIQUE)) {
|
||||
setFieldError(
|
||||
'payment_number',
|
||||
intl.get('payment_number_is_not_unique'),
|
||||
);
|
||||
if (errors) {
|
||||
transformErrors(errors, { setFieldError });
|
||||
}
|
||||
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { isEqual, isUndefined } from 'lodash';
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import {
|
||||
useAccounts,
|
||||
useVendors,
|
||||
@@ -18,11 +20,21 @@ const PaymentMadeFormContext = createContext();
|
||||
/**
|
||||
* Payment made form provider.
|
||||
*/
|
||||
function PaymentMadeFormProvider({ paymentMadeId, baseCurrency, ...props }) {
|
||||
function PaymentMadeFormProvider({
|
||||
query,
|
||||
paymentMadeId,
|
||||
baseCurrency,
|
||||
...props
|
||||
}) {
|
||||
const [submitPayload, setSubmitPayload] = React.useState({});
|
||||
const [paymentVendorId, setPaymentVendorId] = React.useState(null);
|
||||
const [selectVendor, setSelectVendor] = React.useState(null);
|
||||
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
|
||||
// Handle fetch accounts data.
|
||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||
|
||||
@@ -53,7 +65,8 @@ function PaymentMadeFormProvider({ paymentMadeId, baseCurrency, ...props }) {
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches();
|
||||
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||
|
||||
|
||||
// Fetch payment made settings.
|
||||
useSettings();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { pick, first } from 'lodash';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import {
|
||||
defaultFastFieldShouldUpdate,
|
||||
@@ -111,3 +114,20 @@ export const useSetPrimaryBranchToForm = () => {
|
||||
}
|
||||
}, [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,
|
||||
transformToEditForm,
|
||||
transformFormToRequest,
|
||||
transformErrors,
|
||||
} from './utils';
|
||||
|
||||
/**
|
||||
@@ -135,19 +136,8 @@ function PaymentReceiveForm({
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
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 (errors) {
|
||||
transformErrors(errors, { setFieldError });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 {
|
||||
useSettingsPaymentReceives,
|
||||
@@ -19,6 +20,7 @@ const PaymentReceiveFormContext = createContext();
|
||||
* Payment receive form provider.
|
||||
*/
|
||||
function PaymentReceiveFormProvider({
|
||||
query,
|
||||
paymentReceiveId,
|
||||
baseCurrency,
|
||||
...props
|
||||
@@ -28,6 +30,10 @@ function PaymentReceiveFormProvider({
|
||||
|
||||
const [selectCustomer, setSelectCustomer] = React.useState(null);
|
||||
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
// Fetches payment recevie details.
|
||||
const {
|
||||
data: {
|
||||
@@ -56,7 +62,7 @@ function PaymentReceiveFormProvider({
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches();
|
||||
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Detarmines whether the new mode.
|
||||
const isNewMode = !paymentReceiveId;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import React from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { omit, pick, first } from 'lodash';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider';
|
||||
import {
|
||||
defaultFastFieldShouldUpdate,
|
||||
@@ -182,3 +185,31 @@ export const useSetPrimaryBranchToForm = () => {
|
||||
}
|
||||
}, [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_has_associated_transactions": "لا يمكنك حذف هذا المخزن لأنه لديه معاملات مرتبطة به. ",
|
||||
"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_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.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