"use client"; import { useSession } from "next-auth/react"; import { usePilotConnectionStore } from "../../../_store/pilot/connectionStore"; import { useEffect, useRef, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { getStationsAPI } from "querys/stations"; export const ConnectionBtn = () => { const modalRef = useRef(null); const connection = usePilotConnectionStore((state) => state); const [form, setForm] = useState<{ logoffTime: string | null; selectedStationId: number | null; }>({ logoffTime: null, selectedStationId: null, }); const { data: stations } = useQuery({ queryKey: ["stations"], queryFn: () => getStationsAPI(), }); useEffect(() => { if (stations && stations.length > 0 && form.selectedStationId === null) { setForm((prevForm) => ({ ...prevForm, selectedStationId: stations[0]?.id ?? null, })); } }, [stations, form.selectedStationId]); const session = useSession(); const uid = session.data?.user?.id; if (!uid) return null; return (
{connection.message.length > 0 && ( {connection.message} )} {connection.status === "disconnected" && ( )} {connection.status == "connected" && ( )}
{connection.status == "connected" ? (

Verbunden als{" "} <{connection.selectedStation?.bosCallsign}>

) : (

Als Pilot anmelden

)}
{connection.status == "disconnected" && (

Du kannst diese Zeit später noch anpassen.

)}
{connection.status == "connected" ? ( ) : ( )}
); }; export const Connection = () => { return (
); };