index.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use client'
  2. import React, { useState } from 'react'
  3. import { useRouter } from 'next/navigation'
  4. import { useToastContext } from '@/app/components/base/toast'
  5. import ExternalKnowledgeBaseCreate from '@/app/components/datasets/external-knowledge-base/create'
  6. import type { CreateKnowledgeBaseReq } from '@/app/components/datasets/external-knowledge-base/create/declarations'
  7. import { createExternalKnowledgeBase } from '@/service/datasets'
  8. const ExternalKnowledgeBaseConnector = () => {
  9. const { notify } = useToastContext()
  10. const [loading, setLoading] = useState(false)
  11. const router = useRouter()
  12. const handleConnect = async (formValue: CreateKnowledgeBaseReq) => {
  13. try {
  14. setLoading(true)
  15. const result = await createExternalKnowledgeBase({ body: formValue })
  16. if (result && result.id) {
  17. notify({ type: 'success', message: 'External Knowledge Base Connected Successfully' })
  18. router.back()
  19. }
  20. else { throw new Error('Failed to create external knowledge base') }
  21. }
  22. catch (error) {
  23. console.error('Error creating external knowledge base:', error)
  24. notify({ type: 'error', message: 'Failed to connect External Knowledge Base' })
  25. }
  26. setLoading(false)
  27. }
  28. return (
  29. <ExternalKnowledgeBaseCreate onConnect={handleConnect} loading={loading} />
  30. )
  31. }
  32. export default ExternalKnowledgeBaseConnector