Commit a8b7961f authored by Eric Rosenbaum's avatar Eric Rosenbaum

alerts default to 6 seconds

parent 872737ad
...@@ -4,6 +4,8 @@ import PropTypes from 'prop-types'; ...@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import AlertStatus from './alert-status.js'; import AlertStatus from './alert-status.js';
import AlertContext from './alert-context.js'; import AlertContext from './alert-context.js';
const DEFAULT_TIMEOUT_SECONDS = 6;
const AlertProvider = ({children}) => { const AlertProvider = ({children}) => {
const defaultState = { const defaultState = {
status: AlertStatus.NONE, status: AlertStatus.NONE,
...@@ -19,7 +21,7 @@ const AlertProvider = ({children}) => { ...@@ -19,7 +21,7 @@ const AlertProvider = ({children}) => {
setState(defaultState); setState(defaultState);
}; };
const handleAlert = (status, data, timeoutSeconds = 3) => { const handleAlert = (status, data, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) => {
if (timeoutRef.current) clearTimeout(timeoutRef.current); if (timeoutRef.current) clearTimeout(timeoutRef.current);
setState({status, data, showClear: !timeoutSeconds}); setState({status, data, showClear: !timeoutSeconds});
if (timeoutSeconds) { if (timeoutSeconds) {
...@@ -37,9 +39,9 @@ const AlertProvider = ({children}) => { ...@@ -37,9 +39,9 @@ const AlertProvider = ({children}) => {
data: state.data, data: state.data,
showClear: state.showClear, showClear: state.showClear,
clearAlert: clearAlert, clearAlert: clearAlert,
successAlert: (newData, timeoutSeconds = 3) => successAlert: (newData, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) =>
handleAlert(AlertStatus.SUCCESS, newData, timeoutSeconds), handleAlert(AlertStatus.SUCCESS, newData, timeoutSeconds),
errorAlert: (newData, timeoutSeconds = 3) => errorAlert: (newData, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) =>
handleAlert(AlertStatus.ERROR, newData, timeoutSeconds) handleAlert(AlertStatus.ERROR, newData, timeoutSeconds)
}} }}
> >
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment