diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index ec7327d23..541f1f218 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -1,19 +1,10 @@ import { cookies } from "next/headers" import { DefaultQueryClientProvider } from "@/providers/query" -import { Label } from "@/components/ui/label" import { Metadata } from "next" import { SelectedWorkflowProvider } from "@/providers/selected-workflow" -import { Switch } from "@/components/ui/switch" -import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs" -import { UserNav } from "@/components/user-nav" import { Workspace } from "@/components/workspace" -import WorkflowSwitcher from "@/components/workflow-switcher" - -import { - WorkflowIcon, - BellRingIcon, -} from "lucide-react" +import { Navbar } from "@/components/navbar" export const metadata: Metadata = { title: "Workflows | Tracecat", @@ -42,32 +33,7 @@ export default function DashboardPage() {
-
-
-
- - - - - - Workflow - - - - Cases - - - -
-
-
- - -
- -
-
-
+

Workflow Status

- + - {statusCapitalized} + {statusCapitalized} diff --git a/frontend/src/components/navbar.tsx b/frontend/src/components/navbar.tsx new file mode 100644 index 000000000..a2847dc69 --- /dev/null +++ b/frontend/src/components/navbar.tsx @@ -0,0 +1,79 @@ +"use client"; + +import { useEffect, useState } from "react" +import axios from "axios" + +import { Label } from "@/components/ui/label" +import { Switch } from "@/components/ui/switch" +import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs" +import { UserNav } from "@/components/user-nav" +import WorkflowSwitcher from "@/components/workflow-switcher" +import { useSelectedWorkflowMetadata } from "@/providers/selected-workflow" + +import { + WorkflowIcon, + BellRingIcon, +} from "lucide-react" + + +export function Navbar() { + + const { selectedWorkflowMetadata } = useSelectedWorkflowMetadata(); // This assumes the existence of such a hook + const [enableWorkflow, setEnableWorkflow] = useState(false); + const selectedWorkflowId = selectedWorkflowMetadata.id; + + useEffect(() => { + const updateWorkflowStatus = async () => { + if (selectedWorkflowMetadata && selectedWorkflowId) { + const status = enableWorkflow ? "online" : "offline"; + try { + await axios.post(`http://localhost:8000/workflows/${selectedWorkflowId}`, JSON.stringify({ + status: status, + }), { + headers: { + "Content-Type": "application/json", + }, + }); + console.log(`Workflow ${selectedWorkflowId} set to ${status}`); + } catch (error) { + console.error("Failed to update workflow status:", error); + } + } + }; + + updateWorkflowStatus(); + }, [enableWorkflow, selectedWorkflowMetadata]); + + return ( +
+
+
+ + + + + + Workflow + + + + Cases + + + +
+
+
+ setEnableWorkflow(newCheckedState)} + /> + +
+ +
+
+
+ ) +}