+
{/* ----------- Message Text ----------- */}
{({ field, meta: { error, touched } }) => (
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js
index efa1a090a..d7eabc30e 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js
@@ -1,6 +1,8 @@
import React from 'react';
import { Intent, Button, Classes } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
+import styled from 'styled-components';
+
import { FormattedMessage as T } from 'components';
import { useSMSMessageDialogContext } from './SMSMessageDialogProvider';
@@ -27,7 +29,7 @@ function SMSMessageFormFloatingActions({
return (
-
+
@@ -37,11 +39,15 @@ function SMSMessageFormFloatingActions({
style={{ minWidth: '75px' }}
type="submit"
>
- { }
+ Save SMS Message
-
+
);
}
export default compose(withDialogActions)(SMSMessageFormFloatingActions);
+
+const FooterActions = styled.div`
+ justify-content: flex-start;
+`;
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
index 93eb57375..a6f60ad1f 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
@@ -1,28 +1,62 @@
import React from 'react';
-import { Formik, Form } from 'formik';
+import { Formik, Form, useFormikContext } from 'formik';
+import styled from 'styled-components';
+import { Classes } from '@blueprintjs/core';
import 'style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss';
import { CreateNotifyViaSMSFormSchema } from './NotifyViaSMSForm.schema';
import NotifyViaSMSFormFields from './NotifyViaSMSFormFields';
import NotifyViaSMSFormFloatingActions from './NotifyViaSMSFormFloatingActions';
+import { FormObserver, SMSMessagePreview } from 'components';
-import { transformToForm, saveInvoke } from 'utils';
+import { transformToForm, safeInvoke } from 'utils';
+import { getSMSUnits } from './utils';
const defaultInitialValues = {
+ notification_key: '',
customer_name: '',
customer_phone_number: '',
sms_message: '',
};
+/**
+ * Notify via sms - SMS message preview section.
+ */
+function SMSMessagePreviewSection() {
+ const {
+ values: { sms_message },
+ } = useFormikContext();
+
+ // Calculates the SMS units of message.
+ const messagesUnits = getSMSUnits(sms_message);
+
+ return (
+
+
+
+
+ Note : Note: One SMS unit can contain a maximum of 160
+ characters. {messagesUnits} SMS units will be used to
+ send this SMS notification.
+
+
+ );
+}
+
/**
* Notify Via SMS Form.
*/
-function NotifyViaSMSForm({ onSubmit, NotificationDetail, NotificationName }) {
+function NotifyViaSMSForm({
+ initialValues: initialValuesComponent,
+ onSubmit,
+ onCancel,
+ onValuesChange,
+}) {
// Initial form values
const initialValues = {
...defaultInitialValues,
- ...transformToForm(NotificationDetail, defaultInitialValues),
+ ...transformToForm(initialValuesComponent, defaultInitialValues),
};
return (
@@ -32,11 +66,56 @@ function NotifyViaSMSForm({ onSubmit, NotificationDetail, NotificationName }) {
onSubmit={onSubmit}
>
);
}
+/**
+ * Observes the values change of notify form.
+ */
+function NotifyObserveValuesChange({ onChange }) {
+ const { values } = useFormikContext();
+
+ // Handle the form change observe.
+ const handleChange = () => {
+ safeInvoke(onChange, values);
+ };
+ return ;
+}
+
export default NotifyViaSMSForm;
+
+const NotifyContent = styled.div`
+ display: flex;
+`;
+
+const NotifyFieldsSection = styled.div`
+ flex: 1;
+ width: 65%;
+`;
+
+const SMSPreviewSectionRoot = styled.div`
+ display: flex;
+ flex-direction: column;
+ width: 45%;
+ padding-left: 25px;
+ margin-left: 25px;
+ border-left: 1px solid #dcdcdd;
+`;
+
+const SMSPreviewSectionNote = styled.div`
+ font-size: 12px;
+ opacity: 0.7;
+`;
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js b/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
index 37c88c1e7..65b2058d2 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
@@ -1,16 +1,47 @@
import React from 'react';
import { FastField, ErrorMessage } from 'formik';
-import { FormattedMessage as T } from 'components';
-
-import { Classes, FormGroup, TextArea, InputGroup } from '@blueprintjs/core';
+import { FormGroup, InputGroup } from '@blueprintjs/core';
import classNames from 'classnames';
+
+import {
+ ListSelect,
+ FieldRequiredHint,
+ FormattedMessage as T,
+} from 'components';
import { CLASSES } from 'common/classes';
import { inputIntent } from 'utils';
-import { FieldRequiredHint } from 'components';
-function NotifyViaSMSFormFields() {
+const notificationTypes = [
+ { key: 'details', label: 'Invoice details' },
+ { key: 'reminder', label: 'Invoice reminder' },
+];
+
+export default function NotifyViaSMSFormFields() {
return (
-
+
+
+ {({ form, meta: { error, touched } }) => (
+ }
+ >
+ {
+ form.setFieldValue('notification_key', notification.key);
+ }}
+ />
+
+ )}
+
+
{/* ----------- Send Notification to ----------- */}
{({ form, field, meta: { error, touched } }) => (
@@ -51,29 +82,6 @@ function NotifyViaSMSFormFields() {
)}
-
- {/* ----------- Message Text ----------- */}
-
- {({ field, meta: { error, touched } }) => (
- }
- labelInfo={ }
- className={'form-group--sms_message'}
- intent={inputIntent({ error, touched })}
- helperText={ }
- >
-
-
- )}
-
);
}
-
-export default NotifyViaSMSFormFields;
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js b/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js
index 899125f5f..96e3b50e0 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js
@@ -1,41 +1,47 @@
import React from 'react';
import { useFormikContext } from 'formik';
import { Intent, Button, Classes } from '@blueprintjs/core';
+import styled from 'styled-components';
import { FormattedMessage as T } from 'components';
-import withDialogActions from 'containers/Dialog/withDialogActions';
-import { compose } from 'utils';
+import { safeCallback } from 'utils';
-function NotifyViaSMSFormFloatingActions({
- // #withDialogActions
- closeDialog,
- dialogName,
-}) {
+/**
+ *
+ */
+export default function NotifyViaSMSFormFloatingActions({ onCancel }) {
// Formik context.
const { isSubmitting } = useFormikContext();
// Handle close button click.
- const handleCancelBtnClick = () => {
- closeDialog(dialogName);
+ const handleCancelBtnClick = (event) => {
+ onCancel && onCancel(event);
};
return (
-
-
-
-
+
- { }
+ Send SMS
-
+
+
+
+
);
}
-export default compose(withDialogActions)(NotifyViaSMSFormFloatingActions);
+
+const FooterActions = styled.div`
+ justify-content: flex-start;
+`;
diff --git a/src/containers/NotifyViaSMS/utils.js b/src/containers/NotifyViaSMS/utils.js
index 5ed16cae1..598df1ce1 100644
--- a/src/containers/NotifyViaSMS/utils.js
+++ b/src/containers/NotifyViaSMS/utils.js
@@ -10,3 +10,8 @@ export const transformErrors = (errors) => {
});
}
};
+
+
+export const getSMSUnits = (message, threshold = 140) => {
+ return Math.ceil(message.length / threshold);
+};
\ No newline at end of file
diff --git a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js
index db3aefad8..ebaa9e383 100644
--- a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js
+++ b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js
@@ -1,5 +1,7 @@
import React from 'react';
-import { DataTableEditable, DataTable } from 'components';
+import styled from 'styled-components';
+
+import { DataTable } from 'components';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import { useSMSIntegrationTableColumns } from './components';
@@ -23,7 +25,7 @@ function SMSMessagesDataTable({
};
return (
-
{
return (
- {row.notification_label}
-
+ {row.notification_label}
+
{row.notification_description}
-
+
);
};
+/**
+ * SMS notification message cell.
+ */
export const SMSMessageCell = ({
payload: { onEditSMSMessage },
row: { original },
}) => (
- {original.sms_message}
-
- {'Edit'}
-
+ {original.sms_message}
+
+ safeInvoke(onEditSMSMessage, original)}>
+ Edit message
+
+
);
+/**
+ * Retrieve SMS notifications messages table columns
+ * @returns
+ */
export function useSMSIntegrationTableColumns() {
- return React.useMemo(() => [
- {
- Header: intl.get('sms_message.label_Notification'),
- accessor: NotificationAccessor,
- className: 'notification',
- width: '180',
- },
- {
- Header: intl.get('service'),
- accessor: 'module_formatted',
- className: 'service',
- width: '80',
- },
- {
- Header: intl.get('sms_message.label_mesage'),
- accessor: 'sms_message',
- Cell: SMSMessageCell,
- className: 'sms_message',
- clickable: true,
- width: '180',
- },
- {
- Header: intl.get('sms_message.label_auto'),
- accessor: 'is_notification_enabled',
- Cell: SwitchFieldCell,
- className: 'is_notification_enabled',
- disableSortBy: true,
- disableResizing: true,
- width: '80',
- },
- ]);
+ return React.useMemo(
+ () => [
+ {
+ Header: intl.get('sms_message.label_Notification'),
+ accessor: NotificationAccessor,
+ className: 'notification',
+ width: '180',
+ },
+ {
+ Header: intl.get('service'),
+ accessor: 'module_formatted',
+ className: 'service',
+ width: '80',
+ },
+ {
+ Header: intl.get('sms_message.label_mesage'),
+ accessor: 'sms_message',
+ Cell: SMSMessageCell,
+ className: 'sms_message',
+ clickable: true,
+ width: '180',
+ },
+ {
+ Header: intl.get('sms_message.label_auto'),
+ accessor: 'is_notification_enabled',
+ Cell: SwitchFieldCell,
+ className: 'is_notification_enabled',
+ disableSortBy: true,
+ disableResizing: true,
+ width: '80',
+ },
+ ],
+ [],
+ );
}
+
+const NotificationLabel = styled.div`
+ font-weight: 500;
+`;
+
+const NotificationDescription = styled.div`
+ font-size: 14px;
+ margin-top: 6px;
+ display: block;
+ opacity: 0.75;
+`;
+
+const MessageBox = styled.div`
+ padding: 10px;
+ background-color: #fbfbfb;
+ border: 1px dashed #dcdcdc;
+ font-size: 14px;
+ line-height: 1.45;
+`;
+
+const MessageBoxActions = styled.div`
+ margin-top: 2px;
+
+ button {
+ font-size: 12px;
+ }
+`;
diff --git a/src/hooks/query/invoices.js b/src/hooks/query/invoices.js
index 6c1c7f767..aabe2fa07 100644
--- a/src/hooks/query/invoices.js
+++ b/src/hooks/query/invoices.js
@@ -254,13 +254,13 @@ export function useCreateNotifyInvoiceBySMS(props) {
);
}
-export function useInvoiceSMSDetail(invoiceId, props, requestProps) {
+export function useInvoiceSMSDetail(invoiceId, query, props) {
return useRequestQuery(
- [t.SALE_INVOICE_SMS_DETAIL, invoiceId],
+ [t.SALE_INVOICE_SMS_DETAIL, invoiceId, query],
{
method: 'get',
url: `sales/invoices/${invoiceId}/sms-details`,
- ...requestProps,
+ params: query,
},
{
select: (res) => res.data.data,
diff --git a/src/lang/en/index.json b/src/lang/en/index.json
index 87aedd67a..d94b9f180 100644
--- a/src/lang/en/index.json
+++ b/src/lang/en/index.json
@@ -1427,23 +1427,23 @@
"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.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.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.",
"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."
-}
-
+ "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
diff --git a/src/static/json/icons.js b/src/static/json/icons.js
index 42a191624..fc6ffe780 100644
--- a/src/static/json/icons.js
+++ b/src/static/json/icons.js
@@ -509,4 +509,11 @@ export default {
],
viewBox: '0 0 24 24',
},
+ "sms-message-preview": {
+ path: [
+ 'M8.341,375.3573H399.3271v-.0015l-390.9861-.07ZM363.2382,0H44.43A44.4508,44.4508,0,0,0,0,44.371V375.284l8.341.0016V44.371A36.0651,36.0651,0,0,1,44.43,8.33H90.7089a4.6454,4.6454,0,0,1,4.6482,4.6423v1.9718a23.8588,23.8588,0,0,0,23.8742,23.843H288.9146a23.8586,23.8586,0,0,0,23.8741-23.843V12.972A4.6456,4.6456,0,0,1,317.4372,8.33h45.801A36.0651,36.0651,0,0,1,399.3271,44.371V375.3558l8.341.0015V44.371A44.4508,44.4508,0,0,0,363.2382,0Z',
+ "M1199.9485,803.1623"
+ ],
+ viewBox: "0 0 407.6681 375.3573",
+ }
};
diff --git a/src/style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss b/src/style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss
index e0ba9e197..f4e334703 100644
--- a/src/style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss
+++ b/src/style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss
@@ -1,6 +1,5 @@
.dialog--notify-vis-sms {
- max-width: 350px;
- max-height: 450px;
+ width: 800px;
.bp3-dialog-body {
.bp3-form-group {
diff --git a/src/style/pages/Preferences/Page.scss b/src/style/pages/Preferences/Page.scss
index 1f996676e..d156b96c4 100644
--- a/src/style/pages/Preferences/Page.scss
+++ b/src/style/pages/Preferences/Page.scss
@@ -17,8 +17,7 @@
&__inside-content {
display: flex;
flex-direction: column;
- height: 100%;
-
+
&--tabable {
margin-left: -25px;
margin-right: -25px;
diff --git a/src/style/pages/SMSMessage/SMSMessage.scss b/src/style/pages/SMSMessage/SMSMessage.scss
index 7b447d293..bd9b46c90 100644
--- a/src/style/pages/SMSMessage/SMSMessage.scss
+++ b/src/style/pages/SMSMessage/SMSMessage.scss
@@ -1,5 +1,5 @@
.dialog--sms-message {
- max-width: 350px;
+ width: 800px;
.bp3-form-group {
margin-bottom: 15px;
diff --git a/src/utils/index.js b/src/utils/index.js
index c5f67fd32..f91986577 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -341,7 +341,7 @@ export const saveInvoke = (func, ...rest) => {
};
export const safeInvoke = (func, ...rest) => {
- return func && func(...rest);
+ func && func(...rest);
};
export const transformToForm = (obj, emptyInitialValues) => {
From 8daefb6946a167d19909c8b6b72b17fec92a5760 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 09:57:12 +0200
Subject: [PATCH 17/41] fix: add notification id to sms messages templates
table.
---
src/containers/Preferences/SMSIntegration/components.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/containers/Preferences/SMSIntegration/components.js b/src/containers/Preferences/SMSIntegration/components.js
index 161bddfe0..3e59329ba 100644
--- a/src/containers/Preferences/SMSIntegration/components.js
+++ b/src/containers/Preferences/SMSIntegration/components.js
@@ -67,6 +67,7 @@ export function useSMSIntegrationTableColumns() {
return React.useMemo(
() => [
{
+ id: 'notification',
Header: intl.get('sms_message.label_Notification'),
accessor: NotificationAccessor,
className: 'notification',
From 4b5e06f50c8e8d15b39e9e4519b4cea26e7c1113 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 11:08:47 +0200
Subject: [PATCH 18/41] feat: SMS notification module.
---
.../NotifyEstimateViaSMSForm.js | 18 ++++++++++++++--
.../NotifyInvoiceViaSMSForm.js | 9 ++++++++
.../NotifyPaymentReceiveViaSMSForm.js | 20 ++++++++++++++++--
.../NotifyReceiptViaSMSForm.js | 21 +++++++++++++++++--
.../NotifyReceiptViaSMSFormProvider.js | 6 +++++-
.../NotifyViaSMS/NotifyViaSMSForm.js | 13 ++++++++++--
.../NotifyViaSMS/NotifyViaSMSFormFields.js | 15 +++++++------
src/hooks/query/estimates.js | 10 +++++++++
src/hooks/query/settings.js | 6 +++++-
9 files changed, 100 insertions(+), 18 deletions(-)
diff --git a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js
index 4ad780a49..a7da22dd0 100644
--- a/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js
+++ b/src/containers/Dialogs/NotifyEstimateViaSMSDialog/NotifyEstimateViaSMSForm.js
@@ -11,6 +11,11 @@ import { transformErrors } from '../../../containers/NotifyViaSMS/utils';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
+const notificationType = {
+ key: 'sale-estimate-details',
+ label: 'Sale estimate details',
+};
+
function NotifyEstimateViaSMSForm({
// #withDialogActions
closeDialog,
@@ -51,10 +56,19 @@ function NotifyEstimateViaSMSForm({
.catch(onError);
};
+ const initialValues = {
+ ...estimateSMSDetail,
+ };
+ // Handle the form cancel.
+ const handleFormCancel = () => {
+ closeDialog(dialogName);
+ };
+
return (
);
diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
index f30904583..9cb293b73 100644
--- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
+++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
@@ -80,10 +80,19 @@ function NotifyInvoiceViaSMSForm({
setNotificationType(values.notification_key);
}
};
+ // Momerize the notification types.
+ const notificationTypes = React.useMemo(
+ () => [
+ { key: 'details', label: 'Invoice details' },
+ { key: 'reminder', label: 'Invoice reminder' },
+ ],
+ [],
+ );
return (
{
+ closeDialog(dialogName);
+ };
+
+ // Form initial values.
+ const initialValues = React.useMemo(
+ () => ({ ...paymentReceiveMSDetail }),
+ [paymentReceiveMSDetail],
+ );
return (
);
}
diff --git a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js
index b778f97d4..2b95a0d35 100644
--- a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js
+++ b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSForm.js
@@ -11,6 +11,11 @@ import { transformErrors } from '../../../containers/NotifyViaSMS/utils';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
+const notificationType = {
+ key: 'sale-receipt-details',
+ label: 'Sale receipt details',
+};
+
/**
* Notify Receipt Via SMS Form.
*/
@@ -51,12 +56,24 @@ function NotifyReceiptViaSMSForm({
.then(onSuccess)
.catch(onError);
};
+ // Handle the form cancel.
+ const handleFormCancel = () => {
+ closeDialog(dialogName);
+ };
+ // Initial values.
+ const initialValues = React.useMemo(
+ () => ({
+ ...receiptSMSDetail,
+ }),
+ [receiptSMSDetail],
+ );
return (
);
}
diff --git a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSFormProvider.js b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSFormProvider.js
index 3f2515319..cc2a00089 100644
--- a/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSFormProvider.js
+++ b/src/containers/Dialogs/NotifyReceiptViaSMSDialog/NotifyReceiptViaSMSFormProvider.js
@@ -4,11 +4,15 @@ import { useCreateNotifyReceiptBySMS, useReceiptSMSDetail } from 'hooks/query';
const NotifyReceiptViaSMSContext = React.createContext();
+/**
+ *
+ */
function NotifyReceiptViaSMSFormProvider({ receiptId, dialogName, ...props }) {
- // Create notfiy receipt via sms mutations.
+ // Create notfiy receipt via SMS mutations.
const { mutateAsync: createNotifyReceiptBySMSMutate } =
useCreateNotifyReceiptBySMS();
+ // Retrieve the receipt SMS notification details.
const { data: receiptSMSDetail, isLoading: isReceiptSMSDetailLoading } =
useReceiptSMSDetail(receiptId, {
enabled: !!receiptId,
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
index a6f60ad1f..b3a55a835 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
@@ -1,4 +1,5 @@
import React from 'react';
+import { castArray } from 'lodash';
import { Formik, Form, useFormikContext } from 'formik';
import styled from 'styled-components';
import { Classes } from '@blueprintjs/core';
@@ -34,7 +35,6 @@ function SMSMessagePreviewSection() {
return (
-
Note : Note: One SMS unit can contain a maximum of 160
characters. {messagesUnits} SMS units will be used to
@@ -49,6 +49,7 @@ function SMSMessagePreviewSection() {
*/
function NotifyViaSMSForm({
initialValues: initialValuesComponent,
+ notificationTypes,
onSubmit,
onCancel,
onValuesChange,
@@ -58,6 +59,11 @@ function NotifyViaSMSForm({
...defaultInitialValues,
...transformToForm(initialValuesComponent, defaultInitialValues),
};
+ // Ensure always returns array.
+ const formattedNotificationTypes = React.useMemo(
+ () => castArray(notificationTypes),
+ [notificationTypes],
+ );
return (
-
+
+
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js b/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
index 65b2058d2..d2b925bdc 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
@@ -2,6 +2,7 @@ import React from 'react';
import { FastField, ErrorMessage } from 'formik';
import { FormGroup, InputGroup } from '@blueprintjs/core';
import classNames from 'classnames';
+import styled from 'styled-components';
import {
ListSelect,
@@ -11,14 +12,9 @@ import {
import { CLASSES } from 'common/classes';
import { inputIntent } from 'utils';
-const notificationTypes = [
- { key: 'details', label: 'Invoice details' },
- { key: 'reminder', label: 'Invoice reminder' },
-];
-
-export default function NotifyViaSMSFormFields() {
+export default function NotifyViaSMSFormFields({ notificationTypes }) {
return (
-
+
{({ form, meta: { error, touched } }) => (
{
form.setFieldValue('notification_key', notification.key);
}}
+ disabled={notificationTypes.length < 2}
/>
)}
@@ -82,6 +79,8 @@ export default function NotifyViaSMSFormFields() {
)}
-
+
);
}
+
+const NotifyViaSMSFormFieldsRoot = styled.div``;
diff --git a/src/hooks/query/estimates.js b/src/hooks/query/estimates.js
index 0000e6120..b73eae6ce 100644
--- a/src/hooks/query/estimates.js
+++ b/src/hooks/query/estimates.js
@@ -190,6 +190,9 @@ export function useRefreshEstimates() {
};
}
+/**
+ *
+ */
export function useCreateNotifyEstimateBySMS(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
@@ -210,6 +213,13 @@ export function useCreateNotifyEstimateBySMS(props) {
);
}
+/**
+ *
+ * @param {*} estimateId
+ * @param {*} props
+ * @param {*} requestProps
+ * @returns
+ */
export function useEstimateSMSDetail(estimateId, props, requestProps) {
return useRequestQuery(
[t.SALE_ESTIMATE_SMS_DETAIL, estimateId],
diff --git a/src/hooks/query/settings.js b/src/hooks/query/settings.js
index 74f302bc6..492ce6521 100644
--- a/src/hooks/query/settings.js
+++ b/src/hooks/query/settings.js
@@ -170,8 +170,12 @@ export function useSettingEditSMSNotification(props) {
(values) => apiRequest.post(`settings/sms-notification`, values),
{
onSuccess: () => {
- // Invalidate
queryClient.invalidateQueries([t.SETTING_SMS_NOTIFICATIONS]);
+
+ queryClient.invalidateQueries(t.SALE_INVOICE_SMS_DETAIL);
+ queryClient.invalidateQueries(t.SALE_RECEIPT_SMS_DETAIL);
+ queryClient.invalidateQueries(t.PAYMENT_RECEIVE_SMS_DETAIL);
+ queryClient.invalidateQueries(t.SALE_ESTIMATE_SMS_DETAIL);
},
...props,
},
From 73715574828fc9e883fd8e4c4c6545fcd53f3d40 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 12:34:55 +0200
Subject: [PATCH 19/41] feat: optimize style of SMS notifications module.
---
.../DataTableCells/SwitchFieldCell.js | 18 ++++++++---
src/components/Dialog/Dialog.js | 10 +++---
src/components/Dialog/DialogContent.js | 2 +-
src/components/Dialog/DialogFooterActions.js | 26 +++++++++++++++
src/components/Dialog/DialogSuspense.js | 2 +-
src/components/Dialog/index.js | 6 ++++
src/components/index.js | 9 ++----
.../SMSMessageDialog/SMSMessageForm.js | 1 -
.../SMSMessageDialog/SMSMessageFormContent.js | 1 -
.../SMSMessageFormFloatingActions.js | 12 +++----
.../NotifyViaSMSFormFloatingActions.js | 15 +++------
.../SMSIntegration/SMSMessagesDataTable.js | 32 +++++++++++++++++--
.../Preferences/SMSIntegration/components.js | 6 ++--
src/hooks/query/settings.js | 1 -
14 files changed, 96 insertions(+), 45 deletions(-)
create mode 100644 src/components/Dialog/DialogFooterActions.js
create mode 100644 src/components/Dialog/index.js
diff --git a/src/components/DataTableCells/SwitchFieldCell.js b/src/components/DataTableCells/SwitchFieldCell.js
index df5bb0e89..a25e96ae4 100644
--- a/src/components/DataTableCells/SwitchFieldCell.js
+++ b/src/components/DataTableCells/SwitchFieldCell.js
@@ -1,21 +1,28 @@
import React from 'react';
import classNames from 'classnames';
-import { get } from 'lodash';
import { Classes, Switch, FormGroup, Intent } from '@blueprintjs/core';
+import { safeInvoke } from 'utils';
+
+/**
+ * Switch editable cell.
+ */
const SwitchEditableCell = ({
row: { index, original },
- column: { id, switchProps },
+ column: { id, switchProps, onSwitchChange },
cell: { value: initialValue },
payload,
}) => {
const [value, setValue] = React.useState(initialValue);
+ // Handle the switch change.
const onChange = (e) => {
const newValue = e.target.checked;
setValue(newValue);
- payload.updateData(index, id, newValue);
+
+ safeInvoke(payload.updateData, index, id, newValue);
+ safeInvoke(onSwitchChange, e, newValue, original);
};
React.useEffect(() => {
@@ -31,7 +38,7 @@ const SwitchEditableCell = ({
>
);
};
-export default SwitchEditableCell;
+
+export default SwitchEditableCell;
\ No newline at end of file
diff --git a/src/components/Dialog/Dialog.js b/src/components/Dialog/Dialog.js
index 95e1fdcbf..c5f793251 100644
--- a/src/components/Dialog/Dialog.js
+++ b/src/components/Dialog/Dialog.js
@@ -9,16 +9,16 @@ function DialogComponent(props) {
const { name, children, closeDialog, onClose } = props;
const handleClose = (event) => {
- closeDialog(name)
+ closeDialog(name);
onClose && onClose(event);
};
return (
- { children }
+ {children}
);
}
-export default compose(
- withDialogActions,
-)(DialogComponent);
\ No newline at end of file
+const DialogRoot = compose(withDialogActions)(DialogComponent);
+
+export { DialogRoot as Dialog };
diff --git a/src/components/Dialog/DialogContent.js b/src/components/Dialog/DialogContent.js
index 265182bc5..cb438f499 100644
--- a/src/components/Dialog/DialogContent.js
+++ b/src/components/Dialog/DialogContent.js
@@ -2,7 +2,7 @@ import React from 'react';
import { Spinner, Classes } from '@blueprintjs/core';
import classNames from 'classnames';
-export default function DialogContent(props) {
+export function DialogContent(props) {
const { isLoading, children } = props;
const loadingContent = (
diff --git a/src/components/Dialog/DialogFooterActions.js b/src/components/Dialog/DialogFooterActions.js
new file mode 100644
index 000000000..91c856e9a
--- /dev/null
+++ b/src/components/Dialog/DialogFooterActions.js
@@ -0,0 +1,26 @@
+import React from 'react';
+import styled from 'styled-components';
+import { Classes } from '@blueprintjs/core';
+
+export function DialogFooterActions({ alignment = 'right', children }) {
+ return (
+
+ {children}
+
+ );
+}
+
+const DialogFooterActionsRoot = styled.div`
+ margin-left: -10px;
+ margin-right: -10px;
+ justify-content: ${(props) =>
+ props.alignment === 'right' ? 'flex-end' : 'flex-start'};
+
+ .bp3-button {
+ margin-left: 10px;
+ margin-left: 10px;
+ }
+`;
diff --git a/src/components/Dialog/DialogSuspense.js b/src/components/Dialog/DialogSuspense.js
index 6513d28c5..56ed625b9 100644
--- a/src/components/Dialog/DialogSuspense.js
+++ b/src/components/Dialog/DialogSuspense.js
@@ -5,7 +5,7 @@ function LoadingContent() {
return (
);
}
-export default function DialogSuspense({
+export function DialogSuspense({
children
}) {
return (
diff --git a/src/components/Dialog/index.js b/src/components/Dialog/index.js
new file mode 100644
index 000000000..c7c0982fb
--- /dev/null
+++ b/src/components/Dialog/index.js
@@ -0,0 +1,6 @@
+
+
+export * from './Dialog';
+export * from './DialogFooterActions';
+export * from './DialogSuspense';
+export * from './DialogContent';
\ No newline at end of file
diff --git a/src/components/index.js b/src/components/index.js
index ee698b70c..b8ca111f4 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -23,9 +23,6 @@ import AccountsSelectList from './AccountsSelectList';
import AccountsTypesSelect from './AccountsTypesSelect';
import LoadingIndicator from './LoadingIndicator';
import DashboardActionViewsList from './Dashboard/DashboardActionViewsList';
-import Dialog from './Dialog/Dialog';
-import DialogContent from './Dialog/DialogContent';
-import DialogSuspense from './Dialog/DialogSuspense';
import InputPrependButton from './Forms/InputPrependButton';
import CategoriesSelectList from './CategoriesSelectList';
import Row from './Grid/Row';
@@ -63,6 +60,7 @@ import AvaterCell from './AvaterCell';
import { ItemsMultiSelect } from './Items';
import MoreMenuItems from './MoreMenutItems';
+export * from './Dialog';
export * from './Menu';
export * from './AdvancedFilter/AdvancedFilterDropdown';
export * from './AdvancedFilter/AdvancedFilterPopover';
@@ -121,9 +119,6 @@ export {
LoadingIndicator,
DashboardActionViewsList,
AppToaster,
- Dialog,
- DialogContent,
- DialogSuspense,
InputPrependButton,
CategoriesSelectList,
Col,
@@ -159,5 +154,5 @@ export {
ItemsMultiSelect,
Card,
AvaterCell,
- MoreMenuItems
+ MoreMenuItems,
};
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js
index a693850ec..3f2e8ecc9 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageForm.js
@@ -64,7 +64,6 @@ function SMSMessageForm({
}
setSubmitting(false);
};
- debugger;
editSMSNotificationMutate(form).then(onSuccess).catch(onError);
};
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
index 2d1890208..8cfc998f5 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
@@ -60,7 +60,6 @@ function SMSMessagePreviewSection() {
return (
-
Note : Note: One SMS unit can contain a maximum of 160
characters. {messagesUnits} SMS units will be used to
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js
index d7eabc30e..e4eba28df 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormFloatingActions.js
@@ -1,9 +1,8 @@
import React from 'react';
import { Intent, Button, Classes } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
-import styled from 'styled-components';
-import { FormattedMessage as T } from 'components';
+import { DialogFooterActions, FormattedMessage as T } from 'components';
import { useSMSMessageDialogContext } from './SMSMessageDialogProvider';
import withDialogActions from 'containers/Dialog/withDialogActions';
@@ -20,6 +19,7 @@ function SMSMessageFormFloatingActions({
// Formik context.
const { isSubmitting } = useFormikContext();
+ // SMS Message dialog contxt.
const { dialogName } = useSMSMessageDialogContext();
// Handle close button click.
@@ -29,7 +29,7 @@ function SMSMessageFormFloatingActions({
return (
-
+
@@ -41,13 +41,9 @@ function SMSMessageFormFloatingActions({
>
Save SMS Message
-
+
);
}
export default compose(withDialogActions)(SMSMessageFormFloatingActions);
-
-const FooterActions = styled.div`
- justify-content: flex-start;
-`;
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js b/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js
index 96e3b50e0..84b517e44 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSFormFloatingActions.js
@@ -1,11 +1,8 @@
import React from 'react';
import { useFormikContext } from 'formik';
import { Intent, Button, Classes } from '@blueprintjs/core';
-import styled from 'styled-components';
-import { FormattedMessage as T } from 'components';
-
-import { safeCallback } from 'utils';
+import { DialogFooterActions, FormattedMessage as T } from 'components';
/**
*
@@ -21,7 +18,7 @@ export default function NotifyViaSMSFormFloatingActions({ onCancel }) {
return (
-
+
-
+
);
-}
-
-const FooterActions = styled.div`
- justify-content: flex-start;
-`;
+}
\ No newline at end of file
diff --git a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js
index a183e4bd9..8635fbf6d 100644
--- a/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js
+++ b/src/containers/Preferences/SMSIntegration/SMSMessagesDataTable.js
@@ -1,25 +1,53 @@
import React from 'react';
import styled from 'styled-components';
+import { Intent } from '@blueprintjs/core';
-import { DataTable } from 'components';
+import { DataTable, AppToaster } from 'components';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import { useSMSIntegrationTableColumns, ActionsMenu } from './components';
import { useSMSIntegrationContext } from './SMSIntegrationProvider';
+import { useSettingEditSMSNotification } from 'hooks/query';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
+/**
+ * SMS Message data table.
+ */
function SMSMessagesDataTable({
// #withDialogAction
openDialog,
}) {
+ // Edit SMS message notification mutations.
+ const { mutateAsync: editSMSNotificationMutate } =
+ useSettingEditSMSNotification();
+
+ // Handle notification switch change.
+ const handleNotificationSwitchChange = React.useCallback(
+ (event, value, notification) => {
+ editSMSNotificationMutate({
+ notification_key: notification.key,
+ is_notification_enabled: value,
+ }).then(() => {
+ AppToaster.show({
+ message: 'SMS notification hs been enabled successfully.',
+ intent: Intent.SUCCESS,
+ });
+ });
+ },
+ [editSMSNotificationMutate],
+ );
+
// Table columns.
- const columns = useSMSIntegrationTableColumns();
+ const columns = useSMSIntegrationTableColumns({
+ onSwitchChange: handleNotificationSwitchChange,
+ });
const { notifications, isSMSNotificationsLoading } =
useSMSIntegrationContext();
+ // handle edit message link click
const handleEditMessageText = ({ key }) => {
openDialog('sms-message-form', { notificationkey: key });
};
diff --git a/src/containers/Preferences/SMSIntegration/components.js b/src/containers/Preferences/SMSIntegration/components.js
index 3e59329ba..f1708574a 100644
--- a/src/containers/Preferences/SMSIntegration/components.js
+++ b/src/containers/Preferences/SMSIntegration/components.js
@@ -5,6 +5,7 @@ import { Menu, MenuItem } from '@blueprintjs/core';
import { ButtonLink } from 'components';
import { SwitchFieldCell } from 'components/DataTableCells';
+
import { safeInvoke } from 'utils';
/**
@@ -63,7 +64,7 @@ export function ActionsMenu({
* Retrieve SMS notifications messages table columns
* @returns
*/
-export function useSMSIntegrationTableColumns() {
+export function useSMSIntegrationTableColumns({ onSwitchChange }) {
return React.useMemo(
() => [
{
@@ -98,9 +99,10 @@ export function useSMSIntegrationTableColumns() {
disableResizing: true,
disableSortBy: true,
width: '80',
+ onSwitchChange,
},
],
- [],
+ [onSwitchChange],
);
}
diff --git a/src/hooks/query/settings.js b/src/hooks/query/settings.js
index 492ce6521..b7c70b335 100644
--- a/src/hooks/query/settings.js
+++ b/src/hooks/query/settings.js
@@ -1,4 +1,3 @@
-import { useEffect } from 'react';
import { useMutation, useQueryClient } from 'react-query';
import { useRequestQuery } from '../useQueryRequest';
import useApiRequest from '../useRequest';
From 3039e43767e7efd7eea9c7246b0b31f7d5897198 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 12:41:31 +0200
Subject: [PATCH 20/41] feat: SMS message text preview words break.
---
src/components/SMSPreview/index.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/components/SMSPreview/index.js b/src/components/SMSPreview/index.js
index 907d8274b..0b53aaf4b 100644
--- a/src/components/SMSPreview/index.js
+++ b/src/components/SMSPreview/index.js
@@ -27,13 +27,13 @@ export function SMSMessagePreview({
const SMSMessageText = styled.div`
position: absolute;
- top: 61px;
+ top: 60px;
padding: 12px;
color: #fff;
border-radius: 12px;
margin-left: 12px;
margin-right: 12px;
- overflow-wrap: break-word;
+ word-break: break-word;
background: #2fa2e4;
font-size: 13px;
line-height: 1.6;
From 9e5fddf294e888d4707d870d81c66a661bac1586 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 13:49:16 +0200
Subject: [PATCH 21/41] feat: SMS notification handle errors.
---
.../NotifyInvoiceViaSMSDialogContent.js | 4 +--
.../NotifyInvoiceViaSMSForm.js | 10 ++++---
.../NotifyInvoiceViaSMSFormProvider.js | 4 +++
.../NotifyInvoiceViaSMSDialog/index.js | 2 +-
.../NotifyViaSMS/NotifyViaSMSForm.js | 28 +++++++++++++++++--
src/containers/NotifyViaSMS/utils.js | 15 ++++------
6 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSDialogContent.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSDialogContent.js
index 88f75332d..349312e89 100644
--- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSDialogContent.js
+++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSDialogContent.js
@@ -6,11 +6,11 @@ import NotifyInvoiceViaSMSForm from './NotifyInvoiceViaSMSForm';
export default function NotifyInvoiceViaSMSDialogContent({
// #ownProps
dialogName,
- invoice,
+ invoiceId,
}) {
return (
diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
index 9cb293b73..604f0fd50 100644
--- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
+++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
@@ -33,6 +33,8 @@ function NotifyInvoiceViaSMSForm({
setNotificationType,
} = useNotifyInvoiceViaSMSContext();
+ const [calloutCode, setCalloutCode] = React.useState([]);
+
// Handles the form submit.
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
setSubmitting(true);
@@ -46,7 +48,6 @@ function NotifyInvoiceViaSMSForm({
setSubmitting(false);
closeDialog(dialogName);
};
-
// Handle request response errors.
const onError = ({
response: {
@@ -54,13 +55,14 @@ function NotifyInvoiceViaSMSForm({
},
}) => {
if (errors) {
- transformErrors(errors, { setErrors });
+ transformErrors(errors, { setErrors, setCalloutCode });
}
setSubmitting(false);
};
// Transformes the form values to request.
const requestValues = transformFormValuesToRequest(values);
+ // Submits invoice SMS notification.
createNotifyInvoiceBySMSMutate([invoiceId, requestValues])
.then(onSuccess)
.catch(onError);
@@ -74,7 +76,7 @@ function NotifyInvoiceViaSMSForm({
notification_key: notificationType,
...invoiceSMSDetail,
};
-
+ // Handle form values change.
const handleValuesChange = (values) => {
if (values.notification_key !== notificationType) {
setNotificationType(values.notification_key);
@@ -88,7 +90,6 @@ function NotifyInvoiceViaSMSForm({
],
[],
);
-
return (
);
}
diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSFormProvider.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSFormProvider.js
index c052dc274..9fdad5c56 100644
--- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSFormProvider.js
+++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSFormProvider.js
@@ -4,6 +4,9 @@ import { useCreateNotifyInvoiceBySMS, useInvoiceSMSDetail } from 'hooks/query';
const NotifyInvoiceViaSMSContext = React.createContext();
+/**
+ * Invoice SMS notification provider.
+ */
function NotifyInvoiceViaSMSFormProvider({ invoiceId, dialogName, ...props }) {
const [notificationType, setNotificationType] = React.useState('details');
@@ -16,6 +19,7 @@ function NotifyInvoiceViaSMSFormProvider({ invoiceId, dialogName, ...props }) {
},
{
enabled: !!invoiceId,
+ keepPreviousData: true,
},
);
// Create notfiy invoice by sms mutations.
diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/index.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/index.js
index 8951788cf..91f0c75e6 100644
--- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/index.js
+++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/index.js
@@ -26,7 +26,7 @@ function NotifyInvoiceViaSMSDialog({
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
index b3a55a835..3c7886876 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
@@ -1,8 +1,8 @@
import React from 'react';
-import { castArray } from 'lodash';
+import { castArray, includes } from 'lodash';
import { Formik, Form, useFormikContext } from 'formik';
import styled from 'styled-components';
-import { Classes } from '@blueprintjs/core';
+import { Callout, Classes, Intent } from '@blueprintjs/core';
import 'style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss';
@@ -53,6 +53,8 @@ function NotifyViaSMSForm({
onSubmit,
onCancel,
onValuesChange,
+ calloutCodes,
+ formikProps,
}) {
// Initial form values
const initialValues = {
@@ -67,6 +69,7 @@ function NotifyViaSMSForm({
return (
+
@@ -104,6 +108,26 @@ function NotifyObserveValuesChange({ onChange }) {
return ;
}
+/**
+ * Notify via SMS form alerts.
+ */
+function NotifyViaSMSAlerts({ calloutCodes }) {
+ return [
+ includes(calloutCodes, 100) && (
+
+ The customer phone number does not eixst, please enter a personal phone
+ number to the customer.
+
+ ),
+ includes(calloutCodes, 200) && (
+
+ The customer phone number is invalid, please enter a valid personal
+ phone number to the customer.
+
+ ),
+ ];
+}
+
export default NotifyViaSMSForm;
const NotifyContent = styled.div`
diff --git a/src/containers/NotifyViaSMS/utils.js b/src/containers/NotifyViaSMS/utils.js
index 33804e5c2..2d6b78593 100644
--- a/src/containers/NotifyViaSMS/utils.js
+++ b/src/containers/NotifyViaSMS/utils.js
@@ -1,16 +1,14 @@
-import { Intent } from '@blueprintjs/core';
-import { AppToaster } from 'components';
import intl from 'react-intl-universal';
-export const transformErrors = (errors, { setErrors }) => {
+export const transformErrors = (errors, { setErrors, setCalloutCode }) => {
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,
+ setCalloutCode([200]);
+ setErrors({
+ customer_phone_number: 'The personal phone number is invalid.',
});
}
-
if (errors.find((error) => error.type === 'CUSTOMER_HAS_NO_PHONE_NUMBER')) {
+ setCalloutCode([100]);
setErrors({
customer_phone_number: intl.get(
'notify_via_sms.dialog.customer_no_phone_error_message',
@@ -19,7 +17,6 @@ export const transformErrors = (errors, { setErrors }) => {
}
};
-
export const getSMSUnits = (message, threshold = 140) => {
return Math.ceil(message.length / threshold);
-};
\ No newline at end of file
+};
From 85f1c5584b130a159f3a3e656616ac2066c4b537 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 13:56:59 +0200
Subject: [PATCH 22/41] feat: SMS notification handle response errors.
---
.../Dialogs/SMSMessageDialog/utils.js | 20 +++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/containers/Dialogs/SMSMessageDialog/utils.js b/src/containers/Dialogs/SMSMessageDialog/utils.js
index b4f46f1f7..6b94176bd 100644
--- a/src/containers/Dialogs/SMSMessageDialog/utils.js
+++ b/src/containers/Dialogs/SMSMessageDialog/utils.js
@@ -1,15 +1,19 @@
import { Intent } from '@blueprintjs/core';
-import { AppToaster } from 'components';
-import intl from 'react-intl-universal';
+import { castArray } from 'lodash';
export const transformErrors = (errors, { setErrors }) => {
- if (
- errors.find((error) => error.type === 'UNSUPPORTED_SMS_MESSAGE_VARIABLES')
- ) {
+ let unsupportedVariablesError = errors.find(
+ (error) => error.type === 'UNSUPPORTED_SMS_MESSAGE_VARIABLES',
+ );
+ if (unsupportedVariablesError) {
+ const variables = castArray(
+ unsupportedVariablesError.data.unsupported_args,
+ );
+ const stringifiedVariables = variables.join(', ');
+
setErrors({
- message_text: intl.get(
- 'sms_message.dialog.unsupported_variables_error_message',
- ),
+ message_text: `The SMS message has unsupported variables - ${stringifiedVariables}`,
+ intent: Intent.DANGER,
});
}
};
From e205c0b9a3772f1438dd88b52798ca24a2ae5a30 Mon Sep 17 00:00:00 2001
From: elforjani13 <39470382+elforjani13@users.noreply.github.com>
Date: Tue, 9 Nov 2021 16:20:18 +0200
Subject: [PATCH 23/41] feat add localization.
---
.../NotifyInvoiceViaSMSForm.js | 2 +-
.../SMSMessageDialog/SMSMessageFormContent.js | 34 +++++++++---
.../SMSMessageFormFloatingActions.js | 8 +--
.../NotifyViaSMS/NotifyViaSMSForm.js | 10 ++--
.../NotifyViaSMS/NotifyViaSMSFormFields.js | 2 +-
.../NotifyViaSMSFormFloatingActions.js | 4 +-
src/containers/NotifyViaSMS/utils.js | 2 +-
.../SMSIntegration/SMSMessagesDataTable.js | 5 +-
.../Preferences/SMSIntegration/components.js | 4 +-
src/lang/ar/index.json | 25 +++++----
src/lang/en/index.json | 52 +++++++++++--------
11 files changed, 94 insertions(+), 54 deletions(-)
diff --git a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
index 9cb293b73..b3d33176d 100644
--- a/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
+++ b/src/containers/Dialogs/NotifyInvoiceViaSMSDialog/NotifyInvoiceViaSMSForm.js
@@ -40,7 +40,7 @@ function NotifyInvoiceViaSMSForm({
// Handle request response success.
const onSuccess = (response) => {
AppToaster.show({
- message: intl.get('notify_via_sms.dialog.success_message'),
+ message: intl.get('notify_invoice_via_sms.dialog.success_message'),
intent: Intent.SUCCESS,
});
setSubmitting(false);
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
index 8cfc998f5..6a8dcb293 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
@@ -1,4 +1,5 @@
import React from 'react';
+import intl from 'react-intl-universal';
import { Form, useFormikContext } from 'formik';
import styled from 'styled-components';
import { Classes } from '@blueprintjs/core';
@@ -9,6 +10,9 @@ import SMSMessageFormFloatingActions from './SMSMessageFormFloatingActions';
import { SMSMessagePreview } from 'components';
import { getSMSUnits } from '../../NotifyViaSMS/utils';
+import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
+import { compose } from 'utils';
+
const messageVariables = [
{
variable: '{CompanyName}',
@@ -19,7 +23,10 @@ const messageVariables = [
/**
* SMS message form content.
*/
-export default function SMSMessageFormContent() {
+function SMSMessageFormContent({
+ // #withCurrentOrganization
+ organization: { name },
+}) {
return (
@@ -87,7 +87,7 @@ export function useSMSIntegrationTableColumns({ onSwitchChange }) {
accessor: 'sms_message',
Cell: SMSMessageCell,
className: 'sms_message',
- clickable: true,
+ // clickable: true,
width: '180',
disableSortBy: true,
},
diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json
index af6998c5c..ab17a8691 100644
--- a/src/lang/ar/index.json
+++ b/src/lang/ar/index.json
@@ -1442,24 +1442,31 @@
"bad_debt.cancel_alert.message": "هل أنت متأكد أنك تريد شطب هذه الفاتورة؟ ",
"notify_via_sms.dialog.send_notification_to":"إرسال إشعار إلى ",
"notify_via_sms.dialog.message_text":"نص رسالة ",
+ "notify_via_sms.dialog.notification_type": "Notification type",
"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.",
+ "notiify_via_sms.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
+ "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",
"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_integration.label.overview":"Overview",
+ "sms_integration.label.sms_messages":"SMS Messages ",
"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_messages.label_edit_message": "Edit message",
+ "sms_messages.notification_switch_change_success_message":"SMS notification hs been enabled successfully.",
+ "sms_message.dialog.label": "SMS message",
+ "sms_message.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
+ "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":"تعديل نص رسالة",
- "enable_notification":"تفعيل الإشعارات"
+ "enable_notification":"تفعيل الإشعارات",
+ "send_sms":"Send SMS",
+ "save_sms_message":"Save SMS Message"
+
}
\ No newline at end of file
diff --git a/src/lang/en/index.json b/src/lang/en/index.json
index c15694cf0..83d78e1a7 100644
--- a/src/lang/en/index.json
+++ b/src/lang/en/index.json
@@ -1427,26 +1427,32 @@
"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.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_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"
-}
-
+ "notify_via_sms.dialog.send_notification_to": "Send notification to",
+ "notify_via_sms.dialog.message_text": "Message Text",
+ "notify_via_sms.dialog.notification_type": "Notification type",
+ "notify_via_sms.dialog.notify_via_sms": "Notify vis SMS",
+ "notiify_via_sms.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
+ "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.",
+ "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_messages.label_edit_message": "Edit message",
+ "sms_messages.notification_switch_change_success_message":"SMS notification hs been enabled successfully.",
+ "sms_message.dialog.label": "SMS message",
+ "sms_message.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
+ "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",
+ "send_sms":"Send SMS",
+ "save_sms_message":"Save SMS Message"
+}
\ No newline at end of file
From 5fcf32dcaae74b4c8f547df96576e89a054f0fc0 Mon Sep 17 00:00:00 2001
From: elforjani13 <39470382+elforjani13@users.noreply.github.com>
Date: Tue, 9 Nov 2021 16:39:13 +0200
Subject: [PATCH 24/41] feat add localization again.
---
src/containers/NotifyViaSMS/NotifyViaSMSForm.js | 6 ++----
src/lang/ar/index.json | 2 ++
src/lang/en/index.json | 10 ++++++----
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
index aec773b22..2f9721669 100644
--- a/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
+++ b/src/containers/NotifyViaSMS/NotifyViaSMSForm.js
@@ -119,14 +119,12 @@ function NotifyViaSMSAlerts({ calloutCodes }) {
return [
includes(calloutCodes, 100) && (
- The customer phone number does not eixst, please enter a personal phone
- number to the customer.
+ {intl.get('notify_Via_sms.dialog.customer_phone_number_does_not_eixst')}
),
includes(calloutCodes, 200) && (
- The customer phone number is invalid, please enter a valid personal
- phone number to the customer.
+ {intl.get('notify_Via_sms.dialog.customer_phone_number_invalid')}
),
];
diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json
index ab17a8691..2cded970e 100644
--- a/src/lang/ar/index.json
+++ b/src/lang/ar/index.json
@@ -1445,6 +1445,8 @@
"notify_via_sms.dialog.notification_type": "Notification type",
"notify_via_sms.dialog.notify_via_sms":"Notify vis SMS",
"notiify_via_sms.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
+ "notify_Via_sms.dialog.customer_phone_number_does_not_eixst": "The customer phone number does not eixst, please enter a personal phone number to the customer.",
+ "notify_Via_sms.dialog.customer_phone_number_invalid": "The customer phone number is invalid, please enter a valid personal phone number to the customer.",
"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",
diff --git a/src/lang/en/index.json b/src/lang/en/index.json
index 83d78e1a7..95c5da654 100644
--- a/src/lang/en/index.json
+++ b/src/lang/en/index.json
@@ -1432,6 +1432,8 @@
"notify_via_sms.dialog.notification_type": "Notification type",
"notify_via_sms.dialog.notify_via_sms": "Notify vis SMS",
"notiify_via_sms.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
+ "notify_Via_sms.dialog.customer_phone_number_does_not_eixst": "The customer phone number does not eixst, please enter a personal phone number to the customer.",
+ "notify_Via_sms.dialog.customer_phone_number_invalid": "The customer phone number is invalid, please enter a valid personal phone number to the customer.",
"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.",
@@ -1445,14 +1447,14 @@
"sms_messages.label_mesage": "Message",
"sms_messages.label_auto": "Auto",
"sms_messages.label_edit_message": "Edit message",
- "sms_messages.notification_switch_change_success_message":"SMS notification hs been enabled successfully.",
+ "sms_messages.notification_switch_change_success_message": "SMS notification hs been enabled successfully.",
"sms_message.dialog.label": "SMS message",
"sms_message.dialog.sms_note": "
Note : One SMS unit can contain amaximum of 160 characters.
{value} SMS units will be used to send this SMS notification.",
"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.",
+ "sms_message.dialog.message_variable_description": "
{value} References to the current company name.",
"edit_message_text": "Edit message text",
"enable_notification": "Enable notification",
- "send_sms":"Send SMS",
- "save_sms_message":"Save SMS Message"
+ "send_sms": "Send SMS",
+ "save_sms_message": "Save SMS Message"
}
\ No newline at end of file
From 5a8c61396f93dc8f980dd156405a5494e3415646 Mon Sep 17 00:00:00 2001
From: "a.bouhuolia"
Date: Tue, 9 Nov 2021 18:16:09 +0200
Subject: [PATCH 25/41] feat: SMS message preview with variables.
---
.../SMSMessageDialogContent.js | 3 +++
.../SMSMessageDialogProvider.js | 1 +
.../SMSMessageDialog/SMSMessageFormContent.js | 20 +++++++++++--------
.../SMSMessageFormFloatingActions.js | 6 +++---
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogContent.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogContent.js
index 134a42f48..b7cedf1b3 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogContent.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogContent.js
@@ -4,6 +4,9 @@ import '../../../style/pages/SMSMessage/SMSMessage.scss';
import { SMSMessageDialogProvider } from './SMSMessageDialogProvider';
import SMSMessageForm from './SMSMessageForm';
+/**
+ * SMS message dialog content.
+ */
export default function SMSMessageDialogContent({
// #ownProps
dialogName,
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogProvider.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogProvider.js
index 28c6b180f..8aedd7e53 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogProvider.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageDialogProvider.js
@@ -15,6 +15,7 @@ function SMSMessageDialogProvider({ notificationkey, dialogName, ...props }) {
const { mutateAsync: editSMSNotificationMutate } =
useSettingEditSMSNotification();
+ // SMS notificiation details
const { data: smsNotification, isLoading: isSMSNotificationLoading } =
useSettingSMSNotification(notificationkey);
diff --git a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
index 8cfc998f5..dc28ac84f 100644
--- a/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
+++ b/src/containers/Dialogs/SMSMessageDialog/SMSMessageFormContent.js
@@ -2,24 +2,28 @@ import React from 'react';
import { Form, useFormikContext } from 'formik';
import styled from 'styled-components';
import { Classes } from '@blueprintjs/core';
+import { castArray } from 'lodash';
import SMSMessageFormFields from './SMSMessageFormFields';
import SMSMessageFormFloatingActions from './SMSMessageFormFloatingActions';
+import { useSMSMessageDialogContext } from './SMSMessageDialogProvider';
import { SMSMessagePreview } from 'components';
import { getSMSUnits } from '../../NotifyViaSMS/utils';
-const messageVariables = [
- {
- variable: '{CompanyName}',
- description: 'References to the current company name.',
- },
-];
-
/**
* SMS message form content.
*/
export default function SMSMessageFormContent() {
+ // SMS message dialog context.
+ const { smsNotification } = useSMSMessageDialogContext();
+
+ // Ensure always returns array.
+ const messageVariables = React.useMemo(
+ () => castArray(smsNotification.allowed_variables),
+ [smsNotification.allowed_variables],
+ );
+
return (