-
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.
Merge pull request #241 from dushimsam/dushimsam/feat/admin/delete-group
feat(ui): added delete group page Reviewed-by: mishra.gaurav@siemens.com Tested-by: shaheem.azmal@simen.cm
- Loading branch information
Showing
12 changed files
with
314 additions
and
3 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
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,71 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import Spinner from "react-bootstrap/Spinner"; | ||
import { Button } from "../../Widgets"; | ||
|
||
const DeleteConfirmation = ({ callBack, loading }) => { | ||
return ( | ||
<> | ||
<div | ||
className="modal fade" | ||
id="deleteConfirmationModal" | ||
tabIndex="-1" | ||
role="dialog" | ||
aria-hidden="true" | ||
> | ||
<div className="modal-dialog modal-dialog-centered" role="document"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h5 className="modal-title">Are you sure ?</h5> | ||
<button | ||
type="button" | ||
className="close" | ||
data-dismiss="modal" | ||
aria-label="Close" | ||
> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div className="modal-body"> | ||
Do you really want to delete this group ? This process can not be | ||
undone. | ||
</div> | ||
<div className="modal-footer"> | ||
<button | ||
type="button" | ||
className="btn btn-secondary border-dark border-rounded px-4 py-2 mr-2" | ||
data-dismiss="modal" | ||
onClick={() => {}} | ||
> | ||
Cancel | ||
</button> | ||
<Button | ||
type="button" | ||
onClick={() => callBack()} | ||
className="btn btn-danger border-dark border-rounded px-5 py-2" | ||
> | ||
{loading ? ( | ||
<Spinner | ||
as="span" | ||
animation="border" | ||
size="sm" | ||
role="status" | ||
aria-hidden="true" | ||
/> | ||
) : ( | ||
"YES" | ||
)} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
DeleteConfirmation.propTypes = { | ||
callBack: PropTypes.func.isRequired, | ||
loading: PropTypes.bool.isRequired, | ||
}; | ||
export default DeleteConfirmation; |
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,147 @@ | ||
/* | ||
Copyright (C) 2022 Samuel Dushimimana | ||
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 messages from "constants/messages"; | ||
|
||
// Jquery for handling modal | ||
import $ from "jquery"; | ||
|
||
// Title | ||
import Title from "components/Title"; | ||
|
||
// Widgets | ||
import { Alert, Button, InputContainer } from "components/Widgets"; | ||
|
||
// Required functions for calling APIs | ||
import { deleteGroup, fetchAllDeletableGroups } from "services/groups"; | ||
import DeleteConfirmation from "components/Modals/DeleteConfirmation"; | ||
|
||
const DeleteGroup = () => { | ||
const initialMessage = { | ||
type: "", | ||
text: "", | ||
}; | ||
|
||
const [groups, setGroups] = useState([]); | ||
const [selectedGroupId, setSelectedGroupId] = useState(null); | ||
|
||
// State Variables for handling Error Boundaries | ||
const [loading, setLoading] = useState(false); | ||
const [showMessage, setShowMessage] = useState(false); | ||
const [message, setMessage] = useState(initialMessage); | ||
|
||
useEffect(async () => { | ||
try { | ||
const res = await fetchAllDeletableGroups(); | ||
setGroups(res); | ||
} catch (e) { | ||
setMessage({ | ||
type: "error", | ||
text: e.message, | ||
}); | ||
setShowMessage(true); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (groups.length > 0) { | ||
setSelectedGroupId(groups[0].id); | ||
} | ||
}, [groups]); | ||
|
||
const toggleModal = (modalId, status) => { | ||
// eslint-disable-next-line func-names | ||
$(function () { | ||
if (status === "show") { | ||
$(modalId).modal("show"); | ||
} else { | ||
$(modalId).modal("hide"); | ||
$(".modal-backdrop").remove(); | ||
} | ||
}); | ||
}; | ||
|
||
const deleteItem = async () => { | ||
setLoading(true); | ||
try { | ||
await deleteGroup(selectedGroupId); | ||
setMessage({ | ||
type: "success", | ||
text: messages.deletedGroup, | ||
}); | ||
|
||
setTimeout(() => { | ||
window.location.reload(); | ||
}, 1500); | ||
} catch (error) { | ||
setMessage({ | ||
type: "danger", | ||
text: error.message, | ||
}); | ||
} finally { | ||
setLoading(false); | ||
setShowMessage(true); | ||
toggleModal("#deleteConfirmationModal", "hide"); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Title title="Delete Group" /> | ||
<div className="main-container my-3"> | ||
{showMessage && ( | ||
<Alert | ||
type={message.type} | ||
setShow={setShowMessage} | ||
message={message.text} | ||
/> | ||
)} | ||
<h1 className="font-size-main-heading">Delete Group</h1> | ||
<br /> | ||
<div className="row"> | ||
<div className="col-12 col-lg-8"> | ||
<form> | ||
<InputContainer | ||
name="group" | ||
type="select" | ||
onChange={(e) => setSelectedGroupId(e.target.value)} | ||
options={groups} | ||
property="name" | ||
> | ||
Select group to delete: | ||
</InputContainer> | ||
<Button | ||
type="button" | ||
dataToggle="modal" | ||
dataTarget="#deleteConfirmationModal" | ||
className="mt-4" | ||
disabled={groups.length === 0} | ||
> | ||
Delete | ||
</Button> | ||
</form> | ||
</div> | ||
<DeleteConfirmation callBack={deleteItem} loading={loading} /> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteGroup; |
Oops, something went wrong.