changes pilot socket to reperate pilto socket, added pilot stats

This commit is contained in:
PxlLoewe
2025-05-17 23:51:04 -07:00
parent 16e05a08a6
commit 6b58f564b2
16 changed files with 583 additions and 352 deletions

View File

@@ -1,9 +1,22 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { BADGES, PERMISSION, Report, User } from "@repo/db";
import {
BADGES,
ConnectedAircraft,
ConnectedDispatcher,
PERMISSION,
Report,
Station,
User,
} from "@repo/db";
import { useRef, useState } from "react";
import { useForm } from "react-hook-form";
import { deleteDispoHistory, editUser, resetPassword } from "../../action";
import {
deleteDispoHistory,
deletePilotHistory,
editUser,
resetPassword,
} from "../../action";
import { toast } from "react-hot-toast";
import {
PersonIcon,
@@ -166,59 +179,60 @@ export const ConnectionHistory: React.FC<{ user: User }> = ({
userId: user.id,
}}
prismaModel={"connectedDispatcher"}
columns={[
{
accessorKey: "loginTime",
header: "Login",
cell: ({ row }) => {
return new Date(row.getValue("loginTime")).toLocaleString(
"de-DE",
);
columns={
[
{
accessorKey: "loginTime",
header: "Login",
cell: ({ row }) => {
return new Date(row.getValue("loginTime")).toLocaleString(
"de-DE",
);
},
},
},
{
header: "Time Online",
cell: ({ row }) => {
console.log(row.original);
const loginTime = new Date(row.original.loginTime).getTime();
const logoutTime = new Date(
(row.original as any).logoutTime,
).getTime();
const timeOnline = logoutTime - loginTime;
{
header: "Time Online",
cell: ({ row }) => {
if (row.original.logoutTime == null) {
return <span className="text-success">Online</span>;
}
const loginTime = new Date(row.original.loginTime).getTime();
const logoutTime = new Date(
row.original.logoutTime,
).getTime();
const hours = Math.floor(timeOnline / 1000 / 60 / 60);
const minutes = Math.floor((timeOnline / 1000 / 60) % 60);
const timeOnline = logoutTime - loginTime;
if ((row.original as any).logoutTime == null) {
return <span className="text-success">Online</span>;
}
const hours = Math.floor(timeOnline / 1000 / 60 / 60);
const minutes = Math.floor((timeOnline / 1000 / 60) % 60);
return (
<span className={cn(hours > 2 && "text-error")}>
{hours}h {minutes}min
</span>
);
return (
<span className={cn(hours > 2 && "text-error")}>
{hours}h {minutes}min
</span>
);
},
},
},
{
header: "Aktionen",
cell: ({ row }) => {
return (
<div>
<button
className="btn btn-sm btn-error"
onClick={async () => {
await deleteDispoHistory((row.original as any).id);
dispoTableRef.current?.refresh();
}}
>
löschen
</button>
</div>
);
{
header: "Aktionen",
cell: ({ row }) => {
return (
<div>
<button
className="btn btn-sm btn-error"
onClick={async () => {
await deleteDispoHistory(row.original.id);
dispoTableRef.current?.refresh();
}}
>
löschen
</button>
</div>
);
},
},
},
]}
] as ColumnDef<ConnectedDispatcher>[]
}
/>
</div>
<div className="flex-1">
@@ -232,73 +246,73 @@ export const ConnectionHistory: React.FC<{ user: User }> = ({
}}
prismaModel={"connectedAircraft"}
include={{ Station: true }}
columns={[
{
accessorKey: "Station.bosCallsign",
header: "Station",
cell: ({ row }) => {
return (
<Link
className="link link-hover"
href={`/admin/station/${(row.original as any).id}`}
>
{(row.original as any).Station.bosCallsign}
</Link>
);
},
},
{
accessorKey: "loginTime",
header: "Login",
cell: ({ row }) => {
return new Date(row.getValue("loginTime")).toLocaleString(
"de-DE",
);
},
},
{
header: "Time Online",
cell: ({ row }) => {
console.log(row.original);
const loginTime = new Date(row.original.loginTime).getTime();
const logoutTime = new Date(
(row.original as any).logoutTime,
).getTime();
const timeOnline = logoutTime - loginTime;
const hours = Math.floor(timeOnline / 1000 / 60 / 60);
const minutes = Math.floor((timeOnline / 1000 / 60) % 60);
if ((row.original as any).logoutTime == null) {
return <span className="text-success">Online</span>;
}
return (
<span className={cn(hours > 2 && "text-error")}>
{hours}h {minutes}min
</span>
);
},
},
{
header: "Aktionen",
cell: ({ row }) => {
return (
<div>
<button
className="btn btn-sm btn-error"
onClick={async () => {
await deleteDispoHistory((row.original as any).id);
dispoTableRef.current?.refresh();
}}
columns={
[
{
accessorKey: "Station.bosCallsign",
header: "Station",
cell: ({ row }) => {
return (
<Link
className="link link-hover"
href={`/admin/station/${row.original.id}`}
>
löschen
</button>
</div>
);
{row.original.Station.bosCallsign}
</Link>
);
},
},
},
]}
{
accessorKey: "loginTime",
header: "Login",
cell: ({ row }) => {
return new Date(row.getValue("loginTime")).toLocaleString(
"de-DE",
);
},
},
{
header: "Time Online",
cell: ({ row }) => {
if (!row.original.logoutTime) {
return <span className="text-success">Online</span>;
}
const loginTime = new Date(row.original.loginTime).getTime();
const logoutTime = new Date(
row.original.logoutTime,
).getTime();
const timeOnline = logoutTime - loginTime;
const hours = Math.floor(timeOnline / 1000 / 60 / 60);
const minutes = Math.floor((timeOnline / 1000 / 60) % 60);
return (
<span className={cn(hours > 2 && "text-error")}>
{hours}h {minutes}min
</span>
);
},
},
{
header: "Aktionen",
cell: ({ row }) => {
return (
<div>
<button
className="btn btn-sm btn-error"
onClick={async () => {
await deletePilotHistory(row.original.id);
dispoTableRef.current?.refresh();
}}
>
löschen
</button>
</div>
);
},
},
] as ColumnDef<ConnectedAircraft & { Station: Station }>[]
}
/>
</div>
</div>