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

@@ -50,6 +50,34 @@ export const ConnectionBtn = () => {
};
}, [connection.disconnect]);
const logoffTime = form.logoffTime;
useEffect(() => {
if (!logoffTime || !connection.connectedAircraft) return;
if (logoffDebounce) clearTimeout(logoffDebounce);
const timeout = setTimeout(async () => {
if (!connection.connectedAircraft?.id) return;
await aircraftMutation.mutateAsync({
sessionId: connection.connectedAircraft.id,
change: {
esimatedLogoutTime: logoffTime
? new Date(new Date().toDateString() + " " + logoffTime).toISOString()
: null,
},
});
toast.success("Änderung gespeichert!");
}, 2000);
setLogoffDebounce(timeout);
// Cleanup function to clear timeout
return () => {
if (logoffDebounce) clearTimeout(logoffDebounce);
};
}, [logoffTime, connection.connectedAircraft]);
const session = useSession();
const uid = session.data?.user?.id;
if (!uid) return null;
@@ -126,20 +154,6 @@ export const ConnectionBtn = () => {
...form,
logoffTime: value,
});
if (logoffDebounce) clearTimeout(logoffDebounce);
const timeout = setTimeout(async () => {
if (!connection.connectedAircraft) return;
await aircraftMutation.mutateAsync({
sessionId: connection.connectedAircraft.id,
change: {
esimatedLogoutTime: value
? new Date(new Date().toDateString() + " " + value).toISOString()
: null,
},
});
toast.success("Änderung gespeichert!");
}, 2000);
setLogoffDebounce(timeout);
}}
value={form.logoffTime ?? ""}
type="time"