'use client' import type { FC } from 'react' import React from 'react' import type { PluginDeclaration } from '../../../types' import Card from '../../../card' import { pluginManifestToCardPluginProps } from '../../utils' import Button from '@/app/components/base/button' import { Trans, useTranslation } from 'react-i18next' import { RiLoader2Line } from '@remixicon/react' import Badge, { BadgeState } from '@/app/components/base/badge/index' import { useInstallPackageFromLocal } from '@/service/use-plugins' import checkTaskStatus from '../../base/check-task-status' import { usePluginTaskList } from '@/service/use-plugins' const i18nPrefix = 'plugin.installModal' type Props = { uniqueIdentifier: string payload: PluginDeclaration onCancel: () => void onStartToInstall?: () => void onInstalled: () => void onFailed: (message?: string) => void } const Installed: FC = ({ uniqueIdentifier, payload, onCancel, onStartToInstall, onInstalled, onFailed, }) => { const { t } = useTranslation() const [isInstalling, setIsInstalling] = React.useState(false) const { mutateAsync: installPackageFromLocal } = useInstallPackageFromLocal() const { check, stop, } = checkTaskStatus() const handleCancel = () => { stop() onCancel() } const { handleRefetch } = usePluginTaskList() const handleInstall = async () => { if (isInstalling) return setIsInstalling(true) onStartToInstall?.() try { const { all_installed: isInstalled, task_id: taskId, } = await installPackageFromLocal(uniqueIdentifier) if (isInstalled) { onInstalled() return } handleRefetch() await check({ taskId, pluginUniqueIdentifier: uniqueIdentifier, }) onInstalled() } catch (e) { if (typeof e === 'string') { onFailed(e) return } onFailed() } } return ( <>

{t(`${i18nPrefix}.readyToInstall`)}

}} />

{payload.version}} />
{/* Action Buttons */}
{!isInstalling && ( )}
) } export default React.memo(Installed)