continue Event page
This commit is contained in:
@@ -1,28 +1,32 @@
|
||||
"use client";
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import SortableTable, { Pagination, SortableTableProps } from "./Table";
|
||||
import { PrismaClient } from "@repo/db";
|
||||
import { getData } from "./pagiantedTableActions";
|
||||
'use client';
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import SortableTable, { Pagination, SortableTableProps } from './Table';
|
||||
import { PrismaClient } from '@repo/db';
|
||||
import { getData } from './pagiantedTableActions';
|
||||
|
||||
interface PaginatedTableProps<TData>
|
||||
extends Omit<SortableTableProps<TData>, "data"> {
|
||||
extends Omit<SortableTableProps<TData>, 'data'> {
|
||||
prismaModel: keyof PrismaClient;
|
||||
filter?: Record<string, any>;
|
||||
rowsPerPage?: number;
|
||||
showEditButton?: boolean;
|
||||
searchFields: string[];
|
||||
searchFields?: string[];
|
||||
include?: Record<string, boolean>[];
|
||||
}
|
||||
|
||||
export function PaginatedTable<TData>({
|
||||
prismaModel,
|
||||
rowsPerPage = 10,
|
||||
showEditButton = false,
|
||||
searchFields,
|
||||
searchFields = [],
|
||||
filter,
|
||||
include,
|
||||
...restProps
|
||||
}: PaginatedTableProps<TData>) {
|
||||
const [data, setData] = useState<TData[]>([]);
|
||||
const [page, setPage] = useState(0);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm);
|
||||
|
||||
const debounce = (func: Function, delay: number) => {
|
||||
@@ -46,7 +50,8 @@ export function PaginatedTable<TData>({
|
||||
rowsPerPage,
|
||||
page * rowsPerPage,
|
||||
debouncedSearchTerm,
|
||||
searchFields
|
||||
searchFields,
|
||||
filter
|
||||
).then((result) => {
|
||||
if (result) {
|
||||
setData(result.data);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use server";
|
||||
import { PrismaClient } from "@repo/db";
|
||||
'use server';
|
||||
import { PrismaClient } from '@repo/db';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -8,7 +8,9 @@ export async function getData(
|
||||
limit: number,
|
||||
offset: number,
|
||||
searchTerm: string,
|
||||
searchFields: string[]
|
||||
searchFields: string[],
|
||||
filter?: Record<string, any>,
|
||||
include?: Record<string, boolean>[]
|
||||
) {
|
||||
if (!model || !prisma[model]) {
|
||||
return { data: [], total: 0 };
|
||||
@@ -24,8 +26,9 @@ export async function getData(
|
||||
[field]: { contains: searchTerm },
|
||||
})),
|
||||
].filter(Boolean),
|
||||
...filter,
|
||||
}
|
||||
: {};
|
||||
: { ...filter };
|
||||
|
||||
if (!prisma[model]) {
|
||||
return { data: [], total: 0 };
|
||||
@@ -35,6 +38,7 @@ export async function getData(
|
||||
where,
|
||||
take: limit,
|
||||
skip: offset,
|
||||
include,
|
||||
});
|
||||
|
||||
const total = await (prisma[model] as any).count({ where });
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
GearIcon,
|
||||
ExitIcon,
|
||||
LockClosedIcon,
|
||||
} from "@radix-ui/react-icons";
|
||||
import Link from "next/link";
|
||||
} from '@radix-ui/react-icons';
|
||||
import Link from 'next/link';
|
||||
|
||||
export const VerticalNav = () => {
|
||||
return (
|
||||
@@ -34,6 +34,9 @@ export const VerticalNav = () => {
|
||||
<li>
|
||||
<Link href="/admin/station">Stationen</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/admin/event">Events</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</details>
|
||||
</li>
|
||||
|
||||
33
apps/hub/app/_components/ui/Switch.tsx
Normal file
33
apps/hub/app/_components/ui/Switch.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import {
|
||||
FieldValues,
|
||||
Path,
|
||||
RegisterOptions,
|
||||
UseFormReturn,
|
||||
} from 'react-hook-form';
|
||||
import { cn } from '../../../helper/cn';
|
||||
|
||||
interface InputProps<T extends FieldValues>
|
||||
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'form'> {
|
||||
name: Path<T>;
|
||||
form: UseFormReturn<T>;
|
||||
formOptions?: RegisterOptions<T>;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export const Switch = <T extends FieldValues>({
|
||||
name,
|
||||
label = name,
|
||||
form,
|
||||
formOptions,
|
||||
className,
|
||||
...inputProps
|
||||
}: InputProps<T>) => {
|
||||
return (
|
||||
<div className="form-control">
|
||||
<label className="label cursor-pointer">
|
||||
<span className={cn('label-text', className)}>{label}</span>
|
||||
<input type="checkbox" className="toggle" {...form.register(name)} />
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user