1
1
import { Edit , OpenInNew } from '@mui/icons-material'
2
- import { Alert , Box , Button , Checkbox , Container , FormControlLabel , Input , Modal , Paper , Skeleton , Stack , Tab , TextField , Tooltip , Typography } from '@mui/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'
3
19
import { enqueueSnackbar } from 'notistack'
4
20
import { useEffect , useState } from 'react'
5
21
import { useTranslation } from 'react-i18next'
@@ -35,22 +51,22 @@ const Course = () => {
35
51
const { language } = i18n
36
52
37
53
const { user, isLoading : userLoading } = useCurrentUser ( )
38
- const { data : course , isSuccess : isCourseSuccess , error, refetch : refetchCourse } = useCourse ( id )
39
- console . log ( course )
54
+ const { data : chatInstance , isSuccess : isCourseSuccess , error, refetch : refetchCourse } = useCourse ( id )
55
+ console . log ( chatInstance )
40
56
if ( error ) {
41
57
return < ApiErrorView error = { error } />
42
58
}
43
59
useEffect ( ( ) => {
44
- if ( isCourseSuccess ) {
45
- setResponsibilities ( course ?. responsibilities )
60
+ if ( isCourseSuccess ) {
61
+ setResponsibilities ( chatInstance ?. responsibilities )
46
62
}
47
63
} , [ isCourseSuccess ] )
48
64
49
65
if ( userLoading || ! user || ! isCourseSuccess ) return null
50
66
51
- const studentLink = `${ window . location . origin } ${ PUBLIC_URL } /${ course . courseId } `
67
+ const studentLink = `${ window . location . origin } ${ PUBLIC_URL } /${ chatInstance . courseId } `
52
68
53
- const amongResponsibles = course . responsibilities ? course . responsibilities . some ( ( r ) => r . user . id === user . id ) : false
69
+ const amongResponsibles = chatInstance . responsibilities ? chatInstance . responsibilities . some ( ( r ) => r . user . id === user . id ) : false
54
70
55
71
if ( ! user . isAdmin && ! amongResponsibles ) {
56
72
return (
@@ -65,13 +81,14 @@ const Course = () => {
65
81
enqueueSnackbar ( t ( 'linkCopied' ) , { variant : 'info' } )
66
82
}
67
83
68
- const courseEnabled = course . usageLimit > 0
84
+ const courseEnabled = chatInstance . usageLimit > 0
69
85
70
- const isCourseActive = courseEnabled && Date . parse ( course . activityPeriod . endDate ) > Date . now ( ) && Date . parse ( course . activityPeriod . startDate ) <= Date . now ( )
86
+ const isCourseActive =
87
+ courseEnabled && Date . parse ( chatInstance . activityPeriod . endDate ) > Date . now ( ) && Date . parse ( chatInstance . activityPeriod . startDate ) <= Date . now ( )
71
88
72
- const willBeEnabled = courseEnabled && Date . parse ( course . activityPeriod . startDate ) > Date . now ( )
89
+ const willBeEnabled = courseEnabled && Date . parse ( chatInstance . activityPeriod . startDate ) > Date . now ( )
73
90
74
- const wasEnabled = courseEnabled && Date . parse ( course . activityPeriod . endDate ) < Date . now ( )
91
+ const wasEnabled = courseEnabled && Date . parse ( chatInstance . activityPeriod . endDate ) < Date . now ( )
75
92
76
93
const getInfoSeverity = ( ) => {
77
94
if ( ! courseEnabled ) return 'warning'
@@ -82,8 +99,8 @@ const Course = () => {
82
99
const getInfoMessage = ( ) => {
83
100
if ( ! courseEnabled ) return t ( 'course:curreNotOpen' )
84
101
if ( isCourseActive ) return t ( 'course:curreOpen' )
85
- if ( willBeEnabled ) return `${ t ( 'course:curreWillBeOpen' ) } ${ course . activityPeriod . startDate } `
86
- if ( wasEnabled ) return `${ t ( 'course:curreWasOpen' ) } ${ course . activityPeriod . endDate } `
102
+ if ( willBeEnabled ) return `${ t ( 'course:curreWillBeOpen' ) } ${ chatInstance . activityPeriod . startDate } `
103
+ if ( wasEnabled ) return `${ t ( 'course:curreWasOpen' ) } ${ chatInstance . activityPeriod . endDate } `
87
104
return ''
88
105
}
89
106
@@ -107,17 +124,16 @@ const Course = () => {
107
124
const handleAddResponsible = async ( e ) => {
108
125
e . preventDefault ( )
109
126
const username = e . target . username . value
110
- const result = await apiClient . post ( `/courses/${ course . id } /responsibilities/assign` , { username : username } )
111
- if ( result . status === 200 ) {
127
+ const result = await apiClient . post ( `/courses/${ chatInstance . id } /responsibilities/assign` , { username : username } )
128
+ if ( result . status === 200 ) {
112
129
const responsibility = result . data
113
130
setResponsibilities ( [ ...responsibilities , responsibility ] )
114
131
refetchCourse ( )
115
132
}
116
-
117
133
}
118
134
const handleRemoveResponsibility = async ( responsibility ) => {
119
- const result = await apiClient . post ( `/courses/${ course . id } /responsibilities/remove` , { username : responsibility . user ?. username } )
120
- if ( result . status === 200 ) {
135
+ const result = await apiClient . post ( `/courses/${ chatInstance . id } /responsibilities/remove` , { username : responsibility . user ?. username } )
136
+ if ( result . status === 200 ) {
121
137
const filteredResponsibilities = responsibilities . filter ( ( r ) => r . id !== responsibility . id )
122
138
setResponsibilities ( filteredResponsibilities )
123
139
}
@@ -139,33 +155,33 @@ const Course = () => {
139
155
>
140
156
< div style = { { display : 'flex' , flexWrap : 'wrap' } } >
141
157
< div style = { { ...full , boxSizing : 'border-box' , height : '50px' } } >
142
- < Typography variant = "h5" > { course . name [ language ] } </ Typography >
158
+ < Typography variant = "h5" > { chatInstance . name [ language ] } </ Typography >
143
159
</ div >
144
160
145
161
< div style = { { ...left , boxSizing : 'border-box' , height : '50px' } } >
146
- < Typography > { course . courseUnits . map ( ( cu ) => cu . code ) . join ( ', ' ) } </ Typography >
162
+ < Typography > { chatInstance . courseUnits . map ( ( cu ) => cu . code ) . join ( ', ' ) } </ Typography >
147
163
</ div >
148
164
< div style = { { ...right , boxSizing : 'border-box' , height : '50px' } } >
149
- < Typography style = { { fontStyle : 'italic' } } > { getCurTypeLabel ( course . courseUnitRealisationTypeUrn ?? '' , language ) } </ Typography >
165
+ < Typography style = { { fontStyle : 'italic' } } > { getCurTypeLabel ( chatInstance . courseUnitRealisationTypeUrn ?? '' , language ) } </ Typography >
150
166
</ div >
151
167
152
168
< div style = { { ...left , boxSizing : 'border-box' } } >
153
169
< Typography >
154
- { t ( 'active' ) } { formatDate ( course . activityPeriod ) }
170
+ { t ( 'active' ) } { formatDate ( chatInstance . activityPeriod ) }
155
171
</ Typography >
156
172
</ div >
157
173
158
174
< div style = { { ...right , boxSizing : 'border-box' } } >
159
- < Link to = { `https://studies.helsinki.fi/kurssit/toteutus/${ course . courseId } ` } target = "_blank" >
175
+ < Link to = { `https://studies.helsinki.fi/kurssit/toteutus/${ chatInstance . courseId } ` } target = "_blank" >
160
176
{ t ( 'course:coursePage' ) } < OpenInNew fontSize = "small" />
161
177
</ Link >
162
178
</ div >
163
179
164
180
{ courseEnabled && (
165
181
< div style = { { ...left , boxSizing : 'border-box' } } >
166
182
< Typography >
167
- { t ( 'admin:model' ) } : { course . model } < span style = { { marginRight : 20 } } />
168
- { t ( 'admin:usageLimit' ) } : { course . usageLimit }
183
+ { t ( 'admin:model' ) } : { chatInstance . model } < span style = { { marginRight : 20 } } />
184
+ { t ( 'admin:usageLimit' ) } : { chatInstance . usageLimit }
169
185
</ Typography >
170
186
</ div >
171
187
) }
@@ -211,11 +227,18 @@ const Course = () => {
211
227
< TextField name = "username" placeholder = { 'käyttäjänimi: ' } > </ TextField >
212
228
< Button type = { 'submit' } > Lisää</ Button >
213
229
</ Form >
214
- < Stack sx = { { margin : 1 , padding : 1 , borderColor : 'gray' , borderWidth : 1 , borderStyle : 'solid' } } >
230
+ < Stack sx = { { margin : 1 , padding : 1 , borderColor : 'gray' , borderWidth : 1 , borderStyle : 'solid' } } >
215
231
{ responsibilities . map ( ( responsibility ) => (
216
- < Box key = { responsibility . id } sx = { { display : 'flex' , alignItems : 'center' , padding : 1 } } >
217
- < Typography > { responsibility . user . last_name } { responsibility . user . first_names } </ Typography >
218
- < AssignedResponsibilityManagement handleRemove = { ( ) => { handleRemoveResponsibility ( responsibility ) } } responsibility = { responsibility } />
232
+ < Box key = { responsibility . id } sx = { { display : 'flex' , alignItems : 'center' , padding : 1 } } >
233
+ < Typography >
234
+ { responsibility . user . last_name } { responsibility . user . first_names }
235
+ </ Typography >
236
+ < AssignedResponsibilityManagement
237
+ handleRemove = { ( ) => {
238
+ handleRemoveResponsibility ( responsibility )
239
+ } }
240
+ responsibility = { responsibility }
241
+ />
219
242
</ Box >
220
243
) ) }
221
244
</ Stack >
@@ -227,7 +250,7 @@ const Course = () => {
227
250
</ Box >
228
251
229
252
< Modal open = { activityPeriodFormOpen } onClose = { ( ) => setActivityPeriodFormOpen ( false ) } >
230
- < EditCourseForm course = { course } setOpen = { setActivityPeriodFormOpen } user = { user } />
253
+ < EditCourseForm course = { chatInstance } setOpen = { setActivityPeriodFormOpen } user = { user } />
231
254
</ Modal >
232
255
233
256
< Box my = { 2 } >
@@ -242,29 +265,27 @@ const Course = () => {
242
265
< Routes >
243
266
< Route path = "/" element = { < Stats courseId = { id } /> } />
244
267
< Route path = { `/discussions/*` } element = { < Discussion /> } />
245
- < Route path = "/prompts" element = { < Prompts courseId = { id } /> } />
268
+ < Route path = "/prompts" element = { < Prompts courseId = { id } chatInstanceId = { chatInstance . id } /> } />
246
269
< Route path = "/rag" element = { < Rag /> } />
247
270
</ Routes >
248
271
</ Container >
249
272
)
250
273
}
251
274
252
- const AssignedResponsibilityManagement = ( { responsibility, handleRemove} ) => {
275
+ const AssignedResponsibilityManagement = ( { responsibility, handleRemove } ) => {
253
276
const { t, i18n } = useTranslation ( )
254
- if ( ! responsibility . createdByUserId ) {
255
- return (
256
- < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } >
257
- </ Stack >
258
- ) }
277
+ if ( ! responsibility . createdByUserId ) {
278
+ return < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } > </ Stack >
279
+ }
259
280
return (
260
- < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } >
281
+ < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } >
261
282
< Typography > { t ( 'course:customResponsibility' ) } </ Typography >
262
283
< Button onClick = { handleRemove } > { t ( 'course:remove' ) } </ Button >
263
284
</ Stack >
264
285
)
265
286
}
266
287
267
- const Prompts = ( { courseId } : { courseId : string } ) => {
288
+ const Prompts = ( { courseId, chatInstanceId } : { courseId : string ; chatInstanceId : string } ) => {
268
289
const { t } = useTranslation ( )
269
290
const [ name , setName ] = useState ( '' )
270
291
const [ system , setSystem ] = useState ( '' )
@@ -290,7 +311,7 @@ const Prompts = ({ courseId }: { courseId: string }) => {
290
311
const handleSave = async ( ) => {
291
312
try {
292
313
await createMutation . mutateAsync ( {
293
- chatInstanceId : courseId ,
314
+ chatInstanceId,
294
315
type : 'CHAT_INSTANCE' ,
295
316
name,
296
317
systemMessage : system ,
0 commit comments