index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use client'
  2. import type { FC } from 'react'
  3. import Modal from '@/app/components/base/modal'
  4. import React, { useCallback, useState } from 'react'
  5. import { InstallStep } from '../../types'
  6. import type { Dependency } from '../../types'
  7. import ReadyToInstall from './ready-to-install'
  8. import { useTranslation } from 'react-i18next'
  9. import useHideLogic from '../hooks/use-hide-logic'
  10. import cn from '@/utils/classnames'
  11. const i18nPrefix = 'plugin.installModal'
  12. export enum InstallType {
  13. fromLocal = 'fromLocal',
  14. fromMarketplace = 'fromMarketplace',
  15. fromDSL = 'fromDSL',
  16. }
  17. type Props = {
  18. installType?: InstallType
  19. fromDSLPayload: Dependency[]
  20. // plugins?: PluginDeclaration[]
  21. onClose: () => void
  22. }
  23. const InstallBundle: FC<Props> = ({
  24. installType = InstallType.fromMarketplace,
  25. fromDSLPayload,
  26. onClose,
  27. }) => {
  28. const { t } = useTranslation()
  29. const [step, setStep] = useState<InstallStep>(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading)
  30. const {
  31. modalClassName,
  32. foldAnimInto,
  33. setIsInstalling,
  34. handleStartToInstall,
  35. } = useHideLogic(onClose)
  36. const getTitle = useCallback(() => {
  37. if (step === InstallStep.uploadFailed)
  38. return t(`${i18nPrefix}.uploadFailed`)
  39. if (step === InstallStep.installed)
  40. return t(`${i18nPrefix}.installComplete`)
  41. return t(`${i18nPrefix}.installPlugin`)
  42. }, [step, t])
  43. return (
  44. <Modal
  45. isShow={true}
  46. onClose={foldAnimInto}
  47. className={cn(modalClassName, 'shadows-shadow-xl flex min-w-[560px] flex-col items-start rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg p-0')}
  48. closable
  49. >
  50. <div className='flex items-start gap-2 self-stretch pb-3 pl-6 pr-14 pt-6'>
  51. <div className='title-2xl-semi-bold self-stretch text-text-primary'>
  52. {getTitle()}
  53. </div>
  54. </div>
  55. <ReadyToInstall
  56. step={step}
  57. onStepChange={setStep}
  58. onStartToInstall={handleStartToInstall}
  59. setIsInstalling={setIsInstalling}
  60. allPlugins={fromDSLPayload}
  61. onClose={onClose}
  62. />
  63. </Modal>
  64. )
  65. }
  66. export default React.memo(InstallBundle)