From adc6b336e0df3a8aa2808ccc3f4de5be0d22775a Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 8 Nov 2021 14:54:11 +0200 Subject: [PATCH] fix: handle error. --- .../NotifyEstimateViaSMSForm.js | 7 +++++-- .../NotifyInvoiceViaSMSForm.js | 5 ++++- .../NotifyPaymentReceiveViaSMSForm.js | 5 ++++- .../NotifyReceiptViaSMSForm.js | 5 ++++- src/containers/NotifyViaSMS/utils.js | 10 +++++++++- src/lang/ar/index.json | 2 ++ src/lang/en/index.json | 3 ++- 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js index e4eb9fea4..6613bcd37 100644 --- a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js +++ b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js @@ -39,11 +39,14 @@ function NotifyEstimateViaSMSForm({ data: { errors }, }, }) => { - transformErrors(errors); + if (errors) { + transformErrors(errors, { setErrors }); + } + setSubmitting(false); }; createNotifyEstimateBySMSMutate([estimateId, values]) .then(onSuccess) - .then(onError); + .catch(onError); }; return ( diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js index f3de4151f..96b684f82 100644 --- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js +++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js @@ -42,7 +42,10 @@ function NotifyInvoiceViaSMSForm({ data: { errors }, }, }) => { - transformErrors(errors); + if (errors) { + transformErrors(errors, { setErrors }); + } + setSubmitting(false); }; createNotifyInvoiceBySMSMutate([invoiceId, values]) .then(onSuccess) diff --git a/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js b/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js index f37ab6c45..997890d8b 100644 --- a/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js +++ b/src/containers/Dialogs/NotifyPaymentReceiveViaSMSDialog/NotifyPaymentReceiveViaSMSForm.js @@ -44,7 +44,10 @@ function NotifyPaymentReceiveViaSMSForm({ data: { errors }, }, }) => { - transformErrors(errors); + if (errors) { + transformErrors(errors, { setErrors }); + } + setSubmitting(false); }; createNotifyPaymentReceivetBySMSMutate([paymentReceiveId, values]) .then(onSuccess) diff --git a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js index 52293ccf5..b778f97d4 100644 --- a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js +++ b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js @@ -42,7 +42,10 @@ function NotifyReceiptViaSMSForm({ data: { errors }, }, }) => { - transformErrors(errors); + if (errors) { + transformErrors(errors, { setErrors }); + } + setSubmitting(false); }; createNotifyReceiptBySMSMutate([receiptId, values]) .then(onSuccess) diff --git a/src/containers/NotifyViaSMS/utils.js b/src/containers/NotifyViaSMS/utils.js index 5ed16cae1..e000b7f13 100644 --- a/src/containers/NotifyViaSMS/utils.js +++ b/src/containers/NotifyViaSMS/utils.js @@ -2,11 +2,19 @@ import { Intent } from '@blueprintjs/core'; import { AppToaster } from 'components'; import intl from 'react-intl-universal'; -export const transformErrors = (errors) => { +export const transformErrors = (errors, { setErrors }) => { 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, }); } + + if (errors.find((error) => error.type === 'CUSTOMER_HAS_NO_PHONE_NUMBER')) { + setErrors({ + customer_phone_number: intl.get( + 'notify_via_sms.dialog.customer_no_phone_error_message', + ), + }); + } }; diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index 4281ccc13..9edc01ec9 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1444,6 +1444,8 @@ "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_via_sms.dialog.phone_invalid_error_message":"Sms notification cannot be sent, customer personal phone number is invalid, please enter a valid one and try again.", + "notify_via_sms.dialog.customer_no_phone_error_message":"الزبون ليس لديه رقم هاتف.", "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", diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 87aedd67a..1c791975b 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1430,7 +1430,8 @@ "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_via_sms.dialog.phone_invalid_error_message":"Sms notification cannot be sent, customer personal phone number is invalid, please enter a valid one and try again.", + "notify_via_sms.dialog.customer_no_phone_error_message":"The customer has no phone number.", "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",