diff --git a/dashboard/components/inventory/components/view/alerts/hooks/useSlackAlerts.tsx b/dashboard/components/inventory/components/view/alerts/hooks/useSlackAlerts.tsx deleted file mode 100644 index 566bf4836..000000000 --- a/dashboard/components/inventory/components/view/alerts/hooks/useSlackAlerts.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import { useEffect, useState } from 'react'; -import settingsService from '../../../../../../services/settingsService'; - -type useSlackAlertsProps = { - viewId: number; -}; - -export type SlackAlert = { - id: number; - name: string; - viewId: string; - type: 'BUDGET' | 'USAGE'; - budget?: number | string; - usage?: number | string; - IsSlack?: boolean; - endpoint?: string; - secret?: string; -}; - -function useSlackAlerts({ viewId }: useSlackAlertsProps) { - const [loading, setLoading] = useState(true); - const [error, setError] = useState(false); - const [hasSlack, setHasSlack] = useState(false); - const [slackAlerts, setSlackAlerts] = useState(); - const [editSlackAlert, setEditSlackAlert] = useState(false); - const [currentSlackAlert, setCurrentSlackAlert] = useState(); - - function fetchSlackStatus() { - if (!loading) { - setLoading(true); - } - - if (error) { - setError(false); - } - - settingsService.getSlackIntegration().then(res => { - if (res === Error) { - setLoading(false); - setError(true); - } else { - setLoading(false); - setHasSlack(res.enabled); - } - }); - } - - function fetchViewAlerts() { - if (!loading) { - setLoading(true); - } - - if (error) { - setError(false); - } - - settingsService.getSlackAlertsFromAView(viewId).then(res => { - if (res === Error) { - setLoading(false); - setError(true); - } else { - setLoading(false); - setSlackAlerts(res); - } - }); - } - - function createOrEditSlackAlert(alertId?: number) { - if (alertId && slackAlerts) { - const foundSlackAlert = slackAlerts.find(alert => alert.id === alertId); - - if (foundSlackAlert) { - setCurrentSlackAlert(foundSlackAlert); - } - } - setEditSlackAlert(true); - } - - function closeSlackAlert(action?: 'hasChanges') { - setCurrentSlackAlert(undefined); - setEditSlackAlert(false); - - if (action === 'hasChanges') { - fetchViewAlerts(); - } - } - - useEffect(() => { - if (!hasSlack) { - fetchSlackStatus(); - } - - if (hasSlack && viewId) { - fetchViewAlerts(); - } - }, [hasSlack]); - - const hasNoSlackAlerts = - hasSlack && !editSlackAlert && slackAlerts && slackAlerts.length === 0; - - return { - loading, - error, - hasSlack, - slackAlerts, - hasNoSlackAlerts, - editSlackAlert, - currentSlackAlert, - createOrEditSlackAlert, - closeSlackAlert, - fetchViewAlerts - }; -} - -export default useSlackAlerts;