'use client' import type { FC } from 'react' import React from 'react' import { RiLoader2Line } from '@remixicon/react' import Card from '../../../card' import type { PluginDeclaration } from '../../../types' import Button from '@/app/components/base/button' import { useTranslation } from 'react-i18next' import { uploadPackageFile } from '@/service/plugins' const i18nPrefix = 'plugin.installModal' type Props = { file: File onCancel: () => void onUploaded: (result: { uniqueIdentifier: string manifest: PluginDeclaration }) => void onFailed: (errorMsg: string) => void } const Uploading: FC = ({ file, onCancel, onUploaded, onFailed, }) => { const { t } = useTranslation() const fileName = file.name const handleUpload = async () => { try { const res = await uploadPackageFile(file) // onUploaded(res) } catch (e: any) { if (e.response?.message) { onFailed(e.response?.message) } else { // Why it would into this branch? const res = e.response onUploaded({ uniqueIdentifier: res.unique_identifier, manifest: res.manifest, }) } } } React.useEffect(() => { handleUpload() }, []) return ( <>
{t(`${i18nPrefix}.uploadingPackage`, { packageName: fileName, })}
{/* Action Buttons */}
) } export default React.memo(Uploading)