import { useState, useEffect } from "react"; import { Eye, EyeOff, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Skeleton } from "@/components/ui/skeleton"; import asanaLogo from "@/modules/intelligence-ia/assets/asana-logo.png"; interface Workspace { id: string; name: string; } interface User { id: string; name: string; } interface AsanaCardProps { apiKey?: string; workspaces?: Workspace[]; users?: User[]; selectedWorkspaceId?: string; selectedUserId?: string; loadingWorkspaces?: boolean; loadingUsers?: boolean; loadingIntegration?: boolean; hasIntegration?: boolean; saving?: boolean; onSave?: (apiKey: string, workspaceId: string, userId: string) => void | Promise; onConfirmApiKey?: (apiKey: string) => void | Promise; onWorkspaceChange?: (workspaceId: string) => void | Promise; } export function AsanaCard({ apiKey = "", workspaces = [], users = [], selectedWorkspaceId = "", selectedUserId = "", loadingWorkspaces = false, loadingUsers = false, loadingIntegration = false, hasIntegration = false, saving = false, onSave, onConfirmApiKey, onWorkspaceChange, }: AsanaCardProps) { const [showKey, setShowKey] = useState(false); const [key, setKey] = useState(apiKey); const [selectedWorkspace, setSelectedWorkspace] = useState(selectedWorkspaceId); const [selectedUser, setSelectedUser] = useState(selectedUserId); const [isApiKeyConfirmed, setIsApiKeyConfirmed] = useState(!!apiKey); // Atualiza os valores quando as props mudam (carregamento inicial) useEffect(() => { if (apiKey) { setKey(apiKey); setIsApiKeyConfirmed(true); } }, [apiKey]); useEffect(() => { if (selectedWorkspaceId) { setSelectedWorkspace(selectedWorkspaceId); } }, [selectedWorkspaceId]); useEffect(() => { if (selectedUserId) { setSelectedUser(selectedUserId); } }, [selectedUserId]); const handleKeyChange = (value: string) => { setKey(value); setSelectedWorkspace(""); setSelectedUser(""); setIsApiKeyConfirmed(false); }; const handleConfirmApiKey = async () => { if (key.length >= 5) { setIsApiKeyConfirmed(true); // Chama a função assíncrona para buscar workspaces await onConfirmApiKey?.(key); } }; const handleWorkspaceChange = async (value: string) => { setSelectedWorkspace(value); setSelectedUser(""); // Chama a função assíncrona para buscar usuários await onWorkspaceChange?.(value); }; const handleSave = async () => { await onSave?.(key, selectedWorkspace, selectedUser); }; return (
Asana

Asana

Gerencie tarefas e projetos

{loadingIntegration ? (
) : (
handleKeyChange(e.target.value)} placeholder="Insira sua chave de API" className="pr-10 bg-card border-border" disabled={loadingWorkspaces} />
)}
{loadingIntegration ? (
Carregando integração...
) : (
{loadingWorkspaces && (
)}
)}
{loadingUsers ? (
Carregando usuários...
) : (
)}
); }