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-05-09 07:42:44 +02:00
|
|
|
import { getBasePath } from "../lib/frontendUtils";
|
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) => {
|
2024-05-09 07:42:44 +02:00
|
|
|
router.push(`${getBasePath()}${entity}/${id}`);
|
2024-03-04 13:52:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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-05-09 07:42:44 +02:00
|
|
|
<Button
|
|
|
|
|
text="Create"
|
|
|
|
|
kind="primary"
|
|
|
|
|
href={`${getBasePath()}${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
|
|
|
);
|
|
|
|
|
};
|