|
@@ -8,7 +8,7 @@ import DetailModal from './detail-modal'
|
|
|
import { useContext } from 'use-context-selector'
|
|
|
import { RiAddLine } from '@remixicon/react'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
-import { fetchKnowledges } from '@/service/common'
|
|
|
+import { delKnowledge, fetchKnowledges } from '@/service/common'
|
|
|
import I18n from '@/context/i18n'
|
|
|
import { useAppContext } from '@/context/app-context'
|
|
|
import LogoEmbeddedChatHeader from '@/app/components/base/logo/logo-embedded-chat-header'
|
|
@@ -19,19 +19,23 @@ import UpgradeBtn from '@/app/components/billing/upgrade-btn'
|
|
|
import { NUM_INFINITE } from '@/app/components/billing/config'
|
|
|
import { LanguagesSupported } from '@/i18n/language'
|
|
|
import cn from '@/utils/classnames'
|
|
|
+import Confirm from '@/app/components/base/confirm'
|
|
|
+import useTimestamp from '@/hooks/use-timestamp'
|
|
|
dayjs.extend(relativeTime)
|
|
|
|
|
|
const KnowledgesPage = () => {
|
|
|
const { t } = useTranslation()
|
|
|
const { locale } = useContext(I18n)
|
|
|
+ const { formatTime } = useTimestamp()
|
|
|
+
|
|
|
const ServiceTypeMap: any = {
|
|
|
- 1: '智能问答',
|
|
|
- 2: '智能搜索',
|
|
|
- 3: '智能推荐',
|
|
|
+ QUESTION_ANSWER: '智能问答',
|
|
|
+ SEARCH: '智能搜索',
|
|
|
+ RECOMMEND: '智能推荐',
|
|
|
}
|
|
|
const StatusMap: any = {
|
|
|
- 0: '未启用',
|
|
|
- 1: '已启用',
|
|
|
+ false: '未启用',
|
|
|
+ true: '已启用',
|
|
|
}
|
|
|
const { userProfile, currentWorkspace, isCurrentWorkspaceOwner, isCurrentWorkspaceManager, systemFeatures } = useAppContext()
|
|
|
const { data, mutate }: any = useSWR(
|
|
@@ -47,13 +51,26 @@ const KnowledgesPage = () => {
|
|
|
const [detailModalVisible, setDetailModalVisible] = useState(false)
|
|
|
const [transfer, setTransfer] = useState<any>({
|
|
|
mode: 'add',
|
|
|
- id: null,
|
|
|
+ row: null,
|
|
|
})
|
|
|
const knowledgeList = data?.data || []
|
|
|
const { plan, enableBilling } = useProviderContext()
|
|
|
const isNotUnlimitedMemberPlan = enableBilling && plan.type !== Plan.team && plan.type !== Plan.enterprise
|
|
|
const isMemberFull = enableBilling && isNotUnlimitedMemberPlan && knowledgeList.length >= plan.total.teamMembers
|
|
|
|
|
|
+ const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
|
|
+ const [row, setRow] = useState<any>({})
|
|
|
+ const handleDel = async () => {
|
|
|
+ try {
|
|
|
+ await delKnowledge({
|
|
|
+ url: `/external_applications/${row.id}`,
|
|
|
+ body: {},
|
|
|
+ })
|
|
|
+ setShowConfirmDelete(false)
|
|
|
+ mutate()
|
|
|
+ }
|
|
|
+ catch (e) { }
|
|
|
+ }
|
|
|
return (
|
|
|
<>
|
|
|
<div className='flex flex-col'>
|
|
@@ -106,11 +123,11 @@ const KnowledgesPage = () => {
|
|
|
{
|
|
|
knowledgeList.map((know: any) => (
|
|
|
<div key={know.id} className='flex justify-between border-b border-divider-subtle'>
|
|
|
- <div className='system-sm-regular w-[100px] shrink-0 py-2 text-center text-text-secondary'>{ServiceTypeMap[Number(know.serviceType)]}</div>
|
|
|
- <div className='system-sm-regular shrink-0 grow py-2 text-center text-text-secondary'>{know.serviceName}</div>
|
|
|
+ <div className='system-sm-regular w-[100px] shrink-0 py-2 text-center text-text-secondary'>{ServiceTypeMap[know.type]}</div>
|
|
|
+ <div className='system-sm-regular shrink-0 grow py-2 text-center text-text-secondary'>{know.name}</div>
|
|
|
<div className='system-sm-regular shrink-0 grow py-2 text-center text-text-secondary'>{know.url}</div>
|
|
|
- <div className='system-sm-regular w-[80px] shrink-0 py-2 text-center text-text-secondary'>{StatusMap[Number(know.status)]}</div>
|
|
|
- <div className='system-sm-regular w-[160px] shrink-0 py-2 text-center text-text-secondary'>{know.time}</div>
|
|
|
+ <div className='system-sm-regular w-[80px] shrink-0 py-2 text-center text-text-secondary'>{StatusMap[know.status]}</div>
|
|
|
+ <div className='system-sm-regular w-[160px] shrink-0 py-2 text-center text-text-secondary'>{formatTime(know.updated_at, t('appLog.dateTimeFormat') as string)}</div>
|
|
|
<div className='flex w-[120px] shrink-0 items-center justify-center'>
|
|
|
<Button variant='ghost-accent' size='small' className={cn('shrink-0')} disabled={!isCurrentWorkspaceManager || isMemberFull}
|
|
|
onClick={() => {
|
|
@@ -123,7 +140,10 @@ const KnowledgesPage = () => {
|
|
|
<RiAddLine className='mr-1 h-4 w-4' />
|
|
|
编辑
|
|
|
</Button>
|
|
|
- <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} disabled={!isCurrentWorkspaceManager || isMemberFull} onClick={() => setDetailModalVisible(true)}>
|
|
|
+ <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} disabled={!isCurrentWorkspaceManager || isMemberFull} onClick={() => {
|
|
|
+ setRow(know)
|
|
|
+ setShowConfirmDelete(true)
|
|
|
+ }}>
|
|
|
<RiAddLine className='mr-1 h-4 w-4' />
|
|
|
刪除
|
|
|
</Button>
|
|
@@ -145,6 +165,15 @@ const KnowledgesPage = () => {
|
|
|
/>
|
|
|
)
|
|
|
}
|
|
|
+ {showConfirmDelete && (
|
|
|
+ <Confirm
|
|
|
+ title="删除确认"
|
|
|
+ content={`请确认是否删除${row.name}?`}
|
|
|
+ isShow={showConfirmDelete}
|
|
|
+ onConfirm={handleDel}
|
|
|
+ onCancel={() => setShowConfirmDelete(false)}
|
|
|
+ />
|
|
|
+ )}
|
|
|
</>
|
|
|
)
|
|
|
}
|