'use client' import type { App } from '@/models/explore' import { PlusIcon } from '@heroicons/react/20/solid' import { RiInformation2Line } from '@remixicon/react' import { useTranslation } from 'react-i18next' // extend: start sync app import { useContextSelector } from 'use-context-selector' import { useCallback, useState } from 'react' // extend: atop sync app import { useContext } from 'use-context-selector' import AppIcon from '@/app/components/base/app-icon' import ExploreContext from '@/context/explore-context' import { useGlobalPublicStore } from '@/context/global-public-context' import { AppModeEnum } from '@/types/app' import { cn } from '@/utils/classnames' import { AppTypeIcon } from '../../app/type-selector' import Button from '../../base/button' import Confirm from '@/app/components/base/confirm' import Toast, { ToastContext } from '@/app/components/base/toast' // extend: start sync app import { syncApp } from '@/service/apps' // extend: stop sync app import { useAppContext } from '@/context/app-context' export type AppCardProps = { app: App canCreate: boolean onCreate: () => void isExplore: boolean // extend: start sync app onApp?: boolean // 是否在推荐列表中(已同步) onRefresh?: () => void // extend: stop sync app } const AppCard = ({ app, canCreate, onCreate, isExplore, onApp = false, onRefresh, }: AppCardProps) => { const { t } = useTranslation() const { notify } = useContext(ToastContext) const { userProfile } = useAppContext() const { app: appBasicInfo } = app const { systemFeatures } = useGlobalPublicStore() const isTrialApp = app.can_trial && systemFeatures.enable_trial_app const setShowTryAppPanel = useContextSelector(ExploreContext, ctx => ctx.setShowTryAppPanel) const showTryAPPPanel = useCallback((appId: string) => { return () => { setShowTryAppPanel?.(true, { appId, app }) } }, [setShowTryAppPanel, app]) // ----------------------start SyncToAppTemplate---------------------- const [showSyncApps, setShowSyncApps] = useState(false) // app click sync const onSyncApps = useCallback(async () => { try { await syncApp({ appID: app.app_id }) notify({ type: 'success', message: t('app.syncAppOk', { ns: 'extend' }) }) if (onRefresh) onRefresh() } catch (e: any) { notify({ type: 'error', message: e.message || '操作失败', }) } setShowSyncApps(false) }, [app.app_id, notify, onRefresh, t]) // ----------------------stop SyncToAppTemplate---------------------- return (
{appBasicInfo.name}
{appBasicInfo.mode === AppModeEnum.ADVANCED_CHAT &&
{t('types.advanced', { ns: 'app' }).toUpperCase()}
} {appBasicInfo.mode === AppModeEnum.CHAT &&
{t('types.chatbot', { ns: 'app' }).toUpperCase()}
} {appBasicInfo.mode === AppModeEnum.AGENT_CHAT &&
{t('types.agent', { ns: 'app' }).toUpperCase()}
} {appBasicInfo.mode === AppModeEnum.WORKFLOW &&
{t('types.workflow', { ns: 'app' }).toUpperCase()}
} {appBasicInfo.mode === AppModeEnum.COMPLETION &&
{t('types.completion', { ns: 'app' }).toUpperCase()}
}
{app.description}
{isExplore && (canCreate || isTrialApp) && ( )} {/* ----------------------start SyncToAppTemplate---------------------- */} {isExplore && userProfile?.admin_extend && userProfile?.tenant_extend && !onApp && ( )} {showSyncApps && ( setShowSyncApps(false)} /> )} {/* ----------------------stop SyncToAppTemplate---------------------- */}
) } export default AppCard