diff --git a/apps/hub/app/(app)/admin/event/[id]/page.tsx b/apps/hub/app/(app)/admin/event/[id]/page.tsx new file mode 100644 index 00000000..399adf90 --- /dev/null +++ b/apps/hub/app/(app)/admin/event/[id]/page.tsx @@ -0,0 +1,13 @@ +import { prisma } from '@repo/db'; +import { StationForm } from '../_components/Form'; + +export default async ({ params }: { params: Promise<{ id: string }> }) => { + const { id } = await params; + const station = await prisma.station.findUnique({ + where: { + id: parseInt(id), + }, + }); + if (!station) return
Station not found
; + return ; +}; diff --git a/apps/hub/app/(app)/admin/event/_components/Form.tsx b/apps/hub/app/(app)/admin/event/_components/Form.tsx new file mode 100644 index 00000000..c8bfe068 --- /dev/null +++ b/apps/hub/app/(app)/admin/event/_components/Form.tsx @@ -0,0 +1,246 @@ +'use client'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { StationOptionalDefaultsSchema } from '@repo/db/zod'; +import { set, useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { BosUse, Country, Station } from '@repo/db'; +import { FileText, LocateIcon, PlaneIcon } from 'lucide-react'; +import { Input } from '../../../../_components/ui/Input'; +import { useState } from 'react'; +import { deleteStation, upsertStation } from '../action'; +import { Button } from '../../../../_components/ui/Button'; +import { redirect } from 'next/navigation'; + +export const StationForm = ({ station }: { station?: Station }) => { + const form = useForm>({ + resolver: zodResolver(StationOptionalDefaultsSchema), + defaultValues: station, + }); + const [loading, setLoading] = useState(false); + const [deleteLoading, setDeleteLoading] = useState(false); + console.log(form.formState.errors); + return ( + <> +
{ + setLoading(true); + const createdStation = await upsertStation(values, station?.id); + setLoading(false); + if (!station) redirect(`/admin/station`); + })} + className="grid grid-cols-6 gap-3" + > +
+
+

+ Allgemeines +

+ + + + + + + + +
+
+
+
+

+ Standort + Ausrüstung +

+ + + + + Ausgerüstet mit: + +
+ + + + +
+ + + + +
+
+
+
+

+ Hubschrauber +

+ + + +
+
+
+
+
+ + {station && ( + + )} +
+
+
+
+ + ); +}; diff --git a/apps/hub/app/(app)/admin/event/action.ts b/apps/hub/app/(app)/admin/event/action.ts new file mode 100644 index 00000000..34ffa68d --- /dev/null +++ b/apps/hub/app/(app)/admin/event/action.ts @@ -0,0 +1,20 @@ +'use server'; + +import { prisma, Prisma, Station } from '@repo/db'; + +export const upsertStation = async ( + station: Prisma.StationCreateInput, + id?: Station['id'] +) => { + const newStation = id + ? await prisma.station.update({ + where: { id: id }, + data: station, + }) + : await prisma.station.create({ data: station }); + return newStation; +}; + +export const deleteStation = async (id: Station['id']) => { + await prisma.station.delete({ where: { id: id } }); +}; diff --git a/apps/hub/app/(app)/admin/event/new/page.tsx b/apps/hub/app/(app)/admin/event/new/page.tsx new file mode 100644 index 00000000..a7d5f4de --- /dev/null +++ b/apps/hub/app/(app)/admin/event/new/page.tsx @@ -0,0 +1,5 @@ +import { StationForm } from '../_components/Form'; + +export default () => { + return ; +}; diff --git a/apps/hub/app/(app)/admin/event/page.tsx b/apps/hub/app/(app)/admin/event/page.tsx new file mode 100644 index 00000000..70c3c91c --- /dev/null +++ b/apps/hub/app/(app)/admin/event/page.tsx @@ -0,0 +1,42 @@ +import { DatabaseBackupIcon } from 'lucide-react'; +import { PaginatedTable } from '../../../_components/PaginatedTable'; +import Link from 'next/link'; + +export default () => { + return ( + <> +

+ + Stationen + + + + +

+ + + ); +}; diff --git a/packages/database/prisma/schema/event.prisma b/packages/database/prisma/schema/event.prisma new file mode 100644 index 00000000..e69de29b