Files
calendar/packages/features/ee/dsync/components/GroupTeamMappingTable.tsx
T
Eunjae LeeGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
09ddbe886f refactor: make DataTableProvider framework-agnostic by requiring tableIdentifier (#24513)
* refactor: make DataTableProvider framework-agnostic by requiring tableIdentifier

- Remove Next.js usePathname dependency from DataTableProvider
- Make tableIdentifier a required prop instead of optional
- Update all usages to provide explicit tableIdentifier values
- This makes DataTableProvider usable in non-Next.js contexts

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* refactor: use usePathname at usage sites instead of hardcoding tableIdentifier

- Add validation in DataTableProvider for empty/nullish tableIdentifier
- Use usePathname() in Next.js apps to pass pathname as tableIdentifier
- Use descriptive identifiers for non-Next.js package components
- This keeps DataTableProvider framework-agnostic while allowing Next.js apps to use pathname

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* use pathname instead of hard-coded identifiers

* change type of tableIdentifier

* simplify

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-10-23 15:32:16 +02:00

87 lines
2.4 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 "@calcom/features/data-table/DataTableProvider";
import { DataTable, DataTableToolbar } from "@calcom/features/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;