N-FIN-5: add entity page UI

This commit is contained in:
Markus Thielker 2024-03-10 12:39:10 +01:00
parent 6e449ac603
commit 8dcc99d1f8
No known key found for this signature in database
3 changed files with 248 additions and 3 deletions

View file

@ -0,0 +1,41 @@
'use client';
import { ColumnDef } from '@tanstack/react-table';
import { Entity } from '@prisma/client';
import { CellContext, ColumnDefTemplate } from '@tanstack/table-core';
export const columns = (
actionCell: ColumnDefTemplate<CellContext<Entity, unknown>>,
) => {
return [
{
accessorKey: 'name',
header: 'Name',
},
{
accessorKey: 'type',
header: 'Type',
},
{
accessorKey: 'createdAt',
header: 'Created at',
cell: ({row}) => {
const date = row.getValue('createdAt') as Date;
return date.toDateString();
},
},
{
accessorKey: 'updatedAt',
header: 'Updated at',
cell: ({row}) => {
const date = row.getValue('updatedAt') as Date;
return date.toDateString();
},
},
{
id: 'actions',
cell: actionCell,
},
] as ColumnDef<Entity>[];
};

View file

@ -1,7 +1,33 @@
import { prismaClient } from '@/prisma';
import { getUser } from '@/auth';
import React from 'react';
import EntityPageClientContent from '@/components/EntityPageClientComponents';
import entityCreateUpdate from '@/lib/actions/entityCreateUpdate';
import entityDelete from '@/lib/actions/entityDelete';
export default async function EntitiesPage() {
const user = await getUser();
const entities = await prismaClient.entity.findMany({
where: {
userId: user?.id,
},
orderBy: [
{
type: 'desc',
},
{
id: 'asc',
},
],
});
return (
<main className="flex items-center justify-center min-h-screen text-3xl">
Entities
</main>
<EntityPageClientContent
entities={entities}
onSubmit={entityCreateUpdate}
onDelete={entityDelete}
className="flex flex-col justify-center space-y-4 p-10"/>
);
}