"use client"; import { useEffect, useState } from "react"; import { Button } from "../ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Label } from "../ui/label"; import axios from "axios"; export interface ConnectionDefault { type: string, connections: { name: string, clientId: string, token: string, type: string, scope: string, expiresAt: Date }[] } export const ConnectionDefaultElement = ({ type, connections, }: ConnectionDefault) => { const [connection, setConnection] = useState<{ name: string, clientId: string, token: string, type: string, scope: string, expiresAt: Date } | undefined>(undefined) const [open, setOpen] = useState(false) const OnDefaultConnectionUpdate = function (con: { name: string, clientId: string, token: string, type: string, scope: string, expiresAt: Date }) { if (connection && con.name == connection.name) return; axios.put('/api/connection/default', { name: con.name, type: con.type }) .then(d => { setConnection(con) }) } useEffect(() => { const con = connections.filter((c: any) => c.type == type && c.default) if (con.length > 0) OnDefaultConnectionUpdate(con[0]) console.log('default', type, connections.filter(c => c.type == type).length > 0) }, []) return (