From 35d755e417af45dd88957748c582cb037ec8a39a Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Thu, 11 Nov 2021 12:46:58 +0200 Subject: [PATCH] fix: SMS notification messages context menu. --- .../BalanceSheet/components.js | 2 +- .../SMSIntegration/SMSIntegrationProvider.js | 9 ++-- .../SMSIntegration/SMSMessagesDataTable.js | 45 ++++++++++++------- .../Preferences/SMSIntegration/components.js | 25 +++++++---- src/lang/ar/index.json | 12 ++--- src/lang/en/index.json | 8 ++-- 6 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/containers/FinancialStatements/BalanceSheet/components.js b/src/containers/FinancialStatements/BalanceSheet/components.js index 9439acb74..be3962ed9 100644 --- a/src/containers/FinancialStatements/BalanceSheet/components.js +++ b/src/containers/FinancialStatements/BalanceSheet/components.js @@ -27,7 +27,7 @@ export function BalanceSheetAlerts() { {' '} diff --git a/src/containers/Preferences/SMSIntegration/SMSIntegrationProvider.js b/src/containers/Preferences/SMSIntegration/SMSIntegrationProvider.js index 23b03f148..523ff944e 100644 --- a/src/containers/Preferences/SMSIntegration/SMSIntegrationProvider.js +++ b/src/containers/Preferences/SMSIntegration/SMSIntegrationProvider.js @@ -2,7 +2,6 @@ import React from 'react'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; import { useSettings, useSettingSMSNotifications } from 'hooks/query'; -import PreferencesPageLoader from '../PreferencesPageLoader'; const SMSIntegrationContext = React.createContext(); @@ -13,13 +12,17 @@ function SMSIntegrationProvider({ ...props }) { //Fetches Organization Settings. const { isLoading: isSettingsLoading } = useSettings(); - const { data: notifications, isLoading: isSMSNotificationsLoading } = - useSettingSMSNotifications(); + const { + data: notifications, + isLoading: isSMSNotificationsLoading, + isFetching: isSMSNotificationsFetching, + } = useSettingSMSNotifications(); // Provider state. const provider = { notifications, isSMSNotificationsLoading, + isSMSNotificationsFetching, }; return ( diff --git a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js index b2bb18603..3dd79c381 100644 --- a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js +++ b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js @@ -24,20 +24,24 @@ function SMSMessagesDataTable({ const { mutateAsync: editSMSNotificationMutate } = useSettingEditSMSNotification(); + const toggleSmsNotification = (notificationKey, value) => { + editSMSNotificationMutate({ + notification_key: notificationKey, + is_notification_enabled: value, + }).then(() => { + AppToaster.show({ + message: intl.get( + 'sms_messages.notification_switch_change_success_message', + ), + intent: Intent.SUCCESS, + }); + }); + }; + // Handle notification switch change. const handleNotificationSwitchChange = React.useCallback( (event, value, notification) => { - editSMSNotificationMutate({ - notification_key: notification.key, - is_notification_enabled: value, - }).then(() => { - AppToaster.show({ - message: intl.get( - 'sms_messages.notification_switch_change_success_message', - ), - intent: Intent.SUCCESS, - }); - }); + toggleSmsNotification(notification.key, value); }, [editSMSNotificationMutate], ); @@ -47,28 +51,37 @@ function SMSMessagesDataTable({ onSwitchChange: handleNotificationSwitchChange, }); - const { notifications, isSMSNotificationsLoading } = - useSMSIntegrationContext(); + const { + notifications, + isSMSNotificationsLoading, + isSMSNotificationsFetching, + } = useSMSIntegrationContext(); // handle edit message link click const handleEditMessageText = ({ key }) => { openDialog('sms-message-form', { notificationkey: key }); }; - const handleEnableNotification = () => {}; + const handleEnableNotification = (notification) => { + toggleSmsNotification(notification.key, true); + }; + + const handleDisableNotification = (notification) => { + toggleSmsNotification(notification.key, false); + }; return ( ); diff --git a/src/containers/Preferences/SMSIntegration/components.js b/src/containers/Preferences/SMSIntegration/components.js index c8a5f83df..ba2f37845 100644 --- a/src/containers/Preferences/SMSIntegration/components.js +++ b/src/containers/Preferences/SMSIntegration/components.js @@ -1,10 +1,9 @@ import React from 'react'; import intl from 'react-intl-universal'; import styled from 'styled-components'; -import { Intent, Button, Menu, MenuItem } from '@blueprintjs/core'; +import { Intent, Button, Menu, MenuItem, MenuDivider } from '@blueprintjs/core'; import { SwitchFieldCell } from 'components/DataTableCells'; - import { safeInvoke } from 'utils'; /** @@ -47,19 +46,27 @@ export const SMSMessageCell = ({ * Context menu of SMS notification messages. */ export function ActionsMenu({ - payload: { onEditMessageText, onEnableNotification }, + payload: { onEditMessageText, onEnableNotification, onDisableNotification }, row: { original }, }) { return ( - safeInvoke(onEditMessageText, original)} /> + + {!original.is_notification_enabled ? ( + safeInvoke(onEnableNotification, original)} + /> + ) : ( + safeInvoke(onDisableNotification, original)} + /> + )} ); } diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index b4b13c46f..62af42e11 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1445,8 +1445,8 @@ "notify_via_sms.dialog.notification_type": "نوع الإشعار", "notify_via_sms.dialog.notify_via_sms": "إشعار عبر رسائل قصيرة", "notiify_via_sms.dialog.sms_note": "ملاحظة : يمكن أن تحتوي رسالة قصيرة الواحدة على 160 حرفًا كحد أقصى {value}. سيتم استخدام وحدات الرسائل القصيرة لإرسال هذا إشعار عبر الرسائل القصيرة. ", - "notify_Via_sms.dialog.customer_phone_number_does_not_eixst": "رقم هاتف العميل غير موجود ، يرجى إدخال رقم هاتف للعميل. ", - "notify_Via_sms.dialog.customer_phone_number_invalid": "رقم هاتف العميل غير صالح ، يرجى إدخال رقم هاتف صحيح للعميل. ", + "notify_Via_sms.dialog.customer_phone_number_does_not_eixst": "رقم هاتف الزبون غير موجود ، يرجى إدخال رقم هاتف للعميل. ", + "notify_Via_sms.dialog.customer_phone_number_invalid": "رقم هاتف الزبون غير صالح ، يرجى إدخال رقم هاتف صحيح للعميل. ", "notify_via_sms.dialog.phone_invalid_error_message": "لا يمكن إرسال إشعار الرسائل القصيرة ، رقم الهاتف للعميل غير صالح ، يرجى إدخال رقم صالح والمحاولة مرة أخرى.", "notify_via_sms.dialog.customer_no_phone_error_message": "الزبون ليس لديه رقم هاتف.", "notify_invoice_via_sms.dialog.success_message": "تم إرسال إشعار فاتورة البيع عبر الرسائل القصيرة بنجاح ", @@ -1467,9 +1467,11 @@ "sms_message.dialog.success_message": "تم تحديث إعدادات إشعار الرسائل القصيرة بنجاح. ", "sms_message.dialog.unsupported_variables_error_message": "متغيرات غير مدعومة", "sms_message.dialog.message_variable_description": "{value} إشارة لاسم الشركة الحالي.", - "edit_message_text": "تعديل نص رسالة", - "enable_notification": "تفعيل الإشعارات", + "sms_notifications.edit_message_text": "تعديل نص رسالة", + "sms_notifications.enable_notification": "تفعيل الإشعارات", + "sms_notifications.disable_notification": "تعطيل الإشعارات", "send_sms": "إرسال رسالة قصيرة", "save_sms_message": "حفظ رسالة قصيرة", - "sms_message.edit_form.reset_to_default_message": "إعادة التعيين إلى الرسالة الافتراضية." + "sms_message.edit_form.reset_to_default_message": "إعادة التعيين إلى الرسالة الافتراضية.", + "report.compute_running.refresh": "تحديث" } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 0683e1e35..8f12c024f 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1453,9 +1453,11 @@ "sms_message.dialog.success_message": "Sms notification settings has been updated successfully.", "sms_message.dialog.unsupported_variables_error_message": "Unsupported variables", "sms_message.dialog.message_variable_description": "{value} References to the current company name.", - "edit_message_text": "Edit message text", - "enable_notification": "Enable notification", + "sms_notifications.edit_message_text": "Edit message text", + "sms_notifications.enable_notification": "Enable notification", + "sms_notifications.disable_notification": "Disable notification", "send_sms": "Send SMS", "save_sms_message": "Save SMS Message", - "sms_message.edit_form.reset_to_default_message": "Reset to default message." + "sms_message.edit_form.reset_to_default_message": "Reset to default message.", + "report.compute_running.refresh": "Refresh" } \ No newline at end of file