Added time update from Dispatcher
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user