1
1
import { Edit , OpenInNew } from '@mui/icons-material'
2
- import {
3
- Alert ,
4
- Box ,
5
- Button ,
6
- Checkbox ,
7
- Container ,
8
- FormControlLabel ,
9
- Input ,
10
- Modal ,
11
- Paper ,
12
- Skeleton ,
13
- Stack ,
14
- Tab ,
15
- TextField ,
16
- Tooltip ,
17
- Typography ,
18
- } from '@mui/material'
2
+ import { Alert , Box , Button , Checkbox , Container , FormControlLabel , Input , Modal , Paper , Skeleton , Stack , Tab , Tooltip , Typography } from '@mui/material'
19
3
import { enqueueSnackbar } from 'notistack'
20
4
import { useEffect , useState } from 'react'
21
5
import { useTranslation } from 'react-i18next'
22
- import { Form , Link , Route , Routes , useParams } from 'react-router-dom'
6
+ import { Link , Route , Routes , useParams } from 'react-router-dom'
23
7
24
8
import { PUBLIC_URL } from '../../../../config'
25
9
import useCourse from '../../../hooks/useCourse'
@@ -38,9 +22,7 @@ import { RouterTabs } from '../../common/RouterTabs'
38
22
import Discussion from './Discussions'
39
23
import { ApiErrorView } from '../../common/ApiErrorView'
40
24
import apiClient from '../../../util/apiClient'
41
- import { t } from 'i18next'
42
- import UserTable from '../../Admin/Usage/UserTable'
43
- import UserSearch , { ActionUserSearch } from '../../Admin/UserSearch'
25
+ import { ActionUserSearch } from '../../Admin/UserSearch'
44
26
45
27
const Course = ( ) => {
46
28
const [ showTeachers , setShowTeachers ] = useState ( false )
@@ -53,22 +35,22 @@ const Course = () => {
53
35
const { language } = i18n
54
36
55
37
const { user, isLoading : userLoading } = useCurrentUser ( )
56
- const { data : course , isSuccess : isCourseSuccess , error, refetch : refetchCourse } = useCourse ( id )
57
- console . log ( course )
38
+ const { data : chatInstance , isSuccess : isCourseSuccess , error, refetch : refetchCourse } = useCourse ( id )
39
+ console . log ( chatInstance )
58
40
if ( error ) {
59
41
return < ApiErrorView error = { error } />
60
42
}
61
43
useEffect ( ( ) => {
62
44
if ( isCourseSuccess ) {
63
- setResponsibilities ( course ?. responsibilities )
45
+ setResponsibilities ( chatInstance ?. responsibilities )
64
46
}
65
47
} , [ isCourseSuccess ] )
66
48
67
49
if ( userLoading || ! user || ! isCourseSuccess ) return null
68
50
69
- const studentLink = `${ window . location . origin } ${ PUBLIC_URL } /${ course . courseId } `
51
+ const studentLink = `${ window . location . origin } ${ PUBLIC_URL } /${ chatInstance . courseId } `
70
52
71
- const amongResponsibles = course . responsibilities ? course . responsibilities . some ( ( r ) => r . user . id === user . id ) : false
53
+ const amongResponsibles = chatInstance . responsibilities ? chatInstance . responsibilities . some ( ( r ) => r . user . id === user . id ) : false
72
54
73
55
if ( ! user . isAdmin && ! amongResponsibles ) {
74
56
return (
@@ -83,13 +65,14 @@ const Course = () => {
83
65
enqueueSnackbar ( t ( 'linkCopied' ) , { variant : 'info' } )
84
66
}
85
67
86
- const courseEnabled = course . usageLimit > 0
68
+ const courseEnabled = chatInstance . usageLimit > 0
87
69
88
- const isCourseActive = courseEnabled && Date . parse ( course . activityPeriod . endDate ) > Date . now ( ) && Date . parse ( course . activityPeriod . startDate ) <= Date . now ( )
70
+ const isCourseActive =
71
+ courseEnabled && Date . parse ( chatInstance . activityPeriod . endDate ) > Date . now ( ) && Date . parse ( chatInstance . activityPeriod . startDate ) <= Date . now ( )
89
72
90
- const willBeEnabled = courseEnabled && Date . parse ( course . activityPeriod . startDate ) > Date . now ( )
73
+ const willBeEnabled = courseEnabled && Date . parse ( chatInstance . activityPeriod . startDate ) > Date . now ( )
91
74
92
- const wasEnabled = courseEnabled && Date . parse ( course . activityPeriod . endDate ) < Date . now ( )
75
+ const wasEnabled = courseEnabled && Date . parse ( chatInstance . activityPeriod . endDate ) < Date . now ( )
93
76
94
77
const getInfoSeverity = ( ) => {
95
78
if ( ! courseEnabled ) return 'warning'
@@ -100,8 +83,8 @@ const Course = () => {
100
83
const getInfoMessage = ( ) => {
101
84
if ( ! courseEnabled ) return t ( 'course:curreNotOpen' )
102
85
if ( isCourseActive ) return t ( 'course:curreOpen' )
103
- if ( willBeEnabled ) return `${ t ( 'course:curreWillBeOpen' ) } ${ course . activityPeriod . startDate } `
104
- if ( wasEnabled ) return `${ t ( 'course:curreWasOpen' ) } ${ course . activityPeriod . endDate } `
86
+ if ( willBeEnabled ) return `${ t ( 'course:curreWillBeOpen' ) } ${ chatInstance . activityPeriod . startDate } `
87
+ if ( wasEnabled ) return `${ t ( 'course:curreWasOpen' ) } ${ chatInstance . activityPeriod . endDate } `
105
88
return ''
106
89
}
107
90
@@ -124,15 +107,15 @@ const Course = () => {
124
107
}
125
108
const handleAddResponsible = async ( user : User ) => {
126
109
const username = user . username
127
- const result = await apiClient . post ( `/courses/${ course . id } /responsibilities/assign` , { username : username } )
110
+ const result = await apiClient . post ( `/courses/${ chatInstance . id } /responsibilities/assign` , { username : username } )
128
111
if ( result . status === 200 ) {
129
112
const responsibility = result . data
130
113
setResponsibilities ( [ ...responsibilities , responsibility ] )
131
114
refetchCourse ( )
132
115
}
133
116
}
134
117
const handleRemoveResponsibility = async ( responsibility ) => {
135
- const result = await apiClient . post ( `/courses/${ course . id } /responsibilities/remove` , { username : responsibility . user ?. username } )
118
+ const result = await apiClient . post ( `/courses/${ chatInstance . id } /responsibilities/remove` , { username : responsibility . user ?. username } )
136
119
if ( result . status === 200 ) {
137
120
const filteredResponsibilities = responsibilities . filter ( ( r ) => r . id !== responsibility . id )
138
121
setResponsibilities ( filteredResponsibilities )
@@ -155,33 +138,33 @@ const Course = () => {
155
138
>
156
139
< div style = { { display : 'flex' , flexWrap : 'wrap' } } >
157
140
< div style = { { ...full , boxSizing : 'border-box' , height : '50px' } } >
158
- < Typography variant = "h5" > { course . name [ language ] } </ Typography >
141
+ < Typography variant = "h5" > { chatInstance . name [ language ] } </ Typography >
159
142
</ div >
160
143
161
144
< div style = { { ...left , boxSizing : 'border-box' , height : '50px' } } >
162
- < Typography > { course . courseUnits . map ( ( cu ) => cu . code ) . join ( ', ' ) } </ Typography >
145
+ < Typography > { chatInstance . courseUnits . map ( ( cu ) => cu . code ) . join ( ', ' ) } </ Typography >
163
146
</ div >
164
147
< div style = { { ...right , boxSizing : 'border-box' , height : '50px' } } >
165
- < Typography style = { { fontStyle : 'italic' } } > { getCurTypeLabel ( course . courseUnitRealisationTypeUrn ?? '' , language ) } </ Typography >
148
+ < Typography style = { { fontStyle : 'italic' } } > { getCurTypeLabel ( chatInstance . courseUnitRealisationTypeUrn ?? '' , language ) } </ Typography >
166
149
</ div >
167
150
168
151
< div style = { { ...left , boxSizing : 'border-box' } } >
169
152
< Typography >
170
- { t ( 'active' ) } { formatDate ( course . activityPeriod ) }
153
+ { t ( 'active' ) } { formatDate ( chatInstance . activityPeriod ) }
171
154
</ Typography >
172
155
</ div >
173
156
174
157
< div style = { { ...right , boxSizing : 'border-box' } } >
175
- < Link to = { `https://studies.helsinki.fi/kurssit/toteutus/${ course . courseId } ` } target = "_blank" >
158
+ < Link to = { `https://studies.helsinki.fi/kurssit/toteutus/${ chatInstance . courseId } ` } target = "_blank" >
176
159
{ t ( 'course:coursePage' ) } < OpenInNew fontSize = "small" />
177
160
</ Link >
178
161
</ div >
179
162
180
163
{ courseEnabled && (
181
164
< div style = { { ...left , boxSizing : 'border-box' } } >
182
165
< Typography >
183
- { t ( 'admin:model' ) } : { course . model } < span style = { { marginRight : 20 } } />
184
- { t ( 'admin:usageLimit' ) } : { course . usageLimit }
166
+ { t ( 'admin:model' ) } : { chatInstance . model } < span style = { { marginRight : 20 } } />
167
+ { t ( 'admin:usageLimit' ) } : { chatInstance . usageLimit }
185
168
</ Typography >
186
169
</ div >
187
170
) }
@@ -267,8 +250,7 @@ const Course = () => {
267
250
height : '80vh' ,
268
251
background : 'white' ,
269
252
padding : '2rem' ,
270
- overflowY : 'scroll'
271
-
253
+ overflowY : 'scroll' ,
272
254
} }
273
255
>
274
256
< ActionUserSearch
@@ -282,7 +264,7 @@ const Course = () => {
282
264
</ Modal >
283
265
284
266
< Modal open = { activityPeriodFormOpen } onClose = { ( ) => setActivityPeriodFormOpen ( false ) } >
285
- < EditCourseForm course = { course } setOpen = { setActivityPeriodFormOpen } user = { user } />
267
+ < EditCourseForm course = { chatInstance } setOpen = { setActivityPeriodFormOpen } user = { user } />
286
268
</ Modal >
287
269
288
270
< Box my = { 2 } >
@@ -297,15 +279,15 @@ const Course = () => {
297
279
< Routes >
298
280
< Route path = "/" element = { < Stats courseId = { id } /> } />
299
281
< Route path = { `/discussions/*` } element = { < Discussion /> } />
300
- < Route path = "/prompts" element = { < Prompts courseId = { id } /> } />
282
+ < Route path = "/prompts" element = { < Prompts courseId = { id } chatInstanceId = { chatInstance . id } /> } />
301
283
< Route path = "/rag" element = { < Rag /> } />
302
284
</ Routes >
303
285
</ Container >
304
286
)
305
287
}
306
288
307
289
const AssignedResponsibilityManagement = ( { responsibility, handleRemove } ) => {
308
- const { t, i18n } = useTranslation ( )
290
+ const { t } = useTranslation ( )
309
291
if ( ! responsibility . createdByUserId ) {
310
292
return < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } > </ Stack >
311
293
}
@@ -317,7 +299,7 @@ const AssignedResponsibilityManagement = ({ responsibility, handleRemove }) => {
317
299
)
318
300
}
319
301
320
- const Prompts = ( { courseId } : { courseId : string } ) => {
302
+ const Prompts = ( { courseId, chatInstanceId } : { courseId : string ; chatInstanceId : string } ) => {
321
303
const { t } = useTranslation ( )
322
304
const [ name , setName ] = useState ( '' )
323
305
const [ system , setSystem ] = useState ( '' )
@@ -343,7 +325,7 @@ const Prompts = ({ courseId }: { courseId: string }) => {
343
325
const handleSave = async ( ) => {
344
326
try {
345
327
await createMutation . mutateAsync ( {
346
- chatInstanceId : courseId ,
328
+ chatInstanceId,
347
329
type : 'CHAT_INSTANCE' ,
348
330
name,
349
331
systemMessage : system ,
0 commit comments