Fixed Buchungssystem
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { Calendar } from "lucide-react";
|
import { Calendar } from "lucide-react";
|
||||||
import { getServerSession } from "../../api/auth/[...nextauth]/auth";
|
import { getServerSession } from "../../api/auth/[...nextauth]/auth";
|
||||||
import { Badge } from "@repo/shared-components";
|
|
||||||
import { JSX } from "react";
|
import { JSX } from "react";
|
||||||
import { getPublicUser, prisma } from "@repo/db";
|
import { getPublicUser, prisma } from "@repo/db";
|
||||||
import { formatTimeRange } from "../../../helper/timerange";
|
import { formatTimeRange } from "../../../helper/timerange";
|
||||||
@@ -9,9 +8,9 @@ export const Bookings: () => Promise<JSX.Element> = async () => {
|
|||||||
const session = await getServerSession();
|
const session = await getServerSession();
|
||||||
const futureBookings = await prisma.booking.findMany({
|
const futureBookings = await prisma.booking.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: session?.user.id,
|
|
||||||
startTime: {
|
startTime: {
|
||||||
gte: new Date(),
|
gte: new Date(),
|
||||||
|
lte: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ export default async function Home({
|
|||||||
<RecentFlights />
|
<RecentFlights />
|
||||||
</div>
|
</div>
|
||||||
<div className="card bg-base-200 col-span-6 mb-4 shadow-xl xl:col-span-3">
|
<div className="card bg-base-200 col-span-6 mb-4 shadow-xl xl:col-span-3">
|
||||||
<Badges />
|
<Bookings />
|
||||||
</div>
|
</div>
|
||||||
<div className="card bg-base-200 col-span-6 mb-4 shadow-xl xl:col-span-3">
|
<div className="card bg-base-200 col-span-6 mb-4 shadow-xl xl:col-span-3">
|
||||||
<Bookings />
|
<Badges />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Events />
|
<Events />
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { AxiosError } from "axios";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { DateInput } from "_components/ui/DateInput";
|
import { DateInput } from "_components/ui/DateInput";
|
||||||
|
import { Select } from "_components/ui/Select";
|
||||||
|
|
||||||
interface NewBookingFormData {
|
interface NewBookingFormData {
|
||||||
type: "STATION" | "LST_01" | "LST_02" | "LST_03" | "LST_04";
|
type: "STATION" | "LST_01" | "LST_02" | "LST_03" | "LST_04";
|
||||||
@@ -85,6 +86,9 @@ export const NewBookingModal = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const form = useForm<NewBookingFormData>({
|
||||||
|
resolver: zodResolver(newBookingSchema),
|
||||||
|
});
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@@ -92,10 +96,7 @@ export const NewBookingModal = ({
|
|||||||
setValue,
|
setValue,
|
||||||
reset,
|
reset,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<NewBookingFormData>({
|
} = form;
|
||||||
resolver: zodResolver(newBookingSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedType = watch("type");
|
const selectedType = watch("type");
|
||||||
const hasDISPOPermission = userPermissions.includes("DISPO");
|
const hasDISPOPermission = userPermissions.includes("DISPO");
|
||||||
|
|
||||||
@@ -168,20 +169,17 @@ export const NewBookingModal = ({
|
|||||||
{isLoadingStations ? (
|
{isLoadingStations ? (
|
||||||
<div className="skeleton h-12 w-full"></div>
|
<div className="skeleton h-12 w-full"></div>
|
||||||
) : (
|
) : (
|
||||||
<select
|
<Select
|
||||||
{...register("stationId", {
|
label="Station"
|
||||||
required:
|
name="stationId"
|
||||||
selectedType === "STATION" ? "Bitte wählen Sie eine Station aus" : false,
|
form={form}
|
||||||
|
options={stations?.map((s) => {
|
||||||
|
return {
|
||||||
|
value: s.id,
|
||||||
|
label: `${s.bosCallsign} - ${s.locationState} (${s.aircraft})`,
|
||||||
|
};
|
||||||
})}
|
})}
|
||||||
className="select select-bordered w-full"
|
/>
|
||||||
>
|
|
||||||
<option value="">Station auswählen...</option>
|
|
||||||
{stations?.map((station) => (
|
|
||||||
<option key={station.id} value={station.id}>
|
|
||||||
{station.bosCallsignShort} - {station.locationState} ({station.aircraft})
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
)}
|
)}
|
||||||
{errors.stationId && (
|
{errors.stationId && (
|
||||||
<label className="label">
|
<label className="label">
|
||||||
|
|||||||
Reference in New Issue
Block a user