Skip to content

Commit d57f9ed

Browse files
teacher assigning now is done through a search modal
1 parent 1aab18a commit d57f9ed

File tree

4 files changed

+129
-13
lines changed

4 files changed

+129
-13
lines changed

src/client/components/Admin/UserSearch.tsx

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,83 @@ const UserTable = ({ users }: { users: User[] }) => {
108108
)
109109
}
110110

111+
112+
const ActionUserTable = ({ users, onSelect, actionText, actionButtonText }: { users: User[], onSelect: (user: User) => void, actionText: string, actionButtonText: string }) => {
113+
const { t } = useTranslation()
114+
115+
if (!users || users.length === 0) return null
116+
117+
return (
118+
<Box my={2}>
119+
<TableContainer component={Paper}>
120+
<Table>
121+
<TableHead>
122+
<TableRow>
123+
<TableCell>
124+
<Typography variant="h6">
125+
<b>{t('admin:username')}</b>
126+
</Typography>
127+
</TableCell>
128+
<TableCell align="left">
129+
<Typography variant="h6">
130+
<b>{t('admin:lastName')}</b>
131+
</Typography>
132+
</TableCell>
133+
<TableCell align="left">
134+
<Typography variant="h6">
135+
<b>{t('admin:firstNames')}</b>
136+
</Typography>
137+
</TableCell>
138+
<TableCell align="left">
139+
<Typography variant="h6">
140+
<b>{t('admin:studentNumber')}</b>
141+
</Typography>
142+
</TableCell>
143+
<TableCell align="left">
144+
<Typography variant="h6">
145+
<b>{t('admin:email')}</b>
146+
</Typography>
147+
</TableCell>
148+
<TableCell />
149+
<TableCell align="left">
150+
<Typography variant="h6">
151+
<b>{actionText}</b>
152+
</Typography>
153+
</TableCell>
154+
<TableCell />
155+
</TableRow>
156+
</TableHead>
157+
<TableBody>
158+
{users.map((user) => (
159+
<TableRow key={user.id}>
160+
<TableCell component="th" scope="row">
161+
<Typography variant="h6">{user.username}</Typography>
162+
</TableCell>
163+
<TableCell align="left">
164+
<Typography variant="h6">{user.lastName}</Typography>
165+
</TableCell>
166+
<TableCell align="left">
167+
<Typography variant="h6">{user.firstNames}</Typography>
168+
</TableCell>
169+
<TableCell align="left">
170+
<Typography variant="h6">{user.studentNumber}</Typography>
171+
</TableCell>
172+
<TableCell align="left">
173+
<Typography variant="h6">{user.primaryEmail}</Typography>
174+
</TableCell>
175+
<TableCell>
176+
<Button variant="outlined" onClick={() => {onSelect(user)}}>
177+
{actionButtonText}
178+
</Button>
179+
</TableCell>
180+
</TableRow>
181+
))}
182+
</TableBody>
183+
</Table>
184+
</TableContainer>
185+
</Box>
186+
)
187+
}
111188
const UserSearch = () => {
112189
const [search, setSearch] = useState('')
113190
const { users, isLoading, refetch } = useUserSearch(search)
@@ -130,5 +207,27 @@ const UserSearch = () => {
130207
</Box>
131208
)
132209
}
210+
//a component which allows users to be searched in order to perform some kind of action with the user
211+
export const ActionUserSearch = ({onSelect, actionText, actionButtonText}: {onSelect: (user: User) => void, actionText: string, actionButtonText: string}) => {
212+
const [search, setSearch] = useState('')
213+
const { users, isLoading, refetch } = useUserSearch(search)
214+
const { t } = useTranslation()
215+
216+
useEffect(() => {
217+
if (search && search.length > 4) {
218+
refetch()
219+
}
220+
}, [search])
133221

222+
return (
223+
<Box>
224+
<Input type="text" value={search} onChange={(e) => setSearch(e.target.value)} placeholder={t('admin:searchUsers')} />
225+
226+
{search.length > 2 && search.length < 5 && <div>{t('admin:typeMore')}</div>}
227+
228+
{isLoading && <div>Loading...</div>}
229+
{users && <ActionUserTable users={users} onSelect={onSelect} actionText={actionText} actionButtonText={actionButtonText}/>}
230+
</Box>
231+
)
232+
}
134233
export default UserSearch

src/client/components/Courses/Course/index.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import useCourse from '../../../hooks/useCourse'
1010
import useCurrentUser from '../../../hooks/useCurrentUser'
1111
import { useCreatePromptMutation, useDeletePromptMutation } from '../../../hooks/usePromptMutation'
1212
import usePrompts from '../../../hooks/usePrompts'
13-
import type { Message as MessageType, Responsebility } from '../../../types'
13+
import type { Message as MessageType, Responsebility, User } from '../../../types'
1414
import Conversation from '../../Chat/Conversation'
1515
import SystemMessage from '../../Chat/SystemMessage'
1616
import Rag from '../../Rag/Rag'
@@ -23,10 +23,12 @@ import Discussion from './Discussions'
2323
import { ApiErrorView } from '../../common/ApiErrorView'
2424
import apiClient from '../../../util/apiClient'
2525
import { t } from 'i18next'
26+
import UserTable from '../../Admin/Usage/UserTable'
27+
import UserSearch, { ActionUserSearch } from '../../Admin/UserSearch'
2628

2729
const Course = () => {
2830
const [showTeachers, setShowTeachers] = useState(false)
29-
31+
const [addTeacherViewOpen, setAddTeacherViewOpen] = useState(false)
3032
const [activityPeriodFormOpen, setActivityPeriodFormOpen] = useState(false)
3133
const [responsibilities, setResponsibilities] = useState<Responsebility[]>([])
3234
const { id } = useParams() as { id: string }
@@ -104,9 +106,8 @@ const Course = () => {
104106
boxSizing: 'borderBox',
105107
height: '40px',
106108
}
107-
const handleAddResponsible = async (e) => {
108-
e.preventDefault()
109-
const username = e.target.username.value
109+
const handleAddResponsible = async (user: User) => {
110+
const username = user.username
110111
const result = await apiClient.post(`/courses/${course.id}/responsibilities/assign`, { username: username })
111112
if(result.status === 200){
112113
const responsibility = result.data
@@ -207,10 +208,7 @@ const Course = () => {
207208
</Button>
208209
{showTeachers && (
209210
<Box>
210-
<Form onSubmit={handleAddResponsible}>
211-
<TextField name="username" placeholder={'käyttäjänimi: '}></TextField>
212-
<Button type={'submit'}>Lisää</Button>
213-
</Form>
211+
<Button onClick = {() => {setAddTeacherViewOpen(true)}}>{t('course:add')}</Button>
214212
<Stack sx={{margin: 1, padding: 1, borderColor: 'gray', borderWidth: 1, borderStyle: 'solid'}}>
215213
{responsibilities.map((responsibility) => (
216214
<Box key={responsibility.id} sx={{display: 'flex', alignItems: 'center', padding: 1}}>
@@ -226,6 +224,23 @@ const Course = () => {
226224
</Paper>
227225
</Box>
228226

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+
241+
</Box>
242+
</Modal>
243+
229244
<Modal open={activityPeriodFormOpen} onClose={() => setActivityPeriodFormOpen(false)}>
230245
<EditCourseForm course={course} setOpen={setActivityPeriodFormOpen} user={user} />
231246
</Modal>

src/client/locales/en.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@
285285
"prompts": "Prompts",
286286
"rag": "RAG",
287287
"remove": "remove",
288-
"customResponsibility": "manually added"
288+
"customResponsibility": "manually added",
289+
"add": "add"
289290
},
290291
"tooltip": {
291292
"copied": "Copied!"
@@ -307,4 +308,4 @@
307308
"titleV1": "This is the old chat view. You've selected the new view as default but can restore the old default here:",
308309
"buttonV1": "Select as default"
309310
}
310-
}
311+
}

src/client/locales/fi.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@
285285
"prompts": "Alustukset",
286286
"rag": "RAG",
287287
"remove": "poista",
288-
"customResponsibility": "manuaalisesti lisätty"
288+
"customResponsibility": "manuaalisesti lisätty",
289+
"add": "lisää"
289290
},
290291
"tooltip": {
291292
"copied": "Kopioitu!"
@@ -307,4 +308,4 @@
307308
"titleV1": "Tämä on vanha chattinäkymä. Olet valinnut oletukseksi uuden näkymän mutta voit palauttaa vanhan tästä:",
308309
"buttonV1": "Valitse oletusarvoksi"
309310
}
310-
}
311+
}

0 commit comments

Comments
 (0)