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'
@@ -43,7 +59,7 @@ const Course = () => {
43
59
return < ApiErrorView error = { error } />
44
60
}
45
61
useEffect ( ( ) => {
46
- if ( isCourseSuccess ) {
62
+ if ( isCourseSuccess ) {
47
63
setResponsibilities ( course ?. responsibilities )
48
64
}
49
65
} , [ isCourseSuccess ] )
@@ -109,16 +125,15 @@ const Course = () => {
109
125
const handleAddResponsible = async ( user : User ) => {
110
126
const username = user . username
111
127
const result = await apiClient . post ( `/courses/${ course . id } /responsibilities/assign` , { username : username } )
112
- if ( result . status === 200 ) {
128
+ if ( result . status === 200 ) {
113
129
const responsibility = result . data
114
130
setResponsibilities ( [ ...responsibilities , responsibility ] )
115
131
refetchCourse ( )
116
132
}
117
-
118
133
}
119
134
const handleRemoveResponsibility = async ( responsibility ) => {
120
135
const result = await apiClient . post ( `/courses/${ course . id } /responsibilities/remove` , { username : responsibility . user ?. username } )
121
- if ( result . status === 200 ) {
136
+ if ( result . status === 200 ) {
122
137
const filteredResponsibilities = responsibilities . filter ( ( r ) => r . id !== responsibility . id )
123
138
setResponsibilities ( filteredResponsibilities )
124
139
}
@@ -208,12 +223,25 @@ const Course = () => {
208
223
</ Button >
209
224
{ showTeachers && (
210
225
< Box >
211
- < Button onClick = { ( ) => { setAddTeacherViewOpen ( true ) } } > { t ( 'course:add' ) } </ Button >
212
- < Stack sx = { { margin : 1 , padding : 1 , borderColor : 'gray' , borderWidth : 1 , borderStyle : 'solid' } } >
226
+ < Button
227
+ onClick = { ( ) => {
228
+ setAddTeacherViewOpen ( true )
229
+ } }
230
+ >
231
+ { t ( 'course:add' ) }
232
+ </ Button >
233
+ < Stack sx = { { margin : 1 , padding : 1 , borderColor : 'gray' , borderWidth : 1 , borderStyle : 'solid' } } >
213
234
{ responsibilities . map ( ( responsibility ) => (
214
- < Box key = { responsibility . id } sx = { { display : 'flex' , alignItems : 'center' , padding : 1 } } >
215
- < Typography > { responsibility . user . last_name } { responsibility . user . first_names } </ Typography >
216
- < AssignedResponsibilityManagement handleRemove = { ( ) => { handleRemoveResponsibility ( responsibility ) } } responsibility = { responsibility } />
235
+ < Box key = { responsibility . id } sx = { { display : 'flex' , alignItems : 'center' , padding : 1 } } >
236
+ < Typography >
237
+ { responsibility . user . last_name } { responsibility . user . first_names }
238
+ </ Typography >
239
+ < AssignedResponsibilityManagement
240
+ handleRemove = { ( ) => {
241
+ handleRemoveResponsibility ( responsibility )
242
+ } }
243
+ responsibility = { responsibility }
244
+ />
217
245
</ Box >
218
246
) ) }
219
247
</ Stack >
@@ -224,20 +252,30 @@ const Course = () => {
224
252
</ Paper >
225
253
</ Box >
226
254
227
- < Modal sx = { {
228
- display : 'flex' ,
229
- justifyContent : 'center' ,
230
- alignItems : 'center'
231
- } } open = { addTeacherViewOpen } onClose = { ( ) => setAddTeacherViewOpen ( false ) } >
232
- < Box sx = { {
233
- width : '80vw' ,
234
- height : '80vh' ,
235
- background : 'white' ,
236
- padding : '2rem'
237
- } } >
238
-
239
- < ActionUserSearch onSelect = { ( user : User ) => { handleAddResponsible ( user ) } } actionText = { t ( 'course:add' ) } actionButtonText = { t ( 'course:add' ) } />
240
-
255
+ < Modal
256
+ sx = { {
257
+ display : 'flex' ,
258
+ justifyContent : 'center' ,
259
+ alignItems : 'center' ,
260
+ } }
261
+ open = { addTeacherViewOpen }
262
+ onClose = { ( ) => setAddTeacherViewOpen ( false ) }
263
+ >
264
+ < Box
265
+ sx = { {
266
+ width : '80vw' ,
267
+ height : '80vh' ,
268
+ background : 'white' ,
269
+ padding : '2rem' ,
270
+ } }
271
+ >
272
+ < ActionUserSearch
273
+ onSelect = { ( user : User ) => {
274
+ handleAddResponsible ( user )
275
+ } }
276
+ actionText = { t ( 'course:add' ) }
277
+ actionButtonText = { t ( 'course:add' ) }
278
+ />
241
279
</ Box >
242
280
</ Modal >
243
281
@@ -264,15 +302,13 @@ const Course = () => {
264
302
)
265
303
}
266
304
267
- const AssignedResponsibilityManagement = ( { responsibility, handleRemove} ) => {
305
+ const AssignedResponsibilityManagement = ( { responsibility, handleRemove } ) => {
268
306
const { t, i18n } = useTranslation ( )
269
- if ( ! responsibility . createdByUserId ) {
270
- return (
271
- < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } >
272
- </ Stack >
273
- ) }
307
+ if ( ! responsibility . createdByUserId ) {
308
+ return < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } > </ Stack >
309
+ }
274
310
return (
275
- < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } >
311
+ < Stack direction = { 'row' } sx = { { marginLeft : 'auto' , alignItems : 'center' , height : '1rem' } } >
276
312
< Typography > { t ( 'course:customResponsibility' ) } </ Typography >
277
313
< Button onClick = { handleRemove } > { t ( 'course:remove' ) } </ Button >
278
314
</ Stack >
0 commit comments