fix: SMS notification messages context menu.

This commit is contained in:
a.bouhuolia
2021-11-11 12:46:58 +02:00
parent 307aaf0aa4
commit 35d755e417
6 changed files with 64 additions and 37 deletions

View File

@@ -24,20 +24,24 @@ function SMSMessagesDataTable({
const { mutateAsync: editSMSNotificationMutate } =
useSettingEditSMSNotification();
const toggleSmsNotification = (notificationKey, value) => {
editSMSNotificationMutate({
notification_key: notificationKey,
is_notification_enabled: value,
}).then(() => {
AppToaster.show({
message: intl.get(
'sms_messages.notification_switch_change_success_message',
),
intent: Intent.SUCCESS,
});
});
};
// Handle notification switch change.
const handleNotificationSwitchChange = React.useCallback(
(event, value, notification) => {
editSMSNotificationMutate({
notification_key: notification.key,
is_notification_enabled: value,
}).then(() => {
AppToaster.show({
message: intl.get(
'sms_messages.notification_switch_change_success_message',
),
intent: Intent.SUCCESS,
});
});
toggleSmsNotification(notification.key, value);
},
[editSMSNotificationMutate],
);
@@ -47,28 +51,37 @@ function SMSMessagesDataTable({
onSwitchChange: handleNotificationSwitchChange,
});
const { notifications, isSMSNotificationsLoading } =
useSMSIntegrationContext();
const {
notifications,
isSMSNotificationsLoading,
isSMSNotificationsFetching,
} = useSMSIntegrationContext();
// handle edit message link click
const handleEditMessageText = ({ key }) => {
openDialog('sms-message-form', { notificationkey: key });
};
const handleEnableNotification = () => {};
const handleEnableNotification = (notification) => {
toggleSmsNotification(notification.key, true);
};
const handleDisableNotification = (notification) => {
toggleSmsNotification(notification.key, false);
};
return (
<SMSNotificationsTable
columns={columns}
data={notifications}
loading={isSMSNotificationsLoading}
progressBarLoading={isSMSNotificationsLoading}
progressBarLoading={isSMSNotificationsFetching}
TableLoadingRenderer={TableSkeletonRows}
noInitialFetch={true}
ContextMenu={ActionsMenu}
payload={{
onEditMessageText: handleEditMessageText,
onEnableNotification: handleEnableNotification,
onDisableNotification: handleDisableNotification,
}}
/>
);