import React, { useState, FC, useEffect } from 'react'; import { useAsyncFn } from 'react-use'; import { getBackendSrv } from '@grafana/runtime'; import { HorizontalGroup, Button, LinkButton } from '@grafana/ui'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import Page from 'app/core/components/Page/Page'; import { appEvents } from 'app/core/core'; import { useNavModel } from 'app/core/hooks/useNavModel'; import { AlertNotification } from 'app/types/alerting'; import { ShowConfirmModalEvent } from '../../types/events'; const NotificationsListPage: FC = () => { const navModel = useNavModel('channels'); const [notifications, setNotifications] = useState([]); const getNotifications = async () => { return await getBackendSrv().get(`/api/alert-notifications`); }; const [state, fetchNotifications] = useAsyncFn(getNotifications); useEffect(() => { fetchNotifications().then((res) => { setNotifications(res); }); }, [fetchNotifications]); const deleteNotification = (id: number) => { appEvents.publish( new ShowConfirmModalEvent({ title: 'Delete', text: 'Do you want to delete this notification channel?', text2: `Deleting this notification channel will not delete from alerts any references to it`, icon: 'trash-alt', confirmText: 'Delete', yesText: 'Delete', onConfirm: async () => { deleteNotificationConfirmed(id); }, }) ); }; const deleteNotificationConfirmed = async (id: number) => { await getBackendSrv().delete(`/api/alert-notifications/${id}`); const notifications = await fetchNotifications(); setNotifications(notifications); }; return ( {state.error &&

{state.error}

} {!!notifications.length && ( <>
New channel
{notifications.map((notification) => ( ))}
Name Type
{notification.name} {notification.type} {notification.isDefault && ( )}
)} {!(notifications.length || state.loading) && ( )} ); }; export default NotificationsListPage;