diff --git a/src/app/crews/[id]/manage/page.tsx b/src/app/crews/[id]/manage/page.tsx index ea2c6ddb..99d75d1a 100644 --- a/src/app/crews/[id]/manage/page.tsx +++ b/src/app/crews/[id]/manage/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect } from "react"; +import { useState, useEffect, useCallback } from "react"; import { useParams, useRouter } from "next/navigation"; import { supabase } from "@/utils/supabase/client"; import AgentManagement from "@/components/agents/AgentManagement"; @@ -8,7 +8,13 @@ import TaskManagement from "@/components/tasks/TaskManagement"; import { Card, CardContent } from "@/components/ui/card"; import { Agent, CrewWithCron, Task } from "@/types/supabase"; import { Switch } from "@/components/ui/switch"; -import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip"; + +import { + TooltipProvider, + Tooltip, + TooltipTrigger, + TooltipContent, +} from "@/components/ui/tooltip"; import { HelpCircle, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; @@ -44,16 +50,69 @@ export default function CrewDetails() { const [editForm, setEditForm] = useState({ name: "", description: "", - is_public: false + is_public: false, }); const [cronInput, setCronInput] = useState(""); const [cronEnabled, setCronEnabled] = useState(false); const [cronId, setCronId] = useState(0); + const fetchAgents = useCallback(async () => { + try { + const { data, error } = await supabase + .from("agents") + .select("*") + .eq("crew_id", id); + + if (error) throw error; + + setAgents(data || []); + } catch (error) { + console.error("Error fetching agents:", error); + toast({ + title: "Error", + description: "Failed to fetch agents.", + variant: "destructive", + }); + } + }, [id, toast]); + + useEffect(() => { + if (id) { + fetchAgents(); + } + }, [id, fetchAgents]); + + const fetchTasks = useCallback(async () => { + try { + const { data, error } = await supabase + .from("tasks") + .select("*") + .eq("crew_id", id); + + if (error) throw error; + + setTasks(data || []); + } catch (error) { + console.error("Error fetching tasks:", error); + toast({ + title: "Error", + description: "Failed to fetch tasks.", + variant: "destructive", + }); + } + }, [id, toast]); + + useEffect(() => { + fetchTasks(); + }, [fetchTasks]); + // Fetch current user useEffect(() => { async function fetchUser() { - const { data: { user }, error } = await supabase.auth.getUser(); + const { + data: { user }, + error, + } = await supabase.auth.getUser(); if (error) { console.error("Error fetching user:", error); return; @@ -69,21 +128,17 @@ export default function CrewDetails() { useEffect(() => { async function fetchData() { try { - const [crewResponse, agentsResponse, tasksResponse] = await Promise.all([ - supabase - .from("crews") - .select(`*, crons(id, enabled, input, created_at)`) - .eq("id", id) - .single(), - supabase - .from("agents") - .select("*") - .eq("crew_id", id), - supabase - .from("tasks") - .select("*") - .eq("crew_id", id) - ]); + const [crewResponse, agentsResponse, tasksResponse] = await Promise.all( + [ + supabase + .from("crews") + .select(`*, crons(id, enabled, input, created_at)`) + .eq("id", id) + .single(), + supabase.from("agents").select("*").eq("crew_id", id), + supabase.from("tasks").select("*").eq("crew_id", id), + ] + ); if (crewResponse.error) throw crewResponse.error; if (agentsResponse.error) throw agentsResponse.error; @@ -96,7 +151,7 @@ export default function CrewDetails() { setEditForm({ name: crewData.name, description: crewData.description || "", - is_public: crewData.is_public || false + is_public: crewData.is_public || false, }); if (crewData.crons?.[0]?.input) { setCronId(crewData.crons[0].id); @@ -111,7 +166,7 @@ export default function CrewDetails() { toast({ title: "Error", description: "Failed to load crew data. Please refresh the page.", - variant: "destructive" + variant: "destructive", }); } } @@ -132,7 +187,7 @@ export default function CrewDetails() { .update({ name: editForm.name, description: editForm.description, - is_public: editForm.is_public + is_public: editForm.is_public, }) .eq("id", crew.id); @@ -153,22 +208,24 @@ export default function CrewDetails() { name: editForm.name, description: editForm.description, is_public: editForm.is_public, - cron: crew.cron ? { - ...crew.cron, - input: cronInput - } : null + cron: crew.cron + ? { + ...crew.cron, + input: cronInput, + } + : null, }); toast({ title: "Success", - description: "Crew settings updated successfully." + description: "Crew settings updated successfully.", }); } catch (error) { console.error("Error saving settings:", error); toast({ title: "Error", description: "Failed to save crew settings. Please try again.", - variant: "destructive" + variant: "destructive", }); } finally { setIsSaving(false); @@ -187,7 +244,7 @@ export default function CrewDetails() { crew_id: crew.id, enabled: true, profile_id: currentUser, - input: "" + input: "", }) .select() .single(); @@ -201,7 +258,7 @@ export default function CrewDetails() { setCronEnabled(true); toast({ title: "Success", - description: "Autonomous running enabled." + description: "Autonomous running enabled.", }); } } else if (cronId) { @@ -220,15 +277,18 @@ export default function CrewDetails() { toast({ title: "Success", - description: `Autonomous running ${checked ? "enabled" : "disabled"}.` + description: `Autonomous running ${ + checked ? "enabled" : "disabled" + }.`, }); } } catch (error) { console.error("Error toggling autonomous mode:", error); toast({ title: "Error", - description: "Failed to update autonomous running status. Please try again.", - variant: "destructive" + description: + "Failed to update autonomous running status. Please try again.", + variant: "destructive", }); } }; @@ -250,7 +310,7 @@ export default function CrewDetails() { toast({ title: "Success", - description: "Crew deleted successfully" + description: "Crew deleted successfully", }); router.push("/crews"); @@ -259,7 +319,7 @@ export default function CrewDetails() { toast({ title: "Error", description: "Failed to delete crew. Please try again.", - variant: "destructive" + variant: "destructive", }); } finally { setIsDeleting(false); @@ -267,7 +327,11 @@ export default function CrewDetails() { }; if (!crew) { - return
Cron Job
- Enable to run this crew automatically on an hourly schedule. + Enable to run this crew automatically on an hourly + schedule.
Example Prompt
- Check Bitcoin price and if its above $40,000, analyze market sentiment from the last hour and provide a summary of bullish/bearish indicators + Check Bitcoin price and if its above $40,000, + analyze market sentiment from the last hour and + provide a summary of bullish/bearish indicators
- Note: This job will run every hour. The schedule is fixed and cannot be modified. + Note: This job will run every hour. The schedule is + fixed and cannot be modified.
@@ -363,10 +444,7 @@ export default function CrewDetails() {