mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 15:32:42 +00:00
Fix modal delete behaviour
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
b328a3a38a
commit
98a4401a09
@ -18,6 +18,8 @@ const RoleListPage = () => {
|
||||
const { push } = useHistory();
|
||||
const { roles, getData, isLoading } = useRolesList();
|
||||
const [modalToDelete, setModalDelete] = useState();
|
||||
const [shouldRefetchData, setShouldRefetchData] = useState(false);
|
||||
const [showModalConfirmButtonLoading, setModalButtonLoading] = useState(false);
|
||||
|
||||
const updatePermissions = useMemo(() => {
|
||||
return {
|
||||
@ -38,12 +40,15 @@ const RoleListPage = () => {
|
||||
const handleDelete = () => {
|
||||
strapi.lockAppWithOverlay();
|
||||
|
||||
setModalButtonLoading(true);
|
||||
|
||||
Promise.resolve(
|
||||
request(`/${pluginId}/roles/${modalToDelete}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
)
|
||||
.then(() => {
|
||||
setShouldRefetchData(true);
|
||||
strapi.notification.success(getTrad('Settings.roles.deleted'));
|
||||
})
|
||||
.catch(err => {
|
||||
@ -52,11 +57,18 @@ const RoleListPage = () => {
|
||||
})
|
||||
.finally(() => {
|
||||
setModalDelete(null);
|
||||
getData();
|
||||
strapi.unlockApp();
|
||||
});
|
||||
};
|
||||
|
||||
const handleClosedModalDelete = () => {
|
||||
if (shouldRefetchData) {
|
||||
getData();
|
||||
}
|
||||
setModalButtonLoading(false);
|
||||
setShouldRefetchData(false);
|
||||
};
|
||||
|
||||
const handleNewRoleClick = () => {
|
||||
emitEvent('willCreateRole');
|
||||
push(`/settings/${pluginId}/roles/new`);
|
||||
@ -142,7 +154,9 @@ const RoleListPage = () => {
|
||||
<PopUpWarning
|
||||
isOpen={Boolean(modalToDelete)}
|
||||
onConfirm={handleDelete}
|
||||
onClosed={handleClosedModalDelete}
|
||||
toggleModal={() => setModalDelete(null)}
|
||||
isConfirmButtonLoading={showModalConfirmButtonLoading}
|
||||
/>
|
||||
</RoleListWrapper>
|
||||
</>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user