|
|
|
@ -8,7 +8,6 @@ import Uploading from './steps/uploading'
|
|
|
|
import Install from './steps/install'
|
|
|
|
import Install from './steps/install'
|
|
|
|
import Installed from '../base/installed'
|
|
|
|
import Installed from '../base/installed'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { toolNotionManifest } from '../../card/card-mock'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const i18nPrefix = 'plugin.installModal'
|
|
|
|
const i18nPrefix = 'plugin.installModal'
|
|
|
|
|
|
|
|
|
|
|
|
@ -23,19 +22,21 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
|
|
|
|
onClose,
|
|
|
|
onClose,
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { t } = useTranslation()
|
|
|
|
// uploading -> readyToInstall -> installed/failed
|
|
|
|
// uploading -> !uploadFailed -> readyToInstall -> installed/failed
|
|
|
|
const [step, setStep] = useState<InstallStep>(InstallStep.uploading)
|
|
|
|
const [step, setStep] = useState<InstallStep>(InstallStep.uploading)
|
|
|
|
|
|
|
|
|
|
|
|
const [uniqueIdentifier, setUniqueIdentifier] = useState<string | null>(null)
|
|
|
|
const [uniqueIdentifier, setUniqueIdentifier] = useState<string | null>(null)
|
|
|
|
|
|
|
|
const [manifest, setManifest] = useState<PluginDeclaration | null>(null)
|
|
|
|
|
|
|
|
const [errorMsg, setErrorMsg] = useState<string | null>(null)
|
|
|
|
const getTitle = useCallback(() => {
|
|
|
|
const getTitle = useCallback(() => {
|
|
|
|
|
|
|
|
if (step === InstallStep.uploadFailed)
|
|
|
|
|
|
|
|
return t(`${i18nPrefix}.uploadFailed`)
|
|
|
|
if (step === InstallStep.installed)
|
|
|
|
if (step === InstallStep.installed)
|
|
|
|
return t(`${i18nPrefix}.installedSuccessfully`)
|
|
|
|
return t(`${i18nPrefix}.installedSuccessfully`)
|
|
|
|
if (step === InstallStep.installFailed)
|
|
|
|
if (step === InstallStep.installFailed)
|
|
|
|
return t(`${i18nPrefix}.installFailed`)
|
|
|
|
return t(`${i18nPrefix}.installFailed`)
|
|
|
|
|
|
|
|
|
|
|
|
return t(`${i18nPrefix}.installPlugin`)
|
|
|
|
return t(`${i18nPrefix}.installPlugin`)
|
|
|
|
}, [step])
|
|
|
|
}, [step])
|
|
|
|
const [manifest, setManifest] = useState<PluginDeclaration | null>(toolNotionManifest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleUploaded = useCallback((result: {
|
|
|
|
const handleUploaded = useCallback((result: {
|
|
|
|
uniqueIdentifier: string
|
|
|
|
uniqueIdentifier: string
|
|
|
|
@ -46,6 +47,11 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
|
|
|
|
setStep(InstallStep.readyToInstall)
|
|
|
|
setStep(InstallStep.readyToInstall)
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleUploadFail = useCallback((errorMsg: string) => {
|
|
|
|
|
|
|
|
setErrorMsg(errorMsg)
|
|
|
|
|
|
|
|
setStep(InstallStep.uploadFailed)
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
const handleInstalled = useCallback(async () => {
|
|
|
|
const handleInstalled = useCallback(async () => {
|
|
|
|
setStep(InstallStep.installed)
|
|
|
|
setStep(InstallStep.installed)
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
@ -71,6 +77,7 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
|
|
|
|
file={file}
|
|
|
|
file={file}
|
|
|
|
onCancel={onClose}
|
|
|
|
onCancel={onClose}
|
|
|
|
onUploaded={handleUploaded}
|
|
|
|
onUploaded={handleUploaded}
|
|
|
|
|
|
|
|
onFailed={handleUploadFail}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -84,10 +91,11 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
([InstallStep.installed, InstallStep.installFailed].includes(step)) && (
|
|
|
|
([InstallStep.uploadFailed, InstallStep.installed, InstallStep.installFailed].includes(step)) && (
|
|
|
|
<Installed
|
|
|
|
<Installed
|
|
|
|
payload={manifest!}
|
|
|
|
payload={manifest}
|
|
|
|
isFailed={step === InstallStep.installFailed}
|
|
|
|
isFailed={[InstallStep.uploadFailed, InstallStep.installFailed].includes(step)}
|
|
|
|
|
|
|
|
errMsg={errorMsg}
|
|
|
|
onCancel={onClose}
|
|
|
|
onCancel={onClose}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|