"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 { useCreateDepartmentDepartmentsPost, useListDepartmentsDepartmentsGet, useUpdateDepartmentDepartmentsDepartmentIdPatch, } from "@/api/generated/org/org"; import { useListEmployeesEmployeesGet } from "@/api/generated/org/org"; export default function DepartmentsPage() { const [name, setName] = useState(""); const [headId, setHeadId] = useState(""); const departments = useListDepartmentsDepartmentsGet(); const employees = useListEmployeesEmployeesGet(); const createDepartment = useCreateDepartmentDepartmentsPost({ mutation: { onSuccess: () => { setName(""); setHeadId(""); departments.refetch(); }, }, }); const updateDepartment = useUpdateDepartmentDepartmentsDepartmentIdPatch({ mutation: { onSuccess: () => departments.refetch(), }, }); const sortedEmployees = useMemo(() => { return (employees.data ?? []).slice().sort((a, b) => (a.name ?? "").localeCompare(b.name ?? "")); }, [employees.data]); return (

Departments

Create departments and assign department heads.

Create department Optional head setName(e.target.value)} /> {createDepartment.error ? (
{(createDepartment.error as Error).message}
) : null}
All departments {(departments.data ?? []).length} total {departments.isLoading ?
Loading…
: null} {departments.error ? (
{(departments.error as Error).message}
) : null} {!departments.isLoading && !departments.error ? (
    {(departments.data ?? []).map((d) => (
  • {d.name}
    id: {d.id}
    Head:
  • ))} {(departments.data ?? []).length === 0 ? (
  • No departments yet.
  • ) : null}
) : null} {updateDepartment.error ? (
{(updateDepartment.error as Error).message}
) : null}
); }