feat: install bundle ui

This commit is contained in:
Joel
2024-11-12 17:32:39 +08:00
parent 3716ea46b5
commit 9c6aafd415
8 changed files with 148 additions and 47 deletions

View File

@ -1,9 +1,13 @@
'use client'
import type { FC } from 'react'
import React, { useState } from 'react'
import Modal from '@/app/components/base/modal'
import React, { useCallback, useState } from 'react'
import { InstallStep } from '../../types'
import type { PluginDeclaration } from '../../types'
import SelectPackage from './steps/select-package'
import Install from './steps/install'
import { useTranslation } from 'react-i18next'
const i18nPrefix = 'plugin.installModal'
export enum InstallType {
fromLocal = 'fromLocal',
@ -14,24 +18,47 @@ export enum InstallType {
type Props = {
installType?: InstallType
plugins?: PluginDeclaration[]
onClose: () => void
}
const InstallBundle: FC<Props> = ({
installType = InstallType.fromMarketplace,
plugins = [],
onClose,
}) => {
const { t } = useTranslation()
const [step, setStep] = useState<InstallStep>(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading)
const [selectedPlugins, setSelectedPlugins] = useState<PluginDeclaration[]>([])
const handleSelectedPluginsChange = (plugins: PluginDeclaration[]) => {
setSelectedPlugins(plugins)
}
const getTitle = useCallback(() => {
if (step === InstallStep.uploadFailed)
return t(`${i18nPrefix}.uploadFailed`)
if (step === InstallStep.installed)
return t(`${i18nPrefix}.installedSuccessfully`)
if (step === InstallStep.installFailed)
return t(`${i18nPrefix}.installFailed`)
return t(`${i18nPrefix}.installPlugin`)
}, [step, t])
return (
<div>
<Modal
isShow={true}
onClose={onClose}
className='flex min-w-[560px] p-0 flex-col items-start rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadows-shadow-xl'
closable
>
<div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'>
<div className='self-stretch text-text-primary title-2xl-semi-bold'>
{getTitle()}
</div>
</div>
{step === InstallStep.readyToInstall && (
<SelectPackage plugins={plugins || []} onChange={handleSelectedPluginsChange} />
<Install
plugins={plugins || []}
onCancel={onClose}
/>
)}
</div>
</Modal>
)
}