From 6d67d6163ddbb690caf2e36401b4e84c5ba6bc13 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 8 Nov 2021 13:20:49 +0200 Subject: [PATCH] feat: handle error. --- .../NotifyEstimateViaSMSForm.js | 9 +++++++-- .../NotifyInvoiceViaSMSForm.js | 3 ++- .../NotifyPaymentReceiveViaSMSForm.js | 9 +++++++-- .../NotifyReceiptViaSMSForm.js | 9 +++++++-- .../NotifyViaSMS/NotifyViaSMSForm.schema.js | 2 +- src/containers/NotifyViaSMS/utils.js | 12 +++++++++++ src/lang/ar/index.json | 20 ++++++++++++++++++- src/lang/en/index.json | 1 + 8 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/containers/NotifyViaSMS/utils.js diff --git a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js index 851c9fcc1..e4eb9fea4 100644 --- a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js +++ b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js @@ -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) diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js index 0f2ae70fc..f3de4151f 100644 --- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js +++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js @@ -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) diff --git a/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js b/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js index de79deecb..f37ab6c45 100644 --- a/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js +++ b/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js @@ -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) diff --git a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js index c9ae06410..52293ccf5 100644 --- a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js +++ b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js @@ -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) diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSForm.schema.js b/src/containers/NotifyViaSMS/NotifyViaSMSForm.schema.js index 3e855eb49..ff3114609 100644 --- a/src/containers/NotifyViaSMS/NotifyViaSMSForm.schema.js +++ b/src/containers/NotifyViaSMS/NotifyViaSMSForm.schema.js @@ -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), }); diff --git a/src/containers/NotifyViaSMS/utils.js b/src/containers/NotifyViaSMS/utils.js new file mode 100644 index 000000000..5ed16cae1 --- /dev/null +++ b/src/containers/NotifyViaSMS/utils.js @@ -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, + }); + } +}; diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index 945c453cb..4281ccc13 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -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." } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 267d1a00d..87aedd67a 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -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",