You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use client';
  2. import { useState } from 'react';
  3. import type { Chat } from '@/types/chat';
  4. import { Flex, Layout, Row, Col, Input, Space, Upload, Button, Image } from 'antd';
  5. import PageTitle from '@/components/ui/PageTitle';
  6. import Navigation from '@/components/layout/Navigation'
  7. import { useParams } from 'next/navigation'
  8. import { useQuery } from '@tanstack/react-query';
  9. import { getChat } from '@/app/api/user/chatService';
  10. import { PaperClipOutlined, SendOutlined } from '@ant-design/icons'
  11. import LoadingScreen from '@/components/layout/LoadingScreen';
  12. import ErrorPage from '@/components/layout/ErrorPage';
  13. const ChatPage: React.FC = () => {
  14. const params = useParams()
  15. const chatID = Number(params.chatID);
  16. const { data: chat, error, isLoading } = useQuery<Chat | undefined>({
  17. queryKey: ["getChat"],
  18. queryFn: () => getChat(chatID)
  19. })
  20. const [enabled, setEnabled] = useState(false);
  21. if (isLoading) return <LoadingScreen />
  22. if (error) return <ErrorPage/>
  23. return (
  24. <Layout className="!w-full !max-w-[430px] !mx-auto !relative !bg-white">
  25. <Flex vertical className='!h-screen'>
  26. <Row>
  27. <Col span={24}>
  28. <PageTitle position='center' backButton={true}>{chat?.name}</PageTitle>
  29. <div className="bg-white shadow p-4 flex flex-row border-b-2">
  30. <div>
  31. <Image
  32. src="/default-avatar.png"
  33. alt="Profile"
  34. className="w-15 h-15 rounded-full object-cover border"
  35. />
  36. </div>
  37. <div className='ps-2'>
  38. <p className="text-xl text-gray-500">{ }</p>
  39. <p className="text-md text-gray-500">{chat?.persona?.role}</p>
  40. </div>
  41. <div className='ps-2 flex flex-row gap-2 items-center ms-auto'>
  42. <span>Live</span>
  43. <button
  44. onClick={() => setEnabled(!enabled)}
  45. className={`w-12 h-6 flex items-center rounded-full p-1 transition-colors duration-300 ${enabled ? 'bg-blue-500' : 'bg-gray-300'
  46. }`}
  47. >
  48. <div
  49. className={`bg-white w-4 h-4 rounded-full shadow-md transform transition-transform duration-300 ${enabled ? 'translate-x-6' : 'translate-x-0'
  50. }`}
  51. />
  52. </button>
  53. <span>Offline</span>
  54. </div>
  55. </div>
  56. </Col>
  57. </Row>
  58. <Row className='flex-1 overflow-y-scroll overflow-x-hidden'>
  59. <Col span={24}>
  60. <Flex vertical className="!bg-white">
  61. {/* Chat messages */}
  62. <div className="flex-1 overflow-y-auto px-4 py-6 space-y-4">
  63. {chat?.chatList.map((msg, index) => (
  64. <div key={index}>
  65. <p className={`mb-1 text-gray-500 ${msg.self ? 'text-left' : 'text-right'}`}>
  66. {msg.self ? 'Visitor' : 'Ruccan Chat'}
  67. </p>
  68. <div className={`flex ${msg.self ? 'justify-start' : 'justify-end'}`}>
  69. <div className={`max-w-xs whitespace-pre-wrap px-4 py-2 rounded-lg text-sm ${msg.self ? 'bg-white text-gray-800 shadow' : 'bg-blue-500 text-white'}`}>
  70. {msg.text}
  71. <div className="text-[10px] mt-1 text-right opacity-70">
  72. {msg.time}
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. ))}
  78. </div>
  79. </Flex>
  80. </Col>
  81. </Row>
  82. <div>
  83. <Flex vertical={false} className="!bg-gray-200 !p-4" align="center" justify="space-between">
  84. <Input.TextArea
  85. placeholder="Write a message"
  86. className='!bg-gray-200 !border-0 !text-black'
  87. autoSize={{ minRows: 1, maxRows: 4 }}
  88. style={{ color: 'black', fontSize: 20, resize: 'none', flex: 1 }}
  89. />
  90. <Space size="middle" className="!ps-3">
  91. <Upload showUploadList={false}>
  92. <Button
  93. icon={<PaperClipOutlined style={{ fontSize: 24 }} />}
  94. type="text"
  95. size="large"
  96. style={{ height: 28, width: 28, padding: 0 }}
  97. />
  98. </Upload>
  99. <Button
  100. icon={<SendOutlined style={{ fontSize: 24 }} />}
  101. type="text"
  102. size="large"
  103. style={{ height: 28, width: 28, padding: 0 }}
  104. />
  105. </Space>
  106. </Flex>
  107. <Navigation />
  108. </div>
  109. </Flex>
  110. </Layout>
  111. );
  112. };
  113. export default ChatPage;