refactor notifications service
This commit is contained in:
1 parent
5b43d9d173
commit
d627a25b40
13 files changed
+132
-47
No files matched your search
@@ -31,7 +31,7 @@ const NotificationConfig = ({
|
||||
setMonitor((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
notifications: value.map((notification) => notification._id),
|
||||
notifications: value.map((notification) => notification.id),
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -39,14 +39,14 @@ const NotificationConfig = ({
|
||||
// Handlers
|
||||
const handleDelete = (id) => {
|
||||
const updatedNotifications = selectedNotifications.filter(
|
||||
(notification) => notification._id !== id
|
||||
(notification) => notification.id !== id
|
||||
);
|
||||
|
||||
setSelectedNotifications(updatedNotifications);
|
||||
setMonitor((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
notifications: updatedNotifications.map((notification) => notification._id),
|
||||
notifications: updatedNotifications.map((notification) => notification.id),
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -57,7 +57,7 @@ const NotificationConfig = ({
|
||||
useEffect(() => {
|
||||
if (setNotifications) {
|
||||
const toSet = setNotifications.map((notification) => {
|
||||
return notifications.find((n) => n._id === notification);
|
||||
return notifications.find((n) => n.id === notification);
|
||||
});
|
||||
setSelectedNotifications(toSet);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ const NotificationConfig = ({
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
key={notification._id}
|
||||
key={notification.id}
|
||||
width="100%"
|
||||
>
|
||||
<Typography
|
||||
@@ -106,7 +106,7 @@ const NotificationConfig = ({
|
||||
name="Trash2"
|
||||
size={20}
|
||||
onClick={() => {
|
||||
handleDelete(notification._id);
|
||||
handleDelete(notification.id);
|
||||
}}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
|
||||
@@ -102,7 +102,7 @@ const useGetNotificationById = (id, setNotification) => {
|
||||
const notificationData = {
|
||||
address: notification?.address,
|
||||
notificationName: notification?.notificationName,
|
||||
type: NOTIFICATION_TYPES.find((type) => type.value === notification?.type)?._id,
|
||||
type: NOTIFICATION_TYPES.find((type) => type.value === notification?.type)?.id,
|
||||
};
|
||||
|
||||
setNotification(notificationData);
|
||||
|
||||
@@ -32,13 +32,13 @@ const ActionMenu = ({ notification, onDelete }) => {
|
||||
|
||||
const handleRemove = (e) => {
|
||||
e.stopPropagation();
|
||||
onDelete(notification._id);
|
||||
onDelete(notification.id);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleConfigure = (e) => {
|
||||
e.stopPropagation();
|
||||
navigate(`/notifications/${notification._id}`);
|
||||
navigate(`/notifications/${notification.id}`);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ const CreateNotifications = () => {
|
||||
const [notification, setNotification] = useState({
|
||||
notificationName: "",
|
||||
address: "",
|
||||
type: NOTIFICATION_TYPES[0]._id,
|
||||
type: NOTIFICATION_TYPES[0].id,
|
||||
});
|
||||
const [errors, setErrors] = useState({});
|
||||
const { t } = useTranslation();
|
||||
@@ -66,7 +66,7 @@ const CreateNotifications = () => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const getNotificationTypeValue = (typeId) => {
|
||||
return NOTIFICATION_TYPES.find((type) => type._id === typeId)?.value || "email";
|
||||
return NOTIFICATION_TYPES.find((type) => type.id === typeId)?.value || "email";
|
||||
};
|
||||
|
||||
const extractError = (error, field) =>
|
||||
|
||||
@@ -100,7 +100,7 @@ const Notifications = () => {
|
||||
<Typography variant="h1">{t("notifications.createTitle")}</Typography>
|
||||
<DataTable
|
||||
config={{
|
||||
onRowClick: (row) => navigate(`/notifications/${row._id}`),
|
||||
onRowClick: (row) => navigate(`/notifications/${row.id}`),
|
||||
rowSX: {
|
||||
cursor: "pointer",
|
||||
"&:hover td": {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export const NOTIFICATION_TYPES = [
|
||||
{ _id: 1, name: "E-mail", value: "email" },
|
||||
{ _id: 2, name: "Slack", value: "slack" },
|
||||
{ _id: 3, name: "PagerDuty", value: "pager_duty" },
|
||||
{ _id: 4, name: "Webhook", value: "webhook" },
|
||||
{ _id: 5, name: "Discord", value: "discord" },
|
||||
{ _id: 6, name: "Matrix", value: "matrix" },
|
||||
{ id: 1, name: "E-mail", value: "email" },
|
||||
{ id: 2, name: "Slack", value: "slack" },
|
||||
{ id: 3, name: "PagerDuty", value: "pager_duty" },
|
||||
{ id: 4, name: "Webhook", value: "webhook" },
|
||||
{ id: 5, name: "Discord", value: "discord" },
|
||||
{ id: 6, name: "Matrix", value: "matrix" },
|
||||
];
|
||||
|
||||
export const TITLE_MAP = {
|
||||
|
||||
Reference in new issue
Block a user