"use client"; import { useMemo, useState } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Select } from "@/components/ui/select"; import { useCreateTeamTeamsPost, useListDepartmentsDepartmentsGet, useListEmployeesEmployeesGet, useListTeamsTeamsGet, } from "@/api/generated/org/org"; export default function TeamsPage() { const [name, setName] = useState(""); const [departmentId, setDepartmentId] = useState(""); const [leadEmployeeId, setLeadEmployeeId] = useState(""); const departments = useListDepartmentsDepartmentsGet(); const employees = useListEmployeesEmployeesGet(); const teams = useListTeamsTeamsGet({ department_id: undefined }); const departmentList = useMemo( () => (departments.data?.status === 200 ? departments.data.data : []), [departments.data], ); const employeeList = useMemo( () => (employees.data?.status === 200 ? employees.data.data : []), [employees.data], ); const teamList = useMemo(() => (teams.data?.status === 200 ? teams.data.data : []), [teams.data]); const deptNameById = useMemo(() => { const m = new Map(); for (const d of departmentList) { if (d.id != null) m.set(d.id, d.name); } return m; }, [departmentList]); const empNameById = useMemo(() => { const m = new Map(); for (const e of employeeList) { if (e.id != null) m.set(e.id, e.name); } return m; }, [employeeList]); const createTeam = useCreateTeamTeamsPost({ mutation: { onSuccess: () => { setName(""); setDepartmentId(""); setLeadEmployeeId(""); teams.refetch(); }, }, }); const sorted = teamList .slice() .sort((a, b) => `${deptNameById.get(a.department_id) ?? ""}::${a.name}`.localeCompare(`${deptNameById.get(b.department_id) ?? ""}::${b.name}`)); return (

Teams

Teams live under departments. Projects are owned by teams.

Create team Define a team and attach it to a department. setName(e.target.value)} /> {createTeam.error ?
{(createTeam.error as Error).message}
: null}
All teams {sorted.length} total {teams.isLoading ?
Loading…
: null} {teams.error ?
{(teams.error as Error).message}
: null} {!teams.isLoading && !teams.error ? (
    {sorted.map((t) => (
  • {t.name}
    {deptNameById.get(t.department_id) ?? `Dept#${t.department_id}`}
    {t.lead_employee_id ? Lead: {empNameById.get(t.lead_employee_id) ?? `Emp#${t.lead_employee_id}`} : No lead}
  • ))} {sorted.length === 0 ?
  • No teams yet.
  • : null}
) : null}
); }