import { ChatContext } from '@/app/chat-context'; import { apiInterceptors, getChatFeedBackItme, postChatFeedBackForm } from '@/client/api'; import { FeedBack } from '@/types/chat'; import { ChatFeedBackSchema } from '@/types/db'; import { CloseRounded, MoreHoriz } from '@mui/icons-material'; import { Box, Button, Dropdown, Grid, IconButton, Menu, MenuButton, MenuItem, Option, Select, Sheet, Slider, Textarea, Typography, styled, } from '@mui/joy'; import { Tooltip, message } from 'antd'; import { useCallback, useContext, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; type Props = { conv_index: number; question: any; knowledge_space: string; select_param?: FeedBack; }; const ChatFeedback = ({ conv_index, question, knowledge_space, select_param }: Props) => { const { t } = useTranslation(); const { chatId } = useContext(ChatContext); const [ques_type, setQuesType] = useState(''); const [score, setScore] = useState(4); const [text, setText] = useState(''); const action = useRef(null); const [messageApi, contextHolder] = message.useMessage(); const handleOpenChange = useCallback( (_: any, isOpen: boolean) => { if (isOpen) { apiInterceptors(getChatFeedBackItme(chatId, conv_index)) .then(res => { const finddata = res[1] ?? {}; setQuesType(finddata.ques_type ?? ''); setScore(parseInt(finddata.score ?? '4')); setText(finddata.messages ?? ''); }) .catch(err => { console.log(err); }); } else { setQuesType(''); setScore(4); setText(''); } }, [chatId, conv_index], ); const marks = [ { value: 0, label: '0' }, { value: 1, label: '1' }, { value: 2, label: '2' }, { value: 3, label: '3' }, { value: 4, label: '4' }, { value: 5, label: '5' }, ]; function valueText(value: number) { return { 0: t('Lowest'), 1: t('Missed'), 2: t('Lost'), 3: t('Incorrect'), 4: t('Verbose'), 5: t('Best'), }[value]; } const Item = styled(Sheet)(({ theme }) => ({ backgroundColor: theme.palette.mode === 'dark' ? '#FBFCFD' : '#0E0E10', ...theme.typography['body-sm'], padding: theme.spacing(1), display: 'flex', alignItems: 'center', justifyContent: 'center', borderRadius: 4, width: '100%', height: '100%', })); const handleSubmit = (event: any) => { event.preventDefault(); const formData: ChatFeedBackSchema = { conv_uid: chatId, conv_index: conv_index, question: question, knowledge_space: knowledge_space, score: score, ques_type: ques_type, messages: text, }; apiInterceptors( postChatFeedBackForm({ data: formData, }), ) .then(_ => { messageApi.open({ type: 'success', content: 'save success' }); }) .catch(_ => { messageApi.open({ type: 'error', content: 'save error' }); }); }; return ( {contextHolder}
{t('Q_A_Category')}
{t('feed_back_desc')}
} variant='solid' placement='left' > {t('Q_A_Rating')}
setScore(event.target?.value)} value={score} />