wwf
2025-05-20 938c3e5a587ce950a94964ea509b9e7f8834dfae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import type { PluginDeclaration } from '../../types'
import { InstallStep } from '../../types'
import Install from './steps/install'
import Installed from '../base/installed'
import useRefreshPluginList from '../hooks/use-refresh-plugin-list'
 
type Props = {
  step: InstallStep
  onStepChange: (step: InstallStep) => void,
  onStartToInstall: () => void
  setIsInstalling: (isInstalling: boolean) => void
  onClose: () => void
  uniqueIdentifier: string | null,
  manifest: PluginDeclaration | null,
  errorMsg: string | null,
  onError: (errorMsg: string) => void,
}
 
const ReadyToInstall: FC<Props> = ({
  step,
  onStepChange,
  onStartToInstall,
  setIsInstalling,
  onClose,
  uniqueIdentifier,
  manifest,
  errorMsg,
  onError,
}) => {
  const { refreshPluginList } = useRefreshPluginList()
 
  const handleInstalled = useCallback((notRefresh?: boolean) => {
    onStepChange(InstallStep.installed)
    if (!notRefresh)
      refreshPluginList(manifest)
    setIsInstalling(false)
  }, [manifest, onStepChange, refreshPluginList, setIsInstalling])
 
  const handleFailed = useCallback((errorMsg?: string) => {
    onStepChange(InstallStep.installFailed)
    setIsInstalling(false)
    if (errorMsg)
      onError(errorMsg)
  }, [onError, onStepChange, setIsInstalling])
 
  return (
    <>
      {
        step === InstallStep.readyToInstall && (
          <Install
            uniqueIdentifier={uniqueIdentifier!}
            payload={manifest!}
            onCancel={onClose}
            onInstalled={handleInstalled}
            onFailed={handleFailed}
            onStartToInstall={onStartToInstall}
          />
        )
      }
      {
        ([InstallStep.uploadFailed, InstallStep.installed, InstallStep.installFailed].includes(step)) && (
          <Installed
            payload={manifest}
            isFailed={[InstallStep.uploadFailed, InstallStep.installFailed].includes(step)}
            errMsg={errorMsg}
            onCancel={onClose}
          />
        )
      }
    </>
  )
}
export default React.memo(ReadyToInstall)