You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Function store of all pagination functions, these functions update the count, the current range of pages, etc. Essentially, any action on the pagination bar will be handled by this function store which is passed into the TablePagination component
42
+
// Function store of all pagination functions, these functions update the count, the current range of pages, etc.
43
+
// Essentially, any action on the pagination bar will be handled by this function store which is passed into the TablePagination component
// Determine how many empty rows to display on a certain page, e.g. if rowsPerPage = 5, and there are only 3 rows, should display 2 rows
134
146
constemptyRows=
@@ -144,23 +156,57 @@ const UserTable = () => {
144
156
setPage(0);
145
157
};
146
158
147
-
consthandleCheckboxClick=(event)=>{
148
-
// event persist is required to access target property of event. Without this, a synthetic event object would be used where target is re-assigned to null for performance reasons
// update key of checkbox id to switched/inverted value
165
+
temp[id]=invertPreviousValue;
166
+
// update local state
167
+
setSelectedSysAdmin(temp);
168
+
return1;
169
+
};
150
170
151
-
constid=event.target.getAttribute('id');
152
-
constinvertPreviousValue=!selected[id];
171
+
constsetAdmin=(id)=>{
172
+
constinvertPreviousValue=!selectedAdmin[id];
173
+
// Create a temp copy of the selected object
174
+
consttemp={
175
+
...selectedAdmin,
176
+
};
177
+
temp[id]=invertPreviousValue;
178
+
setSelectedAdmin(temp);
179
+
return2;
180
+
};
153
181
154
-
// create temporary copy of selected object
182
+
constsetUser=(id)=>{
183
+
constinvertPreviousValue=!selectedUser[`U${id}`];
155
184
consttemp={
156
-
...selected,
185
+
...selectedUser,
157
186
};
158
-
// update key of checkbox id to switched/inverted value
159
187
temp[id]=invertPreviousValue;
188
+
setSelectedUser(temp);
189
+
return3;
190
+
};
160
191
161
-
// update local state variable selected
162
-
setSelected(temp);
192
+
consthandleCheckboxClick=(event)=>{
193
+
// event persist is required to access target property of event. Without this, a synthetic event object would be used where target is re-assigned to null for performance reasons
194
+
event.persist();
163
195
196
+
letid=event.target.getAttribute('id');
197
+
letrole_id;
198
+
199
+
if(id.charAt(0)==='S'){
200
+
id=id.slice(1);
201
+
role_id=setSysAdmin(id);
202
+
}elseif(id.charAt(0)==='U'){
203
+
id=id.slice(1);
204
+
role_id=setUser(id);
205
+
}
206
+
else{
207
+
role_id=setAdmin(id);
208
+
}
209
+
164
210
// send request to endpoint http://localhost:3000/admin/switch
165
211
fetch('http://localhost:3000/admin/switch',{
166
212
method: 'POST',
@@ -169,7 +215,8 @@ const UserTable = () => {
169
215
},
170
216
body: JSON.stringify({
171
217
_id: id,
172
-
changeToAdmin: invertPreviousValue,
218
+
role_id: role_id// TM - Need to add info if role needs to be downgraded
219
+
// changeToAdmin: invertPreviousValue,
173
220
}),
174
221
})
175
222
.then((response)=>{
@@ -215,38 +262,58 @@ const UserTable = () => {
215
262
<TableCell>Contact Preference</TableCell>
216
263
<TableCell>Memory Threshold</TableCell>
217
264
<TableCell>CPU Threshold</TableCell>
265
+
<TableCell>User</TableCell>
218
266
<TableCell>Admin</TableCell>
267
+
<TableCell>SysAdmin</TableCell>
219
268
</TableRow>
220
269
</TableHead>
221
270
<TableBody>
222
271
{renderRows.length>0
223
272
? renderRows.map((row,index)=>{
224
-
// const isItemSelected = isSelected(row.name);
225
-
constlabelId=`enhanced-table-checkbox-${index}`;
226
-
return(
227
-
<TableRowkey={row._id}hover>
228
-
<TableCellcomponent='th'scope='row'>
229
-
{row._id}
230
-
</TableCell>
231
-
<TableCell>{row.username}</TableCell>
232
-
<TableCell>{row.email}</TableCell>
233
-
<TableCell>{row.phone}</TableCell>
234
-
<TableCell>{row.role}</TableCell>
235
-
<TableCell>{row.contact_pref}</TableCell>
236
-
<TableCell>{row.mem_threshold}</TableCell>
237
-
<TableCell>{row.cpu_threshold}</TableCell>
238
-
<TableCell>
239
-
<Checkbox
240
-
id={`${row._id}`}
241
-
userid={`${row._id}`}
242
-
checked={selected[row._id]}
243
-
inputProps={{'aria-labelledby': labelId}}
244
-
onChange={handleCheckboxClick}
245
-
/>
246
-
</TableCell>
247
-
</TableRow>
248
-
);
249
-
})
273
+
// const isItemSelected = isSelected(row.name);
274
+
constlabelId=`enhanced-table-checkbox-${index}`;
275
+
return(
276
+
<TableRowkey={row._id}hover>
277
+
<TableCellcomponent='th'scope='row'>
278
+
{row._id}
279
+
</TableCell>
280
+
<TableCell>{row.username}</TableCell>
281
+
<TableCell>{row.email}</TableCell>
282
+
<TableCell>{row.phone}</TableCell>
283
+
<TableCell>{row.role}</TableCell>
284
+
<TableCell>{row.contact_pref}</TableCell>
285
+
<TableCell>{row.mem_threshold}</TableCell>
286
+
<TableCell>{row.cpu_threshold}</TableCell>
287
+
<TableCell>
288
+
<Checkbox
289
+
id={`U${row._id}`}
290
+
userid={`${row._id}`}
291
+
checked={selectedUser[`U${row._id}`]}
292
+
inputProps={{'aria-labelledby': labelId}}
293
+
onChange={handleCheckboxClick}
294
+
/>
295
+
</TableCell>
296
+
<TableCell>
297
+
<Checkbox
298
+
id={`${row._id}`}
299
+
userid={`${row._id}`}
300
+
checked={selectedAdmin[row._id]}
301
+
inputProps={{'aria-labelledby': labelId}}
302
+
onChange={handleCheckboxClick}
303
+
/>
304
+
</TableCell>
305
+
<TableCell>
306
+
<Checkbox
307
+
id={`S${row._id}`}// Edit these details so it links to sysadmin
0 commit comments