'use client'; import React, { useState, useEffect } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Loader2, Search, Zap } from 'lucide-react'; import { pipedreamApi } from '@/hooks/react-query/pipedream/utils'; interface PipedreamApp { name: string; name_slug: string; description?: string; categories?: string[]; logo?: string; } interface PipedreamAppBrowserProps { open: boolean; onOpenChange: (open: boolean) => void; onSelectApp: (app: { app_slug: string; app_name: string }) => void; } export const PipedreamAppBrowser: React.FC = ({ open, onOpenChange, onSelectApp, }) => { const [apps, setApps] = useState([]); const [loading, setLoading] = useState(false); const [searchQuery, setSearchQuery] = useState(''); const [selectedCategory, setSelectedCategory] = useState(null); useEffect(() => { if (open) { loadApps(); } }, [open]); const loadApps = async () => { setLoading(true); try { const response = await pipedreamApi.getApps(); if (response.success) { setApps(response.apps); } } catch (error) { console.error('Failed to load apps:', error); } finally { setLoading(false); } }; const filteredApps = apps.filter(app => { const matchesSearch = !searchQuery || app.name.toLowerCase().includes(searchQuery.toLowerCase()) || app.name_slug.toLowerCase().includes(searchQuery.toLowerCase()); const matchesCategory = !selectedCategory || app.categories?.includes(selectedCategory); return matchesSearch && matchesCategory; }); const categories = Array.from( new Set(apps.flatMap(app => app.categories || [])) ).sort(); return ( Select an App to Connect Choose an app to create a credential profile for
{e.preventDefault()}} className="relative flex-1"> setSearchQuery(e.target.value)} className="pl-10" /> {searchQuery && ( )} {selectedCategory && ( )}
{categories.length > 0 && (
{categories.map(category => ( setSelectedCategory( selectedCategory === category ? null : category )} > {category} ))}
)} {loading ? (
) : (
{filteredApps.map(app => ( ))}
{filteredApps.length === 0 && (
No apps found matching your search
)}
)}
); };