1368ffe55d
* refactor: move data-table hooks/contexts/provider from features to web modules Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: update broken useColumnResizing import path in DataTable.tsx Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: update remaining broken import paths for moved hooks Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * docs: update GUIDE.md import paths and file references for moved modules Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
import type { ColumnDef } from "@tanstack/react-table";
|
|
import { useReactTable, getCoreRowModel } from "@tanstack/react-table";
|
|
import { usePathname } from "next/navigation";
|
|
import { useRef, useState } from "react";
|
|
|
|
import { DataTableProvider } from "~/data-table/DataTableProvider";
|
|
import { DataTable, DataTableToolbar } from "~/data-table/components";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import CreateTeamDialog from "./CreateTeamDialog";
|
|
import GroupNameCell from "./GroupNameCell";
|
|
|
|
interface TeamGroupMapping {
|
|
name: string;
|
|
id: number;
|
|
groupNames: string[];
|
|
directoryId: string;
|
|
}
|
|
|
|
const GroupTeamMappingTable = () => {
|
|
const pathname = usePathname();
|
|
if (!pathname) return null;
|
|
return (
|
|
<DataTableProvider tableIdentifier={pathname}>
|
|
<GroupTeamMappingTableContent />
|
|
</DataTableProvider>
|
|
);
|
|
};
|
|
|
|
const GroupTeamMappingTableContent = () => {
|
|
const { t } = useLocale();
|
|
const [createTeamDialogOpen, setCreateTeamDialogOpen] = useState(false);
|
|
|
|
const { data } = trpc.viewer.dsync.teamGroupMapping.get.useQuery();
|
|
|
|
const tableContainerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const columns: ColumnDef<TeamGroupMapping>[] = [
|
|
{
|
|
id: "name",
|
|
header: t("team"),
|
|
size: 200,
|
|
enableHiding: false,
|
|
enableSorting: false,
|
|
cell: ({ row }) => {
|
|
const { name } = row.original;
|
|
|
|
return <p>{name}</p>;
|
|
},
|
|
},
|
|
{
|
|
id: "group",
|
|
header: t("group_name"),
|
|
size: 500,
|
|
enableHiding: false,
|
|
enableSorting: false,
|
|
cell: ({ row }) => {
|
|
const { id, groupNames, directoryId } = row.original;
|
|
|
|
return <GroupNameCell groupNames={groupNames} teamId={id} directoryId={directoryId} />;
|
|
},
|
|
},
|
|
];
|
|
|
|
const table = useReactTable({
|
|
data: data?.teamGroupMapping ?? [],
|
|
columns,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<DataTable table={table} tableContainerRef={tableContainerRef}>
|
|
<DataTableToolbar.Root>
|
|
<DataTableToolbar.CTA onClick={() => setCreateTeamDialogOpen(true)}>
|
|
Create team
|
|
</DataTableToolbar.CTA>
|
|
</DataTableToolbar.Root>
|
|
</DataTable>
|
|
<CreateTeamDialog open={createTeamDialogOpen} onOpenChange={setCreateTeamDialogOpen} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default GroupTeamMappingTable;
|