This commit is contained in:
PxlLoewe
2025-06-02 13:02:02 -07:00
6 changed files with 56 additions and 46 deletions

View File

@@ -2,6 +2,7 @@
import { useSession } from "next-auth/react";
import { useDispatchConnectionStore } from "../../../../_store/dispatch/connectionStore";
import { useRef, useState } from "react";
import { toast } from "react-hot-toast";
export const ConnectionBtn = () => {
const modalRef = useRef<HTMLDialogElement>(null);
@@ -10,6 +11,7 @@ export const ConnectionBtn = () => {
logoffTime: "",
selectedZone: "LST_01",
});
const [logoffDebounce, setLogoffDebounce] = useState<NodeJS.Timeout | null>(null);
const session = useSession();
const uid = session.data?.user?.id;
if (!uid) return null;
@@ -22,14 +24,14 @@ export const ConnectionBtn = () => {
{connection.status == "connected" ? (
<button
className="btn btn-soft btn-error"
className="btn btn-sm btn-soft btn-success"
type="submit"
onSubmit={() => false}
onClick={() => {
connection.disconnect();
modalRef.current?.showModal();
}}
>
Trennen
Verbunden
</button>
) : (
<button
@@ -40,9 +42,7 @@ export const ConnectionBtn = () => {
}}
className="btn btn-sm btn-soft btn-info"
>
{connection.status == "disconnected"
? "Verbinden"
: connection.status}
{connection.status == "disconnected" ? "Verbinden" : connection.status}
</button>
)}
@@ -50,10 +50,7 @@ export const ConnectionBtn = () => {
<div className="modal-box flex flex-col items-center justify-center">
{connection.status == "connected" ? (
<h3 className="text-lg font-bold mb-5">
Verbunden als{" "}
<span className="text-info">
&lt;{connection.selectedZone}&gt;
</span>
Verbunden als <span className="text-info">&lt;{connection.selectedZone}&gt;</span>
</h3>
) : (
<h3 className="text-lg font-bold mb-5">Als Disponent anmelden</h3>
@@ -62,26 +59,30 @@ export const ConnectionBtn = () => {
<label className="floating-label w-full text-base">
<span>Logoff Zeit (UTC+1)</span>
<input
onChange={(e) =>
onChange={(e) => {
const value = e.target.value;
setForm({
...form,
logoffTime: e.target.value,
})
}
logoffTime: value,
});
if (logoffDebounce) clearTimeout(logoffDebounce);
const timeout = setTimeout(() => {
toast.success("Änderung gespeichert!");
}, 2000);
setLogoffDebounce(timeout);
}}
value={form.logoffTime}
type="time"
className="input w-full"
/>
</label>
{connection.status == "disconnected" && (
<p className="fieldset-label">
Du kannst diese Zeit später noch anpassen.
</p>
<p className="fieldset-label">Du kannst diese Zeit später noch anpassen.</p>
)}
</fieldset>
<div className="modal-action flex justify-between w-full">
<form method="dialog" className="w-full flex justify-between">
<button className="btn btn-soft">Abbrechen</button>
<button className="btn btn-soft">Zurück</button>
{connection.status == "connected" ? (
<button
className="btn btn-soft btn-error"