mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-08-04 16:19:22 +00:00
Close #2062
Squashed commit of the following:
commit a1a1d4fe74dd414f83477d972bc07062e2c890ab
Merge: 9535e109 84938c56
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Tue Sep 8 10:21:47 2020 +0300
Merge branch 'master' into fix/2062
commit 9535e10934c57c2592df234a030bad183c0086cd
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Mon Sep 7 13:59:57 2020 +0300
Fix translation
commit e6f912d1d2793fd008c22b4418681abcc54896d0
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Mon Sep 7 12:03:45 2020 +0300
- client: Add link to 'update_failed' error toast
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Trans } from 'react-i18next';
|
|
import { useDispatch } from 'react-redux';
|
|
import { TOAST_TIMEOUTS } from '../../helpers/constants';
|
|
import { removeToast } from '../../actions';
|
|
|
|
const Toast = ({
|
|
id,
|
|
message,
|
|
type,
|
|
options,
|
|
}) => {
|
|
const dispatch = useDispatch();
|
|
const [timerId, setTimerId] = useState(null);
|
|
|
|
const clearRemoveToastTimeout = () => clearTimeout(timerId);
|
|
const removeCurrentToast = () => dispatch(removeToast(id));
|
|
const setRemoveToastTimeout = () => {
|
|
const timeout = TOAST_TIMEOUTS[type];
|
|
const timerId = setTimeout(removeCurrentToast, timeout);
|
|
|
|
setTimerId(timerId);
|
|
};
|
|
|
|
useEffect(() => {
|
|
setRemoveToastTimeout();
|
|
}, []);
|
|
|
|
return <div className={`toast toast--${type}`}
|
|
onMouseOver={clearRemoveToastTimeout}
|
|
onMouseOut={setRemoveToastTimeout}>
|
|
<p className="toast__content">
|
|
<Trans
|
|
i18nKey={message}
|
|
{...options}
|
|
/>
|
|
</p>
|
|
<button className="toast__dismiss" onClick={removeCurrentToast}>
|
|
<svg stroke="#fff" fill="none" width="20" height="20" strokeWidth="2"
|
|
viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="m18 6-12 12" />
|
|
<path d="m6 6 12 12" />
|
|
</svg>
|
|
</button>
|
|
</div>;
|
|
};
|
|
|
|
Toast.propTypes = {
|
|
id: PropTypes.string.isRequired,
|
|
message: PropTypes.string.isRequired,
|
|
type: PropTypes.string.isRequired,
|
|
options: PropTypes.object,
|
|
};
|
|
|
|
export default Toast;
|