gitscope
← marzneshin / v0.5.2 / dashboard/src/features/admins/components/tables/admins/index.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/features/admins/components/tables/admins/index.tsx · TypeScript
Blame Raw
 1import type { FC } from "react";
 2import { fetchAdmins, AdminType, AdminsQueryFetchKey } from "@marzneshin/features/admins";
 3import { columns as columnsFn } from "./columns";
 4import { EntityTable } from "@marzneshin/features/entity-table";
 5import { useNavigate } from "@tanstack/react-router";
 6
 7export const AdminsTable: FC = () => {
 8    const navigate = useNavigate({ from: "/admins" });
 9    const onOpen = (entity: AdminType) => {
10        navigate({
11            to: "/admins/$adminId",
12            params: { adminId: entity.username },
13        })
14    }
15
16    const onEdit = (entity: AdminType) => {
17        navigate({
18            to: "/admins/$adminId/edit",
19            params: { adminId: entity.username },
20        })
21    }
22
23    const onDelete = (entity: AdminType) => {
24        navigate({
25            to: "/admins/$adminId/delete",
26            params: { adminId: entity.username },
27        })
28    }
29
30    const columns = columnsFn({ onEdit, onDelete, onOpen });
31
32    return (
33        <EntityTable
34            fetchEntity={fetchAdmins}
35            manualSorting={false}
36            columns={columns}
37            filteredColumn="username"
38            entityKey={AdminsQueryFetchKey}
39            onCreate={() => navigate({ to: "/admins/create" })}
40            onOpen={onOpen}
41        />
42    );
43};