"use client"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Label } from "@/components/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 if (connection && !connections.some(c => c.clientId == connection.clientId && c.name == connection.name && c.token == connection.token)) 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]) }, []) return (