'use client' import React from 'react' import type { Item } from '@/app/components/base/select' import { PortalSelect } from '@/app/components/base/select' import Button from '@/app/components/base/button' import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../../types' import { useTranslation } from 'react-i18next' import { useGitHubUpload } from '../../hooks' const i18nPrefix = 'plugin.installFromGitHub' type SelectPackageProps = { updatePayload: UpdateFromGitHubPayload repoUrl: string selectedVersion: string versions: Item[] onSelectVersion: (item: Item) => void selectedPackage: string packages: Item[] onSelectPackage: (item: Item) => void onUploaded: (result: { uniqueIdentifier: string manifest: PluginDeclaration }) => void onFailed: (errorMsg: string) => void onBack: () => void } const SelectPackage: React.FC = ({ updatePayload, repoUrl, selectedVersion, versions, onSelectVersion, selectedPackage, packages, onSelectPackage, onUploaded, onFailed, onBack, }) => { const { t } = useTranslation() const isEdit = Boolean(updatePayload) const [isUploading, setIsUploading] = React.useState(false) const { handleUpload } = useGitHubUpload() const handleUploadPackage = async () => { if (isUploading) return setIsUploading(true) try { const repo = repoUrl.replace('https://github.com/', '') await handleUpload(repo, selectedVersion, selectedPackage, (GitHubPackage) => { onUploaded({ uniqueIdentifier: GitHubPackage.unique_identifier, manifest: GitHubPackage.manifest, }) }) } catch (e: any) { if (e.response?.message) onFailed(e.response?.message) else onFailed(t(`${i18nPrefix}.uploadFailed`)) } finally { setIsUploading(false) } } return ( <>
{!isEdit && }
) } export default SelectPackage