'use client' import React, { useMemo, useState } from 'react' import { RiInformation2Line } from '@remixicon/react' import Card from '../../card' import { extensionDallE, modelGPT4, toolNotion } from '../../card/card-mock' import Modal from '@/app/components/base/modal' import Button from '@/app/components/base/button' import Checkbox from '@/app/components/base/checkbox' import Badge, { BadgeState } from '@/app/components/base/badge/index' type InstallFromMarketplaceProps = { onClose: () => void } const InstallFromMarketplace: React.FC = ({ onClose }) => { const plugins = useMemo(() => [toolNotion, extensionDallE, modelGPT4], []) const [selectedPlugins, setSelectedPlugins] = useState>(new Set()) const [isInstalling, setIsInstalling] = useState(false) const [nextStep, setNextStep] = useState(false) const mockInstall = async () => { setIsInstalling(true) await new Promise(resolve => setTimeout(resolve, 1500)) setIsInstalling(false) } const pluginsToShow = useMemo(() => { if (plugins.length === 1 || (nextStep && selectedPlugins.size === 1)) return plugins.length === 1 ? plugins : plugins.filter((_, index) => selectedPlugins.has(index)) return nextStep ? plugins.filter((_, index) => selectedPlugins.has(index)) : plugins }, [plugins, nextStep, selectedPlugins]) const renderPluginCard = (plugin: any, index: number) => ( {plugin.version} ) : ( <> {`${plugin.version} -> ${plugin.latest_version}`}
Used in 3 apps
) } /> ) return (
{nextStep ? (isInstalling ? 'Install plugin' : 'Installation successful') : 'Install plugin'}
{(nextStep && !isInstalling) ? `The following ${pluginsToShow.length === 1 ? 'plugin has' : `${pluginsToShow.length} plugins have`} been installed successfully` : `About to install the following ${pluginsToShow.length === 1 ? 'plugin' : `${pluginsToShow.length} plugins`}`}
{pluginsToShow.map((plugin, index) => (
1 && !nextStep) ? 'pl-1 items-center gap-2' : ''} flex-grow`}> {(plugins.length > 1 && !nextStep) && ( { const newSelectedPlugins = new Set(selectedPlugins) newSelectedPlugins.has(index) ? newSelectedPlugins.delete(index) : newSelectedPlugins.add(index) setSelectedPlugins(newSelectedPlugins) }} /> )} {renderPluginCard(plugin, index)}
))}
{nextStep ? ( ) : ( <> )}
) } export default InstallFromMarketplace