|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
'use client'
|
|
|
|
|
import type { FC } from 'react'
|
|
|
|
|
import React, { useMemo } from 'react'
|
|
|
|
|
import { RiInformation2Line } from '@remixicon/react'
|
|
|
|
|
// import { RiInformation2Line } from '@remixicon/react'
|
|
|
|
|
import type { Plugin, PluginManifestInMarket } from '../../../types'
|
|
|
|
|
import Card from '../../../card'
|
|
|
|
|
import { pluginManifestInMarketToPluginProps } from '../../utils'
|
|
|
|
|
@ -9,8 +9,9 @@ import Button from '@/app/components/base/button'
|
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
import { RiLoader2Line } from '@remixicon/react'
|
|
|
|
|
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
|
|
|
|
import { useInstallPackageFromMarketPlace } from '@/service/use-plugins'
|
|
|
|
|
import { useInstallPackageFromMarketPlace, useUpdatePackageFromMarketPlace } from '@/service/use-plugins'
|
|
|
|
|
import checkTaskStatus from '../../base/check-task-status'
|
|
|
|
|
import useCheckInstalled from '@/app/components/plugins/install-plugin/hooks/use-check-installed'
|
|
|
|
|
|
|
|
|
|
const i18nPrefix = 'plugin.installModal'
|
|
|
|
|
|
|
|
|
|
@ -32,7 +33,18 @@ const Installed: FC<Props> = ({
|
|
|
|
|
onFailed,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
const toInstallVersion = payload.version || payload.latest_version
|
|
|
|
|
const pluginId = (payload as Plugin).plugin_id
|
|
|
|
|
const { installedInfo } = useCheckInstalled({
|
|
|
|
|
pluginIds: [pluginId],
|
|
|
|
|
enabled: !!pluginId,
|
|
|
|
|
})
|
|
|
|
|
const installedInfoPayload = installedInfo?.[pluginId]
|
|
|
|
|
const installedVersion = installedInfoPayload?.installedVersion
|
|
|
|
|
const hasInstalled = !!installedVersion
|
|
|
|
|
|
|
|
|
|
const { mutateAsync: installPackageFromMarketPlace } = useInstallPackageFromMarketPlace()
|
|
|
|
|
const { mutateAsync: updatePackageFromMarketPlace } = useUpdatePackageFromMarketPlace()
|
|
|
|
|
const [isInstalling, setIsInstalling] = React.useState(false)
|
|
|
|
|
const {
|
|
|
|
|
check,
|
|
|
|
|
@ -50,10 +62,28 @@ const Installed: FC<Props> = ({
|
|
|
|
|
setIsInstalling(true)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const {
|
|
|
|
|
all_installed: isInstalled,
|
|
|
|
|
task_id: taskId,
|
|
|
|
|
} = await installPackageFromMarketPlace(uniqueIdentifier)
|
|
|
|
|
let taskId
|
|
|
|
|
let isInstalled
|
|
|
|
|
if (hasInstalled) {
|
|
|
|
|
const {
|
|
|
|
|
all_installed,
|
|
|
|
|
task_id,
|
|
|
|
|
} = await updatePackageFromMarketPlace({
|
|
|
|
|
original_plugin_unique_identifier: installedInfoPayload.uniqueIdentifier,
|
|
|
|
|
new_plugin_unique_identifier: uniqueIdentifier,
|
|
|
|
|
})
|
|
|
|
|
taskId = task_id
|
|
|
|
|
isInstalled = all_installed
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const {
|
|
|
|
|
all_installed,
|
|
|
|
|
task_id,
|
|
|
|
|
} = await installPackageFromMarketPlace(uniqueIdentifier)
|
|
|
|
|
taskId = task_id
|
|
|
|
|
isInstalled = all_installed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isInstalled) {
|
|
|
|
|
onInstalled()
|
|
|
|
|
return
|
|
|
|
|
@ -73,28 +103,25 @@ const Installed: FC<Props> = ({
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toInstallVersion = '1.3.0'
|
|
|
|
|
const supportCheckInstalled = false // TODO: check installed in beta version.
|
|
|
|
|
|
|
|
|
|
const versionInfo = useMemo(() => {
|
|
|
|
|
return (<>{
|
|
|
|
|
payload.latest_version === toInstallVersion || !supportCheckInstalled
|
|
|
|
|
!installedVersion
|
|
|
|
|
? (
|
|
|
|
|
<Badge className='mx-1' size="s" state={BadgeState.Default}>{payload.version || payload.latest_version}</Badge>
|
|
|
|
|
<Badge className='mx-1' size="s" state={BadgeState.Default}>{ }</Badge>
|
|
|
|
|
)
|
|
|
|
|
: (
|
|
|
|
|
<>
|
|
|
|
|
<Badge className='mx-1' size="s" state={BadgeState.Warning}>
|
|
|
|
|
{`${payload.latest_version} -> ${toInstallVersion}`}
|
|
|
|
|
{`${installedVersion} -> ${toInstallVersion}`}
|
|
|
|
|
</Badge>
|
|
|
|
|
<div className='flex px-0.5 justify-center items-center gap-0.5'>
|
|
|
|
|
{/* <div className='flex px-0.5 justify-center items-center gap-0.5'>
|
|
|
|
|
<div className='text-text-warning system-xs-medium'>Used in 3 apps</div>
|
|
|
|
|
<RiInformation2Line className='w-4 h-4 text-text-tertiary' />
|
|
|
|
|
</div>
|
|
|
|
|
</div> */}
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}</>)
|
|
|
|
|
}, [payload.latest_version, payload.version, supportCheckInstalled])
|
|
|
|
|
}, [installedVersion, payload])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
|