implemented #76

This commit is contained in:
PxlLoewe
2025-07-23 19:06:35 -07:00
parent 115296d7f7
commit 0b0f4fac2f
6 changed files with 45 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import { useMutation } from "@tanstack/react-query";
import { Prisma } from "@repo/db";
import { changeDispatcherAPI } from "_querys/dispatcher";
import { Button, getNextDateWithTime } from "@repo/shared-components";
import { Ghost } from "lucide-react";
export const ConnectionBtn = () => {
const modalRef = useRef<HTMLDialogElement>(null);
@@ -14,6 +15,7 @@ export const ConnectionBtn = () => {
const [form, setForm] = useState({
logoffTime: "",
selectedZone: "LST_01",
ghostMode: false,
});
const changeDispatcherMutation = useMutation({
mutationFn: ({ id, data }: { id: number; data: Prisma.ConnectedDispatcherUpdateInput }) =>
@@ -45,7 +47,7 @@ export const ConnectionBtn = () => {
modalRef.current?.showModal();
}}
>
Verbunden
Verbunden {connection.ghostMode && <Ghost />}
</button>
) : (
<button
@@ -89,6 +91,21 @@ export const ConnectionBtn = () => {
<p className="fieldset-label">Du kannst diese Zeit später noch anpassen.</p>
)}
</fieldset>
{session.data?.user.permissions.includes("ADMIN_KICK") &&
connection.status === "disconnected" && (
<fieldset className="fieldset bg-base-100 border-base-300 rounded-box w-full border p-4">
<legend className="fieldset-legend">Ghost-Mode</legend>
<label className="label">
<input
checked={form.ghostMode}
onChange={(e) => setForm({ ...form, ghostMode: e.target.checked })}
type="checkbox"
className="checkbox"
/>
Vesteckt deine Verbindung auf dem Tracker
</label>
</fieldset>
)}
<div className="modal-action flex w-full justify-between">
<form method="dialog" className="flex w-full justify-between">
<button className="btn btn-soft">Zurück</button>
@@ -138,6 +155,7 @@ export const ConnectionBtn = () => {
form.logoffTime && logoffHours !== undefined && logoffMinutes !== undefined
? getNextDateWithTime(logoffHours, logoffMinutes).toISOString()
: "",
form.ghostMode,
);
}}
className="btn btn-soft btn-info"

View File

@@ -11,7 +11,13 @@ interface ConnectionStore {
message: string;
selectedZone: string;
logoffTime: string;
connect: (uid: string, selectedZone: string, logoffTime: string) => Promise<void>;
ghostMode: boolean;
connect: (
uid: string,
selectedZone: string,
logoffTime: string,
ghostMode: boolean,
) => Promise<void>;
disconnect: () => void;
}
@@ -23,11 +29,12 @@ export const useDispatchConnectionStore = create<ConnectionStore>((set) => ({
message: "",
selectedZone: "LST_01",
logoffTime: "",
connect: async (uid, selectedZone, logoffTime) =>
ghostMode: false,
connect: async (uid, selectedZone, logoffTime, ghostMode) =>
new Promise((resolve) => {
set({ status: "connecting", message: "" });
dispatchSocket.auth = { uid };
set({ selectedZone, logoffTime });
set({ selectedZone, logoffTime, ghostMode });
dispatchSocket.connect();
dispatchSocket.once("connect", () => {
@@ -40,11 +47,12 @@ export const useDispatchConnectionStore = create<ConnectionStore>((set) => ({
}));
dispatchSocket.on("connect", () => {
const { logoffTime, selectedZone } = useDispatchConnectionStore.getState();
const { logoffTime, selectedZone, ghostMode } = useDispatchConnectionStore.getState();
useAudioStore.getState().connect("LST_01", selectedZone || "Leitstelle");
dispatchSocket.emit("connect-dispatch", {
logoffTime,
selectedZone,
ghostMode,
});
useDispatchConnectionStore.setState({ status: "connected", message: "" });
});

View File

@@ -10,6 +10,7 @@ export async function GET(request: Request): Promise<NextResponse> {
const connectedDispatcher = await prisma.connectedDispatcher.findMany({
where: {
logoutTime: null,
ghostMode: false, // Ensure we only get non-ghost mode connections
...filter, // Ensure filter is parsed correctly
},
include: {