|
1 | 1 | import { Send } from '@mui/icons-material'
|
2 |
| -import { Container, IconButton, Paper, TextField } from '@mui/material' |
3 |
| -import { useState } from 'react' |
| 2 | +import { Box, Container, IconButton, Paper, TextField, Typography } from '@mui/material' |
| 3 | +import { useEffect, useState } from 'react' |
| 4 | +import useUserStatus from '../../hooks/useUserStatus'; |
| 5 | +import { useParams } from 'react-router-dom'; |
| 6 | +import { useTranslation } from 'react-i18next'; |
4 | 7 |
|
5 | 8 | export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (message: string) => void }) => {
|
| 9 | + const { courseId } = useParams() |
| 10 | + const { userStatus, isLoading: statusLoading, refetch: refetchStatus } = useUserStatus(courseId) |
6 | 11 | const [message, setMessage] = useState<string>('')
|
7 | 12 |
|
| 13 | + const { t, i18n } = useTranslation() |
8 | 14 | const handleSubmit = (e: React.FormEvent) => {
|
9 | 15 | e.preventDefault()
|
10 | 16 | if (message.trim()) {
|
11 | 17 | onSubmit(message)
|
12 | 18 | setMessage('')
|
| 19 | + refetchStatus() |
13 | 20 | }
|
14 | 21 | }
|
| 22 | + useEffect(() => { |
| 23 | + console.log('userStatus', userStatus) |
| 24 | + }) |
15 | 25 |
|
| 26 | + if(statusLoading) { |
| 27 | + return (<p>loading</p>) |
| 28 | + } |
16 | 29 | return (
|
17 | 30 | <Container
|
18 | 31 | disableGutters
|
@@ -60,6 +73,12 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
|
60 | 73 | },
|
61 | 74 | }}
|
62 | 75 | />
|
| 76 | + <Box> |
| 77 | + <Typography variant="body1"> |
| 78 | + {userStatus.usage} / {userStatus.limit} {t('status:tokensUsed')} |
| 79 | + </Typography> |
| 80 | + </Box> |
| 81 | + |
63 | 82 | </Paper>
|
64 | 83 | </Container>
|
65 | 84 | )
|
|
0 commit comments