Flash messages: Can be successive and do not re-render page upon closing (#1482)

This commit is contained in:
RachelElysia 2021-07-27 16:19:52 -04:00 committed by GitHub
parent 47b7ffa37e
commit 6c36a0babc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View file

@ -0,0 +1 @@
* Does not re-render page to display flash message

View file

@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import classnames from "classnames";
@ -21,6 +21,17 @@ const FlashMessage = ({
[`${baseClass}--full-width`]: fullWidth,
});
useEffect(() => {
if (alertType === "success" && isVisible) {
setTimeout(function () {
document.getElementById(`${klass}`).style.visibility = "visible";
}, 0); // Ensures successive, success alerts are visible
setTimeout(function () {
document.getElementById(`${klass}`).style.visibility = "hidden";
}, 4000); // Hides success alerts after 4 seconds
}
});
if (!isVisible) {
return false;
}
@ -28,11 +39,6 @@ const FlashMessage = ({
const alertIcon =
alertType === "success" ? "success-check" : "warning-filled";
// Success alerts will not be visible after 4 seconds
if (alertType === "success") {
setTimeout(onRemoveFlash, 4000);
}
return (
<div className={klass} id={klass}>
<div className={`${baseClass}__content`}>

View file

@ -248,9 +248,10 @@ export class UserManagementPage extends Component {
const { toggleResetSessionsUserModal } = this;
dispatch(userActions.deleteSessions(userEditing))
.then(() => {
dispatch(renderFlash("success", "Sessions reset"));
if (currentUser.id === userEditing.id) {
dispatch(push(LOGIN));
} else {
dispatch(renderFlash("success", "Sessions reset"));
}
})
.catch(() => {