mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-07-03 03:39:18 +00:00
N-FIN-5: add entity page UI
This commit is contained in:
parent
6e449ac603
commit
8dcc99d1f8
3 changed files with 248 additions and 3 deletions
41
src/app/entities/columns.tsx
Normal file
41
src/app/entities/columns.tsx
Normal 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>[];
|
||||
};
|
|
@ -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"/>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue