import Layout from "@/components/Layout"; import { useAuth } from "@/contexts/AuthContext"; import { useEffect, useMemo, useState } from "react"; import { useNavigate } from "react-router-dom"; import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { aethexCollabService } from "@/lib/aethex-collab-service"; import LoadingScreen from "@/components/LoadingScreen"; export default function Teams() { const { user, profile, loading } = useAuth(); const navigate = useNavigate(); const [isLoading, setIsLoading] = useState(true); const [teams, setTeams] = useState([]); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [creating, setCreating] = useState(false); useEffect(() => { if (!loading && !user) navigate("/login", { replace: true }); }, [loading, user, navigate]); useEffect(() => { const load = async () => { if (!user?.id) return; setIsLoading(true); try { const myTeams = await aethexCollabService.listMyTeams(user.id); setTeams(myTeams); } finally { setIsLoading(false); } }; load(); }, [user?.id]); const canCreate = useMemo(() => name.trim().length > 2 && !creating, [name, creating]); const handleCreate = async () => { if (!user?.id) return; if (!canCreate) return; setCreating(true); try { const team = await aethexCollabService.createTeam(user.id, name.trim(), description.trim() || null, "private"); setName(""); setDescription(""); setTeams((prev) => [{ team_id: team.id, teams: team }, ...prev]); } finally { setCreating(false); } }; if (loading || isLoading) return ; if (!user) return null; return (

Teams

Create a team and collaborate with members across projects.

Your teams Teams you belong to {teams.length === 0 ? (

No teams yet. Create one to get started.

) : ( teams.map((t) => { const team = (t as any).teams || t; return (
{team.name?.[0]?.toUpperCase() || "T"}
{team.name}
{team.visibility || "private"}
Team
); }) )}