Added time update from Dispatcher

This commit is contained in:
PxlLoewe
2025-06-02 15:32:09 -07:00
parent af36b82221
commit 41931fd276
5 changed files with 54 additions and 33 deletions

View File

@@ -23,12 +23,30 @@ export const ConnectionBtn = () => {
const uid = session.data?.user?.id;
if (!uid) return null;
// useEffect für die Logoff-Zeit
useEffect(() => {
// Disconnect the socket when the component unmounts
if (logoffDebounce) clearTimeout(logoffDebounce);
const timeout = setTimeout(async () => {
if (!form.logoffTime || !connection.connectedDispatcher) return;
await changeDispatcherMutation.mutateAsync({
id: connection.connectedDispatcher?.id,
data: {
esimatedLogoutTime: new Date(
new Date().toDateString() + " " + form.logoffTime,
).toISOString(),
},
});
toast.success("Änderung gespeichert!");
}, 2000);
setLogoffDebounce(timeout);
// Cleanup function
return () => {
connection.disconnect();
if (logoffDebounce) clearTimeout(logoffDebounce);
};
}, [connection.disconnect]);
}, [form.logoffTime, connection.connectedDispatcher]);
return (
<div className="rounded-box bg-base-200 flex justify-center items-center gap-2 p-1">
@@ -79,18 +97,6 @@ export const ConnectionBtn = () => {
...form,
logoffTime: value,
});
if (logoffDebounce) clearTimeout(logoffDebounce);
const timeout = setTimeout(async () => {
if (!connection.connectedDispatcher) return;
await changeDispatcherMutation.mutateAsync({
id: connection.connectedDispatcher?.id,
data: {
esimatedLogoutTime: value,
},
});
toast.success("Änderung gespeichert!");
}, 2000);
setLogoffDebounce(timeout);
}}
value={form.logoffTime}
type="time"