"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(() => { /* getStations().then((data) => { setStations(data); if (data[0]) { setForm({ ...form, selectedStationId: data[0].id, }); } }); */ }, [connection.status, form]); 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 Disponent anmelden

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

Du kannst diese Zeit später noch anpassen.

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