diff --git a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js index acbef5440..4ad780a49 100644 --- a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js +++ b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js @@ -41,12 +41,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 ba1649ed4..f30904583 100644 --- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js +++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js @@ -53,7 +53,9 @@ function NotifyInvoiceViaSMSForm({ data: { errors }, }, }) => { - transformErrors(errors); + if (errors) { + transformErrors(errors, { setErrors }); + } setSubmitting(false); }; // Transformes the form values to request. 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/Dialogs/SMSMessageDialog/SMSMessageForm.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js index 2fdac2b75..a693850ec 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'; @@ -58,6 +59,9 @@ function SMSMessageForm({ data: { errors }, }, }) => { + if (errors) { + transformErrors(errors, { setErrors }); + } setSubmitting(false); }; debugger; 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 ( { + 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/containers/NotifyViaSMS/utils.js b/src/containers/NotifyViaSMS/utils.js index 598df1ce1..33804e5c2 100644 --- a/src/containers/NotifyViaSMS/utils.js +++ b/src/containers/NotifyViaSMS/utils.js @@ -2,13 +2,21 @@ 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/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js index ebaa9e383..a183e4bd9 100644 --- a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js +++ b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js @@ -4,7 +4,7 @@ import styled from 'styled-components'; import { DataTable } from 'components'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; -import { useSMSIntegrationTableColumns } from './components'; +import { useSMSIntegrationTableColumns, ActionsMenu } from './components'; import { useSMSIntegrationContext } from './SMSIntegrationProvider'; import withDialogActions from 'containers/Dialog/withDialogActions'; @@ -20,10 +20,12 @@ function SMSMessagesDataTable({ const { notifications, isSMSNotificationsLoading } = useSMSIntegrationContext(); - const handleEditSMSMessage = ({ key }) => { + 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 0fff799c6..161bddfe0 100644 --- a/src/containers/Preferences/SMSIntegration/components.js +++ b/src/containers/Preferences/SMSIntegration/components.js @@ -1,6 +1,7 @@ import React from 'react'; import intl from 'react-intl-universal'; import styled from 'styled-components'; +import { Menu, MenuItem } from '@blueprintjs/core'; import { ButtonLink } from 'components'; import { SwitchFieldCell } from 'components/DataTableCells'; @@ -24,19 +25,40 @@ export const NotificationAccessor = (row) => { * SMS notification message cell. */ export const SMSMessageCell = ({ - payload: { onEditSMSMessage }, + payload: { onEditMessageText }, row: { original }, }) => (
{original.sms_message} - safeInvoke(onEditSMSMessage, original)}> + safeInvoke(onEditMessageText, original)}> Edit message
); +/** + * Context menu of SMS notification messages. + */ +export function ActionsMenu({ + payload: { onEditMessageText, onEnableNotification }, + row: { original }, +}) { + return ( + + + + + ); +} + /** * Retrieve SMS notifications messages table columns * @returns @@ -49,12 +71,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'), @@ -63,14 +87,15 @@ export function useSMSIntegrationTableColumns() { className: 'sms_message', clickable: true, width: '180', + disableSortBy: true, }, { Header: intl.get('sms_message.label_auto'), accessor: 'is_notification_enabled', Cell: SwitchFieldCell, className: 'is_notification_enabled', - disableSortBy: true, disableResizing: true, + disableSortBy: true, width: '80', }, ], 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. diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index 4281ccc13..af6998c5c 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", @@ -1453,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 d94b9f180..c15694cf0 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1427,23 +1427,26 @@ "bad_debt.dialog.success_message": "The given sale invoice has been writte-off successfully.", "bad_debt.cancel_alert.success_message": "The given sale invoice has been canceled write-off successfully.", "bad_debt.cancel_alert.message": "Are you sure you want to write off this invoice?", - "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.success_message": "SMS notification has been sent successfully.", - "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", - "notify_payment_receive_via_sms.dialog.success_message": "The payment notification has been sent successfully.", + "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.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", + "notify_payment_receive_via_sms.dialog.success_message":"The payment notification has been sent successfully.", "send": "Send", - "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_message.dialog.success_message": "Sms notification settings has been updated successfully." -} \ No newline at end of file + "sms_integration.label":"SMS Integration", + "sms_integration.label.overview":"Overview", + "sms_integration.label.sms_messages":"SMS Messages", + "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", + "edit_message_text":"Edit message text", + "enable_notification":"Enable notification" +} +