"use client"; import axios from "axios"; import * as React from 'react'; import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { ConnectionElement, ConnectionAdderElement } from "@/components/elements/connection"; import { ConnectionDefaultElement } from "@/components/elements/connection-default"; const ConnectionsPage = () => { const { data: session, status } = useSession(); const [loading, setLoading] = useState(true) const [connections, setConnections] = useState<{ name: string, clientId: string, token: string, type: string, scope: string, expiresAt: Date }[]>([]) useEffect(() => { if (status != "authenticated") return const fetchData = async () => { setLoading(true) const response = await axios.get("/api/connection") const data = response.data setConnections(data.data) } fetchData().catch(console.error).finally(() => setLoading(false)) }, [session]) const OnConnectionDelete = async (name: string) => { setConnections(connections.filter(c => c.name != name)) } const OnDefaultConnectionUpdate = async (name: string) => { if (!connections.some(c => c.name == name)) return axios.put('/api/connection/default', { name: name }) .then(d => { setConnections([...connections]) }) } return (
Connections
{connections.map((connection) => )} {!loading && }
{connections.length > 0 &&

Default Connections

}
); } export default ConnectionsPage;