dify/web/app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx

73 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-10-22 17:21:25 +08:00
'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 { sleep } from '@/utils'
2024-10-22 18:11:47 +08:00
import { Trans, useTranslation } from 'react-i18next'
const i18nPrefix = 'plugin.installModal'
2024-10-22 17:21:25 +08:00
type Props = {
payload: PluginDeclaration
onCancel: () => void
onInstalled: () => void
}
const Installed: FC<Props> = ({
payload,
onCancel,
onInstalled,
}) => {
2024-10-22 18:11:47 +08:00
const { t } = useTranslation()
2024-10-22 17:21:25 +08:00
const [isInstalling, setIsInstalling] = React.useState(false)
const handleInstall = async () => {
if (isInstalling) return
setIsInstalling(true)
await sleep(1500)
onInstalled()
}
return (
<>
<div className='flex flex-col px-6 py-3 justify-center items-start gap-4 self-stretch'>
<div className='text-text-secondary system-md-regular'>
2024-10-22 18:11:47 +08:00
<p>{t(`${i18nPrefix}.readyToInstall`)}</p>
<p>
<Trans
i18nKey={`${i18nPrefix}.fromTrustSource`}
components={{ trustSource: <span className='system-md-semibold' /> }}
/>
</p>
2024-10-22 17:21:25 +08:00
</div>
<div className='flex p-2 items-start content-start gap-1 self-stretch flex-wrap rounded-2xl bg-background-section-burn'>
<Card
className='w-full'
payload={pluginManifestToCardPluginProps(payload)}
/>
</div>
</div>
{/* Action Buttons */}
<div className='flex p-6 pt-5 justify-end items-center gap-2 self-stretch'>
{!isInstalling && (
<Button variant='secondary' className='min-w-[72px]' onClick={onCancel}>
2024-10-22 18:11:47 +08:00
{t('common.operation.cancel')}
2024-10-22 17:21:25 +08:00
</Button>
)}
<Button
variant='primary'
className='min-w-[72px]'
disabled={isInstalling}
onClick={handleInstall}
>
2024-10-22 18:11:47 +08:00
{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}
2024-10-22 17:21:25 +08:00
</Button>
</div>
</>
)
}
export default React.memo(Installed)