link-stack/packages/bridge-ui/components/List.tsx

36 lines
877 B
TypeScript
Raw Normal View History

2024-03-04 13:52:20 +01:00
"use client";
import { FC } from "react";
import { useRouter } from "next/navigation";
2024-04-24 21:44:05 +02:00
import { List as InternalList, Button } from "ui";
2024-04-30 11:39:16 +02:00
import { type Selectable } from "kysely";
import { type Database } from "bridge-common";
import { serviceConfig } from "../config/config";
2024-03-04 13:52:20 +01:00
2024-04-30 11:39:16 +02:00
type ListProps = {
service: string;
2024-04-26 14:31:33 +02:00
rows: Selectable<keyof Database>[];
2024-04-30 11:39:16 +02:00
};
2024-03-04 13:52:20 +01:00
2024-04-30 11:39:16 +02:00
export const List: FC<ListProps> = ({ service, rows }) => {
const { displayName, entity, listColumns } = serviceConfig[service];
const title = `${displayName}s`;
2024-03-04 13:52:20 +01:00
const router = useRouter();
const onRowClick = (id: string) => {
router.push(`/${entity}/${id}`);
};
return (
2024-04-23 13:36:51 +02:00
<InternalList
title={title}
rows={rows}
2024-04-30 11:39:16 +02:00
columns={listColumns}
2024-04-23 13:36:51 +02:00
onRowClick={onRowClick}
2024-04-24 21:44:05 +02:00
buttons={
2024-04-25 12:31:03 +02:00
<Button text="Create" kind="primary" href={`/${entity}/create`} />
2024-04-24 21:44:05 +02:00
}
2024-04-23 13:36:51 +02:00
/>
2024-03-04 13:52:20 +01:00
);
};