mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
Merge branch 'feature/notify-via-SMS' of https://github.com/bigcapitalhq/client into feature/notify-via-SMS
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -53,7 +53,9 @@ function NotifyInvoiceViaSMSForm({
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
transformErrors(errors);
|
||||
if (errors) {
|
||||
transformErrors(errors, { setErrors });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
// Transformes the form values to request.
|
||||
|
||||
@@ -44,7 +44,10 @@ function NotifyPaymentReceiveViaSMSForm({
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
transformErrors(errors);
|
||||
if (errors) {
|
||||
transformErrors(errors, { setErrors });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
createNotifyPaymentReceivetBySMSMutate([paymentReceiveId, values])
|
||||
.then(onSuccess)
|
||||
|
||||
@@ -42,7 +42,10 @@ function NotifyReceiptViaSMSForm({
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
transformErrors(errors);
|
||||
if (errors) {
|
||||
transformErrors(errors, { setErrors });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
createNotifyReceiptBySMSMutate([receiptId, values])
|
||||
.then(onSuccess)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -20,7 +20,7 @@ function SMSMessageDialog({
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={intl.get('sms_message')}
|
||||
title={intl.get('sms_message.dialog.label')}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
|
||||
15
src/containers/Dialogs/SMSMessageDialog/utils.js
Normal file
15
src/containers/Dialogs/SMSMessageDialog/utils.js
Normal file
@@ -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',
|
||||
),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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',
|
||||
),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<SMSNotificationsTable
|
||||
columns={columns}
|
||||
@@ -32,8 +34,10 @@ function SMSMessagesDataTable({
|
||||
progressBarLoading={isSMSNotificationsLoading}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
noInitialFetch={true}
|
||||
ContextMenu={ActionsMenu}
|
||||
payload={{
|
||||
onEditSMSMessage: handleEditSMSMessage,
|
||||
onEditMessageText: handleEditMessageText,
|
||||
onEnableNotification: handleEnableNotification,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -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 },
|
||||
}) => (
|
||||
<div>
|
||||
<MessageBox>{original.sms_message}</MessageBox>
|
||||
<MessageBoxActions>
|
||||
<ButtonLink onClick={() => safeInvoke(onEditSMSMessage, original)}>
|
||||
<ButtonLink onClick={() => safeInvoke(onEditMessageText, original)}>
|
||||
Edit message
|
||||
</ButtonLink>
|
||||
</MessageBoxActions>
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* Context menu of SMS notification messages.
|
||||
*/
|
||||
export function ActionsMenu({
|
||||
payload: { onEditMessageText, onEnableNotification },
|
||||
row: { original },
|
||||
}) {
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={intl.get('edit_message_text')}
|
||||
onClick={safeInvoke(onEditMessageText, original)}
|
||||
/>
|
||||
<MenuItem
|
||||
text={intl.get('enable_notification')}
|
||||
onClick={safeInvoke(onEnableNotification, original)}
|
||||
/>
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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":"تفعيل الإشعارات"
|
||||
}
|
||||
@@ -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."
|
||||
}
|
||||
"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"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user