diff --git a/frontend/src/container/AllAlertChannels/AlertChannels.tsx b/frontend/src/container/AllAlertChannels/AlertChannels.tsx index 00335f1367..5cb65fd669 100644 --- a/frontend/src/container/AllAlertChannels/AlertChannels.tsx +++ b/frontend/src/container/AllAlertChannels/AlertChannels.tsx @@ -7,7 +7,7 @@ import useComponentPermission from 'hooks/useComponentPermission'; import { useNotifications } from 'hooks/useNotifications'; import history from 'lib/history'; import { useAppContext } from 'providers/App/App'; -import { useCallback, useState } from 'react'; +import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { generatePath } from 'react-router-dom'; import { Channels } from 'types/api/channels/getAll'; @@ -17,7 +17,6 @@ import Delete from './Delete'; function AlertChannels({ allChannels }: AlertChannelsProps): JSX.Element { const { t } = useTranslation(['channels']); const { notifications } = useNotifications(); - const [channels, setChannels] = useState(allChannels); const { user } = useAppContext(); const [action] = useComponentPermission(['new_alert_action'], user.role); @@ -56,14 +55,19 @@ function AlertChannels({ allChannels }: AlertChannelsProps): JSX.Element { - + ), }); } return ( - + ); } diff --git a/frontend/src/container/AllAlertChannels/Delete.tsx b/frontend/src/container/AllAlertChannels/Delete.tsx index 2c617af109..ba734d3c4e 100644 --- a/frontend/src/container/AllAlertChannels/Delete.tsx +++ b/frontend/src/container/AllAlertChannels/Delete.tsx @@ -1,14 +1,15 @@ import { Button } from 'antd'; import { NotificationInstance } from 'antd/es/notification/interface'; import deleteChannel from 'api/channels/delete'; -import { Dispatch, SetStateAction, useState } from 'react'; +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Channels } from 'types/api/channels/getAll'; +import { useQueryClient } from 'react-query'; import APIError from 'types/api/error'; -function Delete({ notifications, setChannels, id }: DeleteProps): JSX.Element { +function Delete({ notifications, id }: DeleteProps): JSX.Element { const { t } = useTranslation(['channels']); const [loading, setLoading] = useState(false); + const queryClient = useQueryClient(); const onClickHandler = async (): Promise => { try { @@ -21,7 +22,8 @@ function Delete({ notifications, setChannels, id }: DeleteProps): JSX.Element { message: 'Success', description: t('channel_delete_success'), }); - setChannels((preChannels) => preChannels.filter((e) => e.id !== id)); + // Invalidate and refetch + queryClient.invalidateQueries(['getChannels']); setLoading(false); } catch (error) { notifications.error({ @@ -46,7 +48,6 @@ function Delete({ notifications, setChannels, id }: DeleteProps): JSX.Element { interface DeleteProps { notifications: NotificationInstance; - setChannels: Dispatch>; id: string; }