Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

page.tsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. 'use client';
  2. import React from 'react';
  3. import PageTitle from '@/components/ui/PageTitle';
  4. import {
  5. EyeOutlined,
  6. EditOutlined,
  7. SortAscendingOutlined,
  8. PlusCircleFilled
  9. } from '@ant-design/icons';
  10. import type { Knowledge } from '@/types/knowledge';
  11. import { useRouter } from 'next/navigation';
  12. import { useQuery } from '@tanstack/react-query';
  13. import PrimaryButton from '@/components/ui/PrimaryButton';
  14. import { Flex, Row, Col, Tag, Button, Table, Layout, Image, Typography } from 'antd';
  15. import type { ColumnsType } from 'antd/es/table';
  16. import { getAllKnowledge } from '@/app/api/user/knowledgeService';
  17. const { Text, Title } = Typography;
  18. const columns: ColumnsType<Knowledge> = [
  19. {
  20. title: (
  21. <Text className="flex items-center gap-1">
  22. Knowledge Source <SortAscendingOutlined className="text-xs text-gray-400" />
  23. </Text>
  24. ),
  25. dataIndex: 'name',
  26. key: 'name'
  27. },
  28. {
  29. title: (
  30. <Text className="flex items-center gap-1">
  31. AI Persona <SortAscendingOutlined className="text-xs text-gray-400" />
  32. </Text>
  33. ),
  34. dataIndex: 'personas',
  35. key: 'personas',
  36. render: (_: any, record: Knowledge) => {
  37. if (!record.personas?.length) return '-';
  38. return (
  39. <Flex wrap>
  40. {record.personas.map((persona) => (
  41. <Tag key={persona.id} color="blue">
  42. {persona.name}
  43. </Tag>
  44. ))}
  45. </Flex>
  46. );
  47. },
  48. },
  49. {
  50. title: 'Action',
  51. key: 'action',
  52. align: 'center' as const,
  53. render: (_: any, record: Knowledge) => (
  54. <Flex justify="center">
  55. <Button type="text" icon={<EditOutlined />} />
  56. <Button type="text" icon={<EyeOutlined />} />
  57. </Flex>
  58. ),
  59. },
  60. ]
  61. const Knowledge: React.FC = () => {
  62. const { data: knowledges, error, isLoading } = useQuery<Knowledge[]>({
  63. queryKey: ["getAllKnowledge"],
  64. queryFn: () => getAllKnowledge()
  65. })
  66. if (isLoading) {
  67. return <p>Loading...</p>
  68. }
  69. if (!knowledges) {
  70. return <p></p>
  71. }
  72. return (
  73. <main className="flex flex-col bg-white h-full">
  74. <PageTitle>KNOWLEDGE SOURCES</PageTitle>
  75. {knowledges.length > 0 ? <KnowledgeList knowledgeData={knowledges} /> : <EmptyKnowledgeIntro />}
  76. </main>
  77. );
  78. };
  79. const EmptyKnowledgeIntro: React.FC = () => {
  80. const router = useRouter();
  81. return (
  82. <Flex vertical flex={1} justify="center" align="center">
  83. <Row justify="center" style={{ width: '100%', padding: '0 24px' }}>
  84. <Col xs={24} sm={20} md={16} lg={12} xl={8}>
  85. <Flex
  86. vertical
  87. align="center"
  88. className="!text-center"
  89. style={{
  90. border: '2px solid #06b6d4', // cyan-500
  91. borderRadius: 12,
  92. padding: '40px 24px',
  93. boxShadow: '0 10px 100px 30px rgba(59, 130, 246, 0.3)',
  94. background: '#fff',
  95. }}
  96. >
  97. <Title level={5} style={{ color: '#1f2937', marginBottom: 8 }}>
  98. NO SOURCE ADDED YET
  99. </Title>
  100. <Text type="secondary" style={{ marginBottom: 24 }}>
  101. Get started by adding your first knowledge source
  102. </Text>
  103. <Image
  104. src="/ruccan_logo2.png"
  105. alt="Ruccan Logo"
  106. width={150}
  107. preview={false}
  108. style={{ marginBottom: 24 }}
  109. />
  110. <PrimaryButton onClick={()=>{router.push("/user/knowledge/create")}}>
  111. ADD FIRST SOURCE
  112. </PrimaryButton>
  113. </Flex>
  114. </Col>
  115. </Row>
  116. </Flex>
  117. );
  118. };
  119. interface KnowledgeListProps {
  120. knowledgeData: Knowledge[] | undefined;
  121. }
  122. const KnowledgeList: React.FC<KnowledgeListProps> = ({ knowledgeData }) => {
  123. const router = useRouter();
  124. return (
  125. <Layout className="!overflow-x-auto">
  126. <Flex className='!px-2 !py-4 !justify-end'>
  127. <PrimaryButton onClick={() => { router.push('knowledge/create') }}>
  128. <PlusCircleFilled /> Add Source
  129. </PrimaryButton>
  130. </Flex>
  131. <Table
  132. className="[&_.ant-table-cell]:!p-2"
  133. rowKey="id"
  134. columns={columns}
  135. dataSource={knowledgeData}
  136. pagination={false}
  137. bordered
  138. />
  139. </Layout>
  140. );
  141. };
  142. export default Knowledge;