2022-01-27 07:00:05 -08:00
|
|
|
import React from 'react';
|
2020-03-27 13:59:38 -07:00
|
|
|
import { injectIntl } from 'react-intl';
|
|
|
|
import { NotificationStack } from 'react-notification';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { connect } from 'react-redux';
|
2022-01-27 07:00:05 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
import { dismissAlert } from '../../../actions/alerts';
|
|
|
|
import { getAlerts } from '../../../selectors';
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
const CustomNotificationStack = (props) => (
|
2022-05-12 13:56:09 -07:00
|
|
|
<div role='assertive' data-testid='toast' className='z-1000 fixed inset-0 flex items-end px-4 py-6 pointer-events-none pt-16 lg:pt-20 sm:items-start'>
|
2022-03-21 11:09:01 -07:00
|
|
|
<NotificationStack {...props} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-09-29 16:55:05 -07:00
|
|
|
const defaultBarStyleFactory = (index, style, notification) => {
|
|
|
|
return Object.assign(
|
|
|
|
{},
|
|
|
|
style,
|
2020-10-07 11:08:36 -07:00
|
|
|
{ bottom: `${14 + index * 12 + index * 42}px` },
|
2020-09-29 16:55:05 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
const mapStateToProps = (state, { intl }) => {
|
|
|
|
const notifications = getAlerts(state);
|
|
|
|
|
2022-01-27 07:00:05 -08:00
|
|
|
notifications.forEach(notification => {
|
|
|
|
['title', 'message', 'actionLabel'].forEach(key => {
|
|
|
|
const value = notification[key];
|
|
|
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
notification[key] = intl.formatMessage(value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (notification.actionLabel) {
|
|
|
|
notification.action = (
|
|
|
|
<Link to={notification.actionLink}>
|
|
|
|
{notification.actionLabel}
|
|
|
|
</Link>
|
|
|
|
);
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
2022-01-27 07:00:05 -08:00
|
|
|
});
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-01-27 07:00:05 -08:00
|
|
|
return { notifications, linkComponent: Link };
|
2020-03-27 13:59:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2022-01-27 07:00:05 -08:00
|
|
|
const onDismiss = alert => {
|
|
|
|
dispatch(dismissAlert(alert));
|
|
|
|
};
|
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
return {
|
2022-01-27 07:00:05 -08:00
|
|
|
onDismiss,
|
|
|
|
onClick: onDismiss,
|
2020-09-29 16:55:05 -07:00
|
|
|
barStyleFactory: defaultBarStyleFactory,
|
|
|
|
activeBarStyleFactory: defaultBarStyleFactory,
|
2020-03-27 13:59:38 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(CustomNotificationStack));
|