feat: add context menu in sms message table.

This commit is contained in:
elforjani13
2021-11-08 16:41:36 +02:00
parent 8c2d138976
commit 7a1c9caa70
5 changed files with 45 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ function SMSMessageDialog({
return ( return (
<Dialog <Dialog
name={dialogName} name={dialogName}
title={intl.get('sms_message')} title={intl.get('sms_message.dialog.label')}
isOpen={isOpen} isOpen={isOpen}
canEscapeJeyClose={true} canEscapeJeyClose={true}
autoFocus={true} autoFocus={true}

View File

@@ -2,7 +2,7 @@ import React from 'react';
import { DataTableEditable, DataTable } from 'components'; import { DataTableEditable, DataTable } from 'components';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import { useSMSIntegrationTableColumns } from './components'; import { useSMSIntegrationTableColumns, ActionsMenu } from './components';
import { useSMSIntegrationContext } from './SMSIntegrationProvider'; import { useSMSIntegrationContext } from './SMSIntegrationProvider';
import withDialogActions from 'containers/Dialog/withDialogActions'; import withDialogActions from 'containers/Dialog/withDialogActions';
@@ -18,10 +18,12 @@ function SMSMessagesDataTable({
const { notifications, isSMSNotificationsLoading } = const { notifications, isSMSNotificationsLoading } =
useSMSIntegrationContext(); useSMSIntegrationContext();
const handleEditSMSMessage = ({ key }) => { const handleEditMessageText = ({ key }) => {
openDialog('sms-message-form', { notificationkey: key }); openDialog('sms-message-form', { notificationkey: key });
}; };
const handleEnableNotification = () => {};
return ( return (
<DataTable <DataTable
columns={columns} columns={columns}
@@ -30,8 +32,10 @@ function SMSMessagesDataTable({
progressBarLoading={isSMSNotificationsLoading} progressBarLoading={isSMSNotificationsLoading}
TableLoadingRenderer={TableSkeletonRows} TableLoadingRenderer={TableSkeletonRows}
noInitialFetch={true} noInitialFetch={true}
ContextMenu={ActionsMenu}
payload={{ payload={{
onEditSMSMessage: handleEditSMSMessage, onEditMessageText: handleEditMessageText,
onEnableNotification: handleEnableNotification,
}} }}
/> />
); );

View File

@@ -1,8 +1,27 @@
import React from 'react'; import React from 'react';
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import { Menu, MenuItem, MenuDivider } from '@blueprintjs/core';
import { SwitchFieldCell } from 'components/DataTableCells'; import { SwitchFieldCell } from 'components/DataTableCells';
import { safeCallback } from 'utils'; import { safeCallback } from 'utils';
export function ActionsMenu({
payload: { onEditMessageText, onEnableNotification },
row: { original },
}) {
return (
<Menu>
<MenuItem
text={intl.get('edit_message_text')}
onClick={safeCallback(onEditMessageText, original)}
/>
<MenuItem
text={intl.get('enable_notification')}
onClick={safeCallback(onEnableNotification, original)}
/>
</Menu>
);
}
/** /**
* Notification accessor. * Notification accessor.
*/ */
@@ -18,14 +37,14 @@ export const NotificationAccessor = (row) => {
}; };
export const SMSMessageCell = ({ export const SMSMessageCell = ({
payload: { onEditSMSMessage }, payload: { onEditMessageText },
row: { original }, row: { original },
}) => ( }) => (
<div> <div>
{original.sms_message} {original.sms_message}
<span <span
className="edit-text" className="edit-text"
onClick={safeCallback(onEditSMSMessage, original)} onClick={safeCallback(onEditMessageText, original)}
> >
{'Edit'} {'Edit'}
</span> </span>
@@ -35,7 +54,7 @@ export const SMSMessageCell = ({
export function useSMSIntegrationTableColumns() { export function useSMSIntegrationTableColumns() {
return React.useMemo(() => [ return React.useMemo(() => [
{ {
Header: intl.get('sms_message.label_Notification'), Header: intl.get('sms_messages.label_notification'),
accessor: NotificationAccessor, accessor: NotificationAccessor,
className: 'notification', className: 'notification',
width: '180', width: '180',
@@ -49,7 +68,7 @@ export function useSMSIntegrationTableColumns() {
disableSortBy: true, disableSortBy: true,
}, },
{ {
Header: intl.get('sms_message.label_mesage'), Header: intl.get('sms_messages.label_mesage'),
accessor: 'sms_message', accessor: 'sms_message',
Cell: SMSMessageCell, Cell: SMSMessageCell,
className: 'sms_message', className: 'sms_message',
@@ -58,7 +77,7 @@ export function useSMSIntegrationTableColumns() {
disableSortBy: true, disableSortBy: true,
}, },
{ {
Header: intl.get('sms_message.label_auto'), Header: intl.get('sms_messages.label_auto'),
accessor: 'is_notification_enabled', accessor: 'is_notification_enabled',
Cell: SwitchFieldCell, Cell: SwitchFieldCell,
className: 'is_notification_enabled', className: 'is_notification_enabled',

View File

@@ -1455,9 +1455,11 @@
"sms_integration.label.overview":"نظرة عامة", "sms_integration.label.overview":"نظرة عامة",
"sms_integration.label.sms_messages":"رسائل SMS ", "sms_integration.label.sms_messages":"رسائل SMS ",
"sms_message.label.sms_messages_template":" إشعارات رسائل قصيرة ", "sms_message.label.sms_messages_template":" إشعارات رسائل قصيرة ",
"sms_message.label_mesage":"رسالة ", "sms_messages.label_mesage":"رسالة ",
"sms_message.label_Notification":"إشعار", "sms_messages.label_notification":"إشعار",
"sms_message.label_auto":"Auto", "sms_messages.label_auto":"Auto",
"sms_message":"رسالة SMS" , "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":"تفعيل الإشعارات"
} }

View File

@@ -1440,12 +1440,13 @@
"sms_integration.label":"SMS Integration", "sms_integration.label":"SMS Integration",
"sms_integration.label.overview":"Overview", "sms_integration.label.overview":"Overview",
"sms_integration.label.sms_messages":"SMS Messages", "sms_integration.label.sms_messages":"SMS Messages",
"sms_message.label.sms_messages_template":"SMS Notifications ", "sms_messages.label_notification":"Notification",
"sms_message.label_mesage":"Message", "sms_messages.label_mesage":"Message",
"sms_message.label_Notification":"Notification", "sms_messages.label_auto":"Auto",
"sms_message.label_auto":"Auto", "sms_message.dialog.label":"SMS message",
"sms_message":"SMS message",
"sms_message.dialog.success_message":"Sms notification settings has been updated successfully.", "sms_message.dialog.success_message":"Sms notification settings has been updated successfully.",
"sms_message.dialog.unsupported_variables_error_message":"Unsupported variables" "sms_message.dialog.unsupported_variables_error_message":"Unsupported variables",
"edit_message_text":"Edit message text",
"enable_notification":"Enable notification"
} }