Skip to content

Commit 4801cb4

Browse files
action user search now takes a drawActionComponent
1 parent 97ed4c9 commit 4801cb4

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/client/components/Admin/UserSearch.tsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,14 @@ const UserTable = ({ users }: { users: User[] }) => {
110110

111111
const ActionUserTable = ({
112112
users,
113-
onSelect,
114113
actionText,
115-
actionButtonText,
114+
drawActionComponent
116115
}: {
117116
users: User[]
118-
onSelect: (user: User) => void
119117
actionText: string
120-
actionButtonText: string
118+
drawActionComponent: (user: User) => any
121119
}) => {
122120
const { t } = useTranslation()
123-
124121
if (!users || users.length === 0) return null
125122

126123
return (
@@ -180,15 +177,8 @@ const ActionUserTable = ({
180177
<Typography variant="h6">{user.primaryEmail}</Typography>
181178
</TableCell>
182179
<TableCell>
183-
<Button
184-
variant="outlined"
185-
onClick={() => {
186-
onSelect(user)
187-
}}
188-
>
189-
{actionButtonText}
190-
</Button>
191-
</TableCell>
180+
{drawActionComponent(user)}
181+
</TableCell>
192182
</TableRow>
193183
))}
194184
</TableBody>
@@ -221,13 +211,10 @@ const UserSearch = () => {
221211
}
222212
//a component which allows users to be searched in order to perform some kind of action with the user
223213
export const ActionUserSearch = ({
224-
onSelect,
225214
actionText,
226-
actionButtonText,
227-
}: {
228-
onSelect: (user: User) => void
215+
drawActionComponent }: {
229216
actionText: string
230-
actionButtonText: string
217+
drawActionComponent: (user: User) => any
231218
}) => {
232219
const [search, setSearch] = useState('')
233220
const { users, isLoading, refetch } = useUserSearch(search)
@@ -246,7 +233,7 @@ export const ActionUserSearch = ({
246233
{search.length > 2 && search.length < 5 && <div>{t('admin:typeMore')}</div>}
247234

248235
{isLoading && <div>Loading...</div>}
249-
{users && <ActionUserTable users={users} onSelect={onSelect} actionText={actionText} actionButtonText={actionButtonText} />}
236+
{users && <ActionUserTable users={users} actionText={actionText} drawActionComponent={drawActionComponent} />}
250237
</Box>
251238
)
252239
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ const Course = () => {
114114
refetchCourse()
115115
}
116116
}
117+
const drawActionComponent = (user: User) => {
118+
return (
119+
<Button onClick={() => handleAddResponsible(user)}>
120+
{t('course:add')}
121+
</Button>
122+
)
123+
}
117124
const handleRemoveResponsibility = async (responsibility) => {
118125
const result = await apiClient.post(`/courses/${chatInstance.id}/responsibilities/remove`, { username: responsibility.user?.username })
119126
if (result.status === 200) {
@@ -254,11 +261,8 @@ const Course = () => {
254261
}}
255262
>
256263
<ActionUserSearch
257-
onSelect={(user: User) => {
258-
handleAddResponsible(user)
259-
}}
260264
actionText={t('course:add')}
261-
actionButtonText={t('course:add')}
265+
drawActionComponent={drawActionComponent}
262266
/>
263267
</Box>
264268
</Modal>

0 commit comments

Comments
 (0)