feat: handle error.

This commit is contained in:
elforjani13
2021-11-08 13:20:49 +02:00
parent 4d89f1e0e0
commit 6d67d6163d
8 changed files with 56 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import NotifyViaSMSForm from '../../NotifyViaSMS/NotifyViaSMSForm';
import { useEstimateViaSMSContext } from './NotifyEstimateViaSMSFormProvider';
import { transformErrors } from '../../../containers/NotifyViaSMS/utils';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
@@ -33,8 +34,12 @@ function NotifyEstimateViaSMSForm({
};
// Handle request response errors.
const onError = () => {
setSubmitting(false);
const onError = ({
response: {
data: { errors },
},
}) => {
transformErrors(errors);
};
createNotifyEstimateBySMSMutate([estimateId, values])
.then(onSuccess)

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import NotifyViaSMSForm from '../../NotifyViaSMS/NotifyViaSMSForm';
import { useNotifyInvoiceViaSMSContext } from './NotifyInvoiceViaSMSFormProvider';
import { transformErrors } from '../../../containers/NotifyViaSMS/utils';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
@@ -41,7 +42,7 @@ function NotifyInvoiceViaSMSForm({
data: { errors },
},
}) => {
setSubmitting(false);
transformErrors(errors);
};
createNotifyInvoiceBySMSMutate([invoiceId, values])
.then(onSuccess)

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import NotifyViaSMSForm from '../../NotifyViaSMS/NotifyViaSMSForm';
import { useNotifyPaymentReceiveViaSMSContext } from './NotifyPaymentReceiveViaFormProvider';
import { transformErrors } from '../../../containers/NotifyViaSMS/utils';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
@@ -38,8 +39,12 @@ function NotifyPaymentReceiveViaSMSForm({
};
// Handle request response errors.
const onError = ({}) => {
setSubmitting(false);
const onError = ({
response: {
data: { errors },
},
}) => {
transformErrors(errors);
};
createNotifyPaymentReceivetBySMSMutate([paymentReceiveId, values])
.then(onSuccess)

View File

@@ -6,6 +6,7 @@ import { AppToaster } from 'components';
import NotifyViaSMSForm from '../../NotifyViaSMS/NotifyViaSMSForm';
import { useNotifyReceiptViaSMSContext } from './NotifyReceiptViaSMSFormProvider';
import { transformErrors } from '../../../containers/NotifyViaSMS/utils';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
@@ -36,8 +37,12 @@ function NotifyReceiptViaSMSForm({
};
// Handle request response errors.
const onError = ({}) => {
setSubmitting(false);
const onError = ({
response: {
data: { errors },
},
}) => {
transformErrors(errors);
};
createNotifyReceiptBySMSMutate([receiptId, values])
.then(onSuccess)

View File

@@ -4,7 +4,7 @@ import { DATATYPES_LENGTH } from 'common/dataTypes';
const Schema = Yup.object().shape({
customer_name: Yup.string().required(),
customer_phone_number: Yup.number().required(),
customer_phone_number: Yup.number(),
sms_message: Yup.string().required().trim().max(DATATYPES_LENGTH.TEXT),
});

View File

@@ -0,0 +1,12 @@
import { Intent } from '@blueprintjs/core';
import { AppToaster } from 'components';
import intl from 'react-intl-universal';
export const transformErrors = (errors) => {
if (errors.some((e) => e.type === 'CUSTOMER_SMS_NOTIFY_PHONE_INVALID')) {
AppToaster.show({
message: intl.get('notify_via_sms.dialog.error_message'),
intent: Intent.DANGER,
});
}
};

View File

@@ -1439,5 +1439,23 @@
"bad_debt.dialog.header_note": "يمكن للبائع تحميل مبلغ الفاتورة على حساب مصروفات الديون المعدومة عندما يكون من المؤكد أن الفاتورة لن يتم دفعها.",
"bad_debt.dialog.success_message":"تم شطب فاتورة البيع المقدمة بنجاح.",
"bad_debt.cancel_alert.success_message":"تم إلغاء شطب فاتورة البيع المقدمة بنجاح.",
"bad_debt.cancel_alert.message": "هل أنت متأكد أنك تريد شطب هذه الفاتورة؟ "
"bad_debt.cancel_alert.message": "هل أنت متأكد أنك تريد شطب هذه الفاتورة؟ ",
"notify_via_sms.dialog.send_notification_to":"إرسال إشعار إلى ",
"notify_via_sms.dialog.message_text":"نص رسالة ",
"notify_via_sms.dialog.notify_via_sms":"Notify vis SMS",
"notify_via_sms.dialog.error_message":"Notify vis SMS",
"notify_invoice_via_sms.dialog.success_message":"The sale invoice sms notification has been sent successfully",
"notify_estimate_via_sms.dialog.success_message":"تم إرسال إشعار الرسائل القصيرة الخاصة بتقدير المبيعات بنجاح. ",
"notify_receipt_via_sms.dialog.success_message":"The sale receipt sms notification has been sent successfully",
"notify_payment_receive_via_sms.dialog.success_message":"تم إرسال إشعار الدفع بنجاح. ",
"send": "إرسال",
"sms_integration.label":"SMS Integration",
"sms_integration.label.overview":"نظرة عامة",
"sms_integration.label.sms_messages":"رسائل SMS ",
"sms_message.label.sms_messages_template":" إشعارات رسائل قصيرة ",
"sms_message.label_mesage":"رسالة ",
"sms_message.label_Notification":"إشعار",
"sms_message.label_auto":"Auto",
"sms_message":"رسالة SMS" ,
"sms_message.dialog.success_message":"Sms notification settings has been updated successfully."
}

View File

@@ -1430,6 +1430,7 @@
"notify_via_sms.dialog.send_notification_to":"Send notification to",
"notify_via_sms.dialog.message_text":"Message Text",
"notify_via_sms.dialog.notify_via_sms":"Notify vis SMS",
"notify_via_sms.dialog.error_message":"Sms notification cannot be sent, customer personal phone number is invalid, please enter a valid one and try again.",
"notify_invoice_via_sms.dialog.success_message":"The sale invoice sms notification has been sent successfully",
"notify_estimate_via_sms.dialog.success_message":"The sale estimate sms notification has been sent successfully",
"notify_receipt_via_sms.dialog.success_message":"The sale receipt sms notification has been sent successfully",