-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: delete multiple users from table toolbar
- Loading branch information
Showing
21 changed files
with
321 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { USERS_COLLECTION, CLASSROOMS_COLLECTION } = require('../db'); | ||
const { DELETE_USERS_IN_CLASSROOM_CHANNEL } = require('../config/channels'); | ||
const { ERROR_GENERAL, ERROR_NO_USER_TO_DELETE } = require('../config/errors'); | ||
|
||
const logger = require('../logger'); | ||
|
||
const deleteUsersInClassroom = (mainWindow, db) => async ( | ||
event, | ||
{ users = [], classroomId } | ||
) => { | ||
logger.debug('deleting a user in a classroom'); | ||
|
||
if (!users.length) { | ||
logger.error('no user to delete'); | ||
return mainWindow.webContents.send( | ||
DELETE_USERS_IN_CLASSROOM_CHANNEL, | ||
ERROR_NO_USER_TO_DELETE | ||
); | ||
} | ||
|
||
try { | ||
const usersInClassroom = db | ||
.get(CLASSROOMS_COLLECTION) | ||
.find({ id: classroomId }) | ||
.get(USERS_COLLECTION); | ||
|
||
users.forEach(({ id }) => { | ||
usersInClassroom.remove({ id }).write(); | ||
}); | ||
|
||
return mainWindow.webContents.send(DELETE_USERS_IN_CLASSROOM_CHANNEL); | ||
} catch (err) { | ||
logger.error(err); | ||
return mainWindow.webContents.send( | ||
DELETE_USERS_IN_CLASSROOM_CHANNEL, | ||
ERROR_GENERAL | ||
); | ||
} | ||
}; | ||
|
||
module.exports = deleteUsersInClassroom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const { dialog } = require('electron'); | ||
const { | ||
RESPOND_DELETE_USERS_IN_CLASSROOM_PROMPT_CHANNEL, | ||
} = require('../config/channels'); | ||
const logger = require('../logger'); | ||
const { ERROR_NO_USER_TO_DELETE } = require('../config/errors'); | ||
|
||
const showDeleteUsersInClassroomPrompt = mainWindow => ( | ||
event, | ||
{ users = [] } | ||
) => { | ||
logger.debug('showing delete user in classroom prompt'); | ||
|
||
if (!users.length) { | ||
logger.error('no user to delete'); | ||
mainWindow.webContents.send( | ||
RESPOND_DELETE_USERS_IN_CLASSROOM_PROMPT_CHANNEL, | ||
ERROR_NO_USER_TO_DELETE | ||
); | ||
} else { | ||
const usernamesString = users | ||
.map(({ username }) => `- ${username}`) | ||
.join('\n'); | ||
|
||
const options = { | ||
type: 'warning', | ||
buttons: ['Cancel', 'Delete'], | ||
defaultId: 0, | ||
cancelId: 0, | ||
message: `Are you sure you want to delete the following users:\n\n${usernamesString}\n\nfrom this classroom?`, | ||
}; | ||
|
||
dialog.showMessageBox(mainWindow, options).then(({ response }) => { | ||
mainWindow.webContents.send( | ||
RESPOND_DELETE_USERS_IN_CLASSROOM_PROMPT_CHANNEL, | ||
response | ||
); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = showDeleteUsersInClassroomPrompt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.