added User edit
This commit is contained in:
22
apps/hub/app/(app)/admin/user/[id]/page.tsx
Normal file
22
apps/hub/app/(app)/admin/user/[id]/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { PrismaClient } from '@repo/db';
|
||||||
|
|
||||||
|
export default async ({ params }: { params: Promise<{ id: string }> }) => {
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
const { id } = await params;
|
||||||
|
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(user);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>
|
||||||
|
{user?.firstname} {user?.lastname}
|
||||||
|
</h1>
|
||||||
|
<p>{user?.email}</p>
|
||||||
|
{/* TODO: Hier Nutzerdaten bearbeiten */}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import Link from 'next/link';
|
||||||
import { PaginatedTable } from '../../../_components/PaginatedTable';
|
import { PaginatedTable } from '../../../_components/PaginatedTable';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
return (
|
return (
|
||||||
<PaginatedTable
|
<PaginatedTable
|
||||||
|
showEditButton
|
||||||
prismaModel="user"
|
prismaModel="user"
|
||||||
columns={[
|
columns={[
|
||||||
{
|
{
|
||||||
@@ -21,10 +23,6 @@ export default async () => {
|
|||||||
header: 'Email',
|
header: 'Email',
|
||||||
accessorKey: 'email',
|
accessorKey: 'email',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
header: 'Role',
|
|
||||||
accessorKey: 'role',
|
|
||||||
},
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -8,11 +8,13 @@ interface PaginatedTableProps<TData>
|
|||||||
extends Omit<SortableTableProps<TData>, 'data'> {
|
extends Omit<SortableTableProps<TData>, 'data'> {
|
||||||
prismaModel: keyof PrismaClient;
|
prismaModel: keyof PrismaClient;
|
||||||
rowsPerPage?: number;
|
rowsPerPage?: number;
|
||||||
|
showEditButton?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PaginatedTable<TData>({
|
export function PaginatedTable<TData>({
|
||||||
prismaModel,
|
prismaModel,
|
||||||
rowsPerPage = 10,
|
rowsPerPage = 10,
|
||||||
|
showEditButton = false,
|
||||||
...restProps
|
...restProps
|
||||||
}: PaginatedTableProps<TData>) {
|
}: PaginatedTableProps<TData>) {
|
||||||
const [data, setData] = useState<TData[]>([]);
|
const [data, setData] = useState<TData[]>([]);
|
||||||
@@ -30,7 +32,12 @@ export function PaginatedTable<TData>({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<SortableTable data={data} {...restProps} />
|
<SortableTable
|
||||||
|
data={data}
|
||||||
|
prismaModel={prismaModel}
|
||||||
|
showEditButton={showEditButton}
|
||||||
|
{...restProps}
|
||||||
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
totalPages={Math.ceil(total / rowsPerPage)}
|
totalPages={Math.ceil(total / rowsPerPage)}
|
||||||
page={page}
|
page={page}
|
||||||
|
|||||||
@@ -9,21 +9,43 @@ import {
|
|||||||
flexRender,
|
flexRender,
|
||||||
} from '@tanstack/react-table';
|
} from '@tanstack/react-table';
|
||||||
import { ArrowLeft, ArrowRight, ChevronDown, ChevronUp } from 'lucide-react'; // Icons for sorting
|
import { ArrowLeft, ArrowRight, ChevronDown, ChevronUp } from 'lucide-react'; // Icons for sorting
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { PrismaClient } from '@repo/db';
|
||||||
|
|
||||||
export interface SortableTableProps<TData> {
|
export interface SortableTableProps<TData> {
|
||||||
data: TData[];
|
data: TData[];
|
||||||
columns: ColumnDef<TData>[];
|
columns: ColumnDef<TData>[];
|
||||||
|
showEditButton?: boolean;
|
||||||
|
prismaModel?: keyof PrismaClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SortableTable<TData>({
|
export default function SortableTable<TData>({
|
||||||
data,
|
data,
|
||||||
columns,
|
columns,
|
||||||
|
prismaModel,
|
||||||
|
showEditButton,
|
||||||
}: SortableTableProps<TData>) {
|
}: SortableTableProps<TData>) {
|
||||||
const [sorting, setSorting] = useState<SortingState>([]);
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data,
|
data,
|
||||||
columns,
|
columns: showEditButton
|
||||||
|
? [
|
||||||
|
...columns,
|
||||||
|
{
|
||||||
|
header: 'Actions',
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Link
|
||||||
|
href={`/admin/${prismaModel as string}/${(row.original as any).id}`}
|
||||||
|
>
|
||||||
|
<button className="btn">Edit</button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: columns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
onSortingChange: setSorting,
|
onSortingChange: setSorting,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const VerticalNav = () => {
|
|||||||
</summary>
|
</summary>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<Link href="/admin/users">User</Link>
|
<Link href="/admin/user">User</Link>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Reference in New Issue
Block a user