getNextHourTime zu shared library hinzugefügt

This commit is contained in:
PxlLoewe
2025-06-27 22:54:31 -07:00
parent dc92174798
commit ec22cdb987
14 changed files with 89 additions and 62 deletions

View File

@@ -6,6 +6,7 @@ import { toast } from "react-hot-toast";
import { useMutation } from "@tanstack/react-query";
import { Prisma } from "@repo/db";
import { changeDispatcherAPI } from "_querys/dispatcher";
import { getNextDateWithTime } from "@repo/shared-components";
export const ConnectionBtn = () => {
const modalRef = useRef<HTMLDialogElement>(null);
@@ -24,17 +25,19 @@ export const ConnectionBtn = () => {
if (!uid) return null;
// useEffect für die Logoff-Zeit
const [logoffHours, logoffMinutes] = form.logoffTime?.split(":").map(Number) || [];
useEffect(() => {
if (!logoffHours || !logoffMinutes) return;
if (logoffDebounce) clearTimeout(logoffDebounce);
const timeout = setTimeout(async () => {
if (!form.logoffTime || !connection.connectedDispatcher) return;
if (!logoffHours || !logoffMinutes || !connection.connectedDispatcher) return;
await changeDispatcherMutation.mutateAsync({
id: connection.connectedDispatcher?.id,
data: {
esimatedLogoutTime: new Date(
new Date().toDateString() + " " + form.logoffTime,
).toISOString(),
esimatedLogoutTime:
logoffHours && logoffMinutes ? getNextDateWithTime(logoffHours, logoffMinutes) : null,
},
});
toast.success("Änderung gespeichert!");