-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UI): added manage group-users page
Signed-off-by: dushimsam <[email protected]>
- Loading branch information
dushimsam
committed
Aug 31, 2022
1 parent
133c1af
commit 8f176b6
Showing
11 changed files
with
451 additions
and
4 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 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,103 @@ | ||
/* | ||
Copyright (C) 2022 Samuel Dushimimana ([email protected]) | ||
SPDX-License-Identifier: GPL-2.0 | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
version 2 as published by the Free Software Foundation. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
import React, { useEffect, useState } from "react"; | ||
|
||
import { InputContainer } from "components/Widgets"; | ||
|
||
// Required functions for calling APIs | ||
import { changeUserPermission, removeGroupMember } from "services/groups"; | ||
|
||
import PropTypes from "prop-types"; | ||
|
||
// Required constants | ||
import { userPermissions } from "constants/constants"; | ||
|
||
const ChangePermissionContainer = ({ | ||
perm, | ||
setShowMessage, | ||
setMessage, | ||
currGroup, | ||
user, | ||
handleFetchGroupMembers, | ||
}) => { | ||
const [selectedPerm, setSelectedPerm] = useState(perm); | ||
|
||
useEffect(() => { | ||
setSelectedPerm(perm); | ||
}, [perm]); | ||
|
||
const handleSetNewPermission = async (newPerm) => { | ||
setSelectedPerm(newPerm); | ||
// eslint-disable-next-line no-console | ||
try { | ||
let res; | ||
if (parseInt(newPerm, 10) === -1) { | ||
// eslint-disable-next-line no-console | ||
console.log(`HERE ID ${newPerm}`); | ||
res = await removeGroupMember(currGroup, user.id); | ||
} else { | ||
res = await changeUserPermission(currGroup, user.id, newPerm); | ||
} | ||
|
||
setShowMessage(true); | ||
setMessage({ | ||
type: "success", | ||
text: res.message, | ||
}); | ||
|
||
handleFetchGroupMembers(currGroup); | ||
} catch (e) { | ||
setMessage({ | ||
type: "danger", | ||
text: e.message, | ||
}); | ||
} finally { | ||
setTimeout(() => { | ||
setShowMessage(false); | ||
}, [3000]); | ||
} | ||
}; | ||
return ( | ||
<tr> | ||
<td>{user.name}</td> | ||
<td> | ||
<InputContainer | ||
type="select" | ||
name="name" | ||
options={userPermissions} | ||
id="select-tag" | ||
value={selectedPerm} | ||
property="name" | ||
onChange={(e) => handleSetNewPermission(e.target.value)} | ||
/> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
ChangePermissionContainer.propTypes = { | ||
perm: PropTypes.number, | ||
setMessage: PropTypes.func, | ||
currGroup: PropTypes.number, | ||
user: PropTypes.node, | ||
handleFetchGroupMembers: PropTypes.func, | ||
setShowMessage: PropTypes.func, | ||
}; | ||
|
||
export default ChangePermissionContainer; |
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 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.