You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uploading.tsx 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { RiLoader2Line } from '@remixicon/react'
  5. import Card from '../../../card'
  6. import type { Dependency, PluginDeclaration } from '../../../types'
  7. import Button from '@/app/components/base/button'
  8. import { useTranslation } from 'react-i18next'
  9. import { uploadFile } from '@/service/plugins'
  10. const i18nPrefix = 'plugin.installModal'
  11. type Props = {
  12. isBundle: boolean
  13. file: File
  14. onCancel: () => void
  15. onPackageUploaded: (result: {
  16. uniqueIdentifier: string
  17. manifest: PluginDeclaration
  18. }) => void
  19. onBundleUploaded: (result: Dependency[]) => void
  20. onFailed: (errorMsg: string) => void
  21. }
  22. const Uploading: FC<Props> = ({
  23. isBundle,
  24. file,
  25. onCancel,
  26. onPackageUploaded,
  27. onBundleUploaded,
  28. onFailed,
  29. }) => {
  30. const { t } = useTranslation()
  31. const fileName = file.name
  32. const handleUpload = async () => {
  33. try {
  34. await uploadFile(file, isBundle)
  35. }
  36. catch (e: any) {
  37. if (e.response?.message) {
  38. onFailed(e.response?.message)
  39. }
  40. else { // Why it would into this branch?
  41. const res = e.response
  42. if (isBundle) {
  43. onBundleUploaded(res)
  44. return
  45. }
  46. onPackageUploaded({
  47. uniqueIdentifier: res.unique_identifier,
  48. manifest: res.manifest,
  49. })
  50. }
  51. }
  52. }
  53. React.useEffect(() => {
  54. handleUpload()
  55. }, [])
  56. return (
  57. <>
  58. <div className='flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3'>
  59. <div className='flex items-center gap-1 self-stretch'>
  60. <RiLoader2Line className='h-4 w-4 animate-spin-slow text-text-accent' />
  61. <div className='system-md-regular text-text-secondary'>
  62. {t(`${i18nPrefix}.uploadingPackage`, {
  63. packageName: fileName,
  64. })}
  65. </div>
  66. </div>
  67. <div className='flex flex-wrap content-start items-start gap-1 self-stretch rounded-2xl bg-background-section-burn p-2'>
  68. <Card
  69. className='w-full'
  70. payload={{ name: fileName } as any}
  71. isLoading
  72. loadingFileName={fileName}
  73. installed={false}
  74. />
  75. </div>
  76. </div>
  77. {/* Action Buttons */}
  78. <div className='flex items-center justify-end gap-2 self-stretch p-6 pt-5'>
  79. <Button variant='secondary' className='min-w-[72px]' onClick={onCancel}>
  80. {t('common.operation.cancel')}
  81. </Button>
  82. <Button
  83. variant='primary'
  84. className='min-w-[72px]'
  85. disabled
  86. >
  87. {t(`${i18nPrefix}.install`)}
  88. </Button>
  89. </div>
  90. </>
  91. )
  92. }
  93. export default React.memo(Uploading)