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 1/5] 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", From 92d8096f3a882097a20f330ed54062f30b34f92f Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 8 Nov 2021 15:00:44 +0200 Subject: [PATCH 2/5] feat: add Invalidate queries. --- src/hooks/query/customers.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hooks/query/customers.js b/src/hooks/query/customers.js index 3e397972a..75a6d6d3b 100644 --- a/src/hooks/query/customers.js +++ b/src/hooks/query/customers.js @@ -20,6 +20,12 @@ const commonInvalidateQueries = (queryClient) => { // Invalidate the financial reports. queryClient.invalidateQueries(t.FINANCIAL_REPORT); + + // Invalidate SMS details. + queryClient.invalidateQueries(t.SALE_ESTIMATE_SMS_DETAIL); + queryClient.invalidateQueries(t.SALE_INVOICE_SMS_DETAIL); + queryClient.invalidateQueries(t.SALE_RECEIPT_SMS_DETAIL); + queryClient.invalidateQueries(t.PAYMENT_RECEIVE_SMS_DETAIL); }; // Customers response selector. From 5b09d8279e6a44898a1a8b17e9feb288bda49a9c Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 8 Nov 2021 15:13:41 +0200 Subject: [PATCH 3/5] feat: handle error sms messgae dialog. --- .../Dialogs/SMSMessageDialog/SMSMessageForm.js | 4 ++++ src/containers/Dialogs/SMSMessageDialog/utils.js | 15 +++++++++++++++ src/lang/en/index.json | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/containers/Dialogs/SMSMessageDialog/utils.js diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js index 3a98f36a6..19924f2c8 100644 --- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js +++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js @@ -9,6 +9,7 @@ import { AppToaster } from 'components'; import SMSMessageFormContent from './SMSMessageFormContent'; import { CreateSMSMessageFormSchema } from './SMSMessageForm.schema'; import { useSMSMessageDialogContext } from './SMSMessageDialogProvider'; +import { transformErrors } from './utils'; import withDialogActions from 'containers/Dialog/withDialogActions'; @@ -60,6 +61,9 @@ function SMSMessageForm({ data: { errors }, }, }) => { + if (errors) { + transformErrors(errors, { setErrors }); + } setSubmitting(false); }; diff --git a/src/containers/Dialogs/SMSMessageDialog/utils.js b/src/containers/Dialogs/SMSMessageDialog/utils.js new file mode 100644 index 000000000..b4f46f1f7 --- /dev/null +++ b/src/containers/Dialogs/SMSMessageDialog/utils.js @@ -0,0 +1,15 @@ +import { Intent } from '@blueprintjs/core'; +import { AppToaster } from 'components'; +import intl from 'react-intl-universal'; + +export const transformErrors = (errors, { setErrors }) => { + if ( + errors.find((error) => error.type === 'UNSUPPORTED_SMS_MESSAGE_VARIABLES') + ) { + setErrors({ + message_text: intl.get( + 'sms_message.dialog.unsupported_variables_error_message', + ), + }); + } +}; diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 1c791975b..6fec2ea85 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1445,6 +1445,7 @@ "sms_message.label_Notification":"Notification", "sms_message.label_auto":"Auto", "sms_message":"SMS message", - "sms_message.dialog.success_message":"Sms notification settings has been updated successfully." + "sms_message.dialog.success_message":"Sms notification settings has been updated successfully.", + "sms_message.dialog.unsupported_variables_error_message":"Unsupported variables" } From 8c2d138976e35f4ebaf0a29336972c9408462b1d Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 8 Nov 2021 16:10:54 +0200 Subject: [PATCH 4/5] fix: disable sort in SMS integration table. --- src/containers/Preferences/SMSIntegration/components.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/containers/Preferences/SMSIntegration/components.js b/src/containers/Preferences/SMSIntegration/components.js index 841e8f8bd..a8bd30796 100644 --- a/src/containers/Preferences/SMSIntegration/components.js +++ b/src/containers/Preferences/SMSIntegration/components.js @@ -39,12 +39,14 @@ export function useSMSIntegrationTableColumns() { accessor: NotificationAccessor, className: 'notification', width: '180', + disableSortBy: true, }, { Header: intl.get('service'), accessor: 'module_formatted', className: 'service', width: '80', + disableSortBy: true, }, { Header: intl.get('sms_message.label_mesage'), @@ -53,6 +55,7 @@ export function useSMSIntegrationTableColumns() { className: 'sms_message', clickable: true, width: '180', + disableSortBy: true, }, { Header: intl.get('sms_message.label_auto'), From 7a1c9caa70d55e53c81cc2ed3ea7d1a6b41c9da9 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 8 Nov 2021 16:41:36 +0200 Subject: [PATCH 5/5] feat: add context menu in sms message table. --- .../Dialogs/SMSMessageDialog/index.js | 2 +- .../SMSIntegration/SMSMessagesDataTable.js | 10 +++++-- .../Preferences/SMSIntegration/components.js | 29 +++++++++++++++---- src/lang/ar/index.json | 10 ++++--- src/lang/en/index.json | 13 +++++---- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/containers/Dialogs/SMSMessageDialog/index.js b/src/containers/Dialogs/SMSMessageDialog/index.js index acb3c8784..aadb1b13e 100644 --- a/src/containers/Dialogs/SMSMessageDialog/index.js +++ b/src/containers/Dialogs/SMSMessageDialog/index.js @@ -20,7 +20,7 @@ function SMSMessageDialog({ return ( { + const handleEditMessageText = ({ key }) => { openDialog('sms-message-form', { notificationkey: key }); }; + const handleEnableNotification = () => {}; + return ( ); diff --git a/src/containers/Preferences/SMSIntegration/components.js b/src/containers/Preferences/SMSIntegration/components.js index a8bd30796..ee02b1249 100644 --- a/src/containers/Preferences/SMSIntegration/components.js +++ b/src/containers/Preferences/SMSIntegration/components.js @@ -1,8 +1,27 @@ import React from 'react'; import intl from 'react-intl-universal'; +import { Menu, MenuItem, MenuDivider } from '@blueprintjs/core'; import { SwitchFieldCell } from 'components/DataTableCells'; import { safeCallback } from 'utils'; +export function ActionsMenu({ + payload: { onEditMessageText, onEnableNotification }, + row: { original }, +}) { + return ( + + + + + ); +} + /** * Notification accessor. */ @@ -18,14 +37,14 @@ export const NotificationAccessor = (row) => { }; export const SMSMessageCell = ({ - payload: { onEditSMSMessage }, + payload: { onEditMessageText }, row: { original }, }) => (
{original.sms_message} {'Edit'} @@ -35,7 +54,7 @@ export const SMSMessageCell = ({ export function useSMSIntegrationTableColumns() { return React.useMemo(() => [ { - Header: intl.get('sms_message.label_Notification'), + Header: intl.get('sms_messages.label_notification'), accessor: NotificationAccessor, className: 'notification', width: '180', @@ -49,7 +68,7 @@ export function useSMSIntegrationTableColumns() { disableSortBy: true, }, { - Header: intl.get('sms_message.label_mesage'), + Header: intl.get('sms_messages.label_mesage'), accessor: 'sms_message', Cell: SMSMessageCell, className: 'sms_message', @@ -58,7 +77,7 @@ export function useSMSIntegrationTableColumns() { disableSortBy: true, }, { - Header: intl.get('sms_message.label_auto'), + Header: intl.get('sms_messages.label_auto'), accessor: 'is_notification_enabled', Cell: SwitchFieldCell, className: 'is_notification_enabled', diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index 9edc01ec9..af6998c5c 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1455,9 +1455,11 @@ "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_messages.label_mesage":"رسالة ", + "sms_messages.label_notification":"إشعار", + "sms_messages.label_auto":"Auto", "sms_message":"رسالة SMS" , - "sms_message.dialog.success_message":"Sms notification settings has been updated successfully." + "sms_message.dialog.success_message":"Sms notification settings has been updated successfully.", + "edit_message_text":"تعديل نص رسالة", + "enable_notification":"تفعيل الإشعارات" } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 6fec2ea85..c15694cf0 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1440,12 +1440,13 @@ "sms_integration.label":"SMS Integration", "sms_integration.label.overview":"Overview", "sms_integration.label.sms_messages":"SMS Messages", - "sms_message.label.sms_messages_template":"SMS Notifications ", - "sms_message.label_mesage":"Message", - "sms_message.label_Notification":"Notification", - "sms_message.label_auto":"Auto", - "sms_message":"SMS message", + "sms_messages.label_notification":"Notification", + "sms_messages.label_mesage":"Message", + "sms_messages.label_auto":"Auto", + "sms_message.dialog.label":"SMS message", "sms_message.dialog.success_message":"Sms notification settings has been updated successfully.", - "sms_message.dialog.unsupported_variables_error_message":"Unsupported variables" + "sms_message.dialog.unsupported_variables_error_message":"Unsupported variables", + "edit_message_text":"Edit message text", + "enable_notification":"Enable notification" }