added logbook
This commit is contained in:
80
apps/hub/app/(app)/_components/RecentFlights.tsx
Normal file
80
apps/hub/app/(app)/_components/RecentFlights.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
"use client";
|
||||
import { Mission, MissionAlertLog, MissionLog, Station } from "@repo/db";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { PaginatedTable } from "_components/PaginatedTable";
|
||||
import { ArrowRight, NotebookText } from "lucide-react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
|
||||
export const RecentFlights = () => {
|
||||
const session = useSession();
|
||||
return (
|
||||
<div className="card-body">
|
||||
<h2 className="card-title justify-between">
|
||||
<span className="card-title">
|
||||
<NotebookText className="w-4 h-4" /> Logbook
|
||||
</span>
|
||||
<Link className="badge badge-sm badge-info badge-outline" href="/logbook">
|
||||
Zum vollständigen Logbook <ArrowRight className="w-4 h-4" />
|
||||
</Link>
|
||||
</h2>
|
||||
<PaginatedTable
|
||||
prismaModel={"missionOnStationUsers"}
|
||||
filter={{
|
||||
userId: session.data?.user?.id ?? "",
|
||||
Mission: {
|
||||
state: "finished",
|
||||
},
|
||||
}}
|
||||
include={{
|
||||
Station: true,
|
||||
User: true,
|
||||
Mission: true,
|
||||
}}
|
||||
columns={
|
||||
[
|
||||
{
|
||||
header: "Station",
|
||||
accessorKey: "Station.name",
|
||||
cell: ({ row }) => row.original.Station.bosCallsign,
|
||||
},
|
||||
|
||||
{
|
||||
header: "Datum",
|
||||
accessorKey: "createdAt",
|
||||
cell: ({ row }) => new Date(row.original.Mission.createdAt).toLocaleDateString(),
|
||||
},
|
||||
{
|
||||
header: "Einsatzlänge",
|
||||
cell: ({ row }) => {
|
||||
const missionStartLogs = row.original.Mission.missionLog.filter(
|
||||
(log) => (log as unknown as MissionLog).type === "alert-log",
|
||||
) as unknown as MissionAlertLog[] | undefined;
|
||||
// Find the first log with a station ID that matches the current row's station ID or use the first log if none match
|
||||
const missionStartLog =
|
||||
missionStartLogs?.find(
|
||||
(log) => log.data.station?.id === row.original.Station.id,
|
||||
) || missionStartLogs?.[0];
|
||||
|
||||
const missionEndLog = row.original.Mission.missionLog.find(
|
||||
(log) => (log as unknown as MissionLog).type === "completed-log",
|
||||
) as unknown as MissionAlertLog | undefined;
|
||||
|
||||
if (!missionStartLog) return "Unbekannt";
|
||||
if (!missionEndLog) return "Unbekannt";
|
||||
|
||||
const start = new Date(missionStartLog.timeStamp);
|
||||
const end = new Date(missionEndLog?.timeStamp);
|
||||
const duration = Math.round((end.getTime() - start.getTime()) / 1000 / 60); // in minutes
|
||||
return `${duration} Minuten`;
|
||||
},
|
||||
},
|
||||
] as ColumnDef<{
|
||||
Station: Station;
|
||||
Mission: Mission;
|
||||
}>[]
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -274,10 +274,13 @@ export const DispoStats = async () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const Stats = ({ stats }: { stats: "pilot" | "dispo" }) => {
|
||||
export const Stats = async ({ stats }: { stats: "pilot" | "dispo" }) => {
|
||||
const session = await getServerSession();
|
||||
if (!session) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<StatsToggle />
|
||||
{session.user.permissions.includes("DISPO") && <StatsToggle />}
|
||||
<div className="card bg-base-200 shadow-xl mb-4 col-span-6 xl:col-span-3">
|
||||
{stats === "dispo" && <DispoStats />}
|
||||
{stats === "pilot" && <PilotStats />}
|
||||
|
||||
@@ -30,30 +30,19 @@ export const StatsToggle = () => {
|
||||
return (
|
||||
<header className="flex justify-between items-center p-4">
|
||||
<h1 className="text-2xl font-bold">
|
||||
Hallo,{" "}
|
||||
{session.status === "authenticated"
|
||||
? session.data?.user.firstname
|
||||
: "<username>"}
|
||||
Hallo, {session.status === "authenticated" ? session.data?.user.firstname : "<username>"}
|
||||
{"!"}
|
||||
</h1>
|
||||
<div>
|
||||
<div className="tooltip" data-tip="Disponent / Pilot">
|
||||
<div className="tooltip tooltip-left" data-tip="Disponent / Pilot">
|
||||
<label className="toggle text-base-content">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={(e) => setChecked(e.target.checked)}
|
||||
/>
|
||||
<Workflow
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
aria-label="enabled"
|
||||
/>
|
||||
<PlaneIcon
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
aria-label="disabled"
|
||||
/>
|
||||
<Workflow className="w-4 h-4" viewBox="0 0 24 24" aria-label="enabled" />
|
||||
<PlaneIcon className="w-4 h-4" viewBox="0 0 24 24" aria-label="disabled" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user