|
|
|
@ -1,9 +1,8 @@
|
|
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import media from 'styled-media-query';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import styled, { css } from 'styled-components';
|
|
|
|
|
import colors from 'config/colors';
|
|
|
|
|
import { getColor, getIcon } from 'utils/notification';
|
|
|
|
@ -13,16 +12,11 @@ import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
|
|
|
|
|
|
|
|
|
|
import * as NotificationActions from 'actions/NotificationActions';
|
|
|
|
|
import Loader from 'components/Loader';
|
|
|
|
|
import type { Action, State } from 'flowtype';
|
|
|
|
|
|
|
|
|
|
import NotificationButton from './components/NotificationButton';
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
key?: number,
|
|
|
|
|
notifications: $ElementType<State, 'notifications'>,
|
|
|
|
|
close: (notif?: any) => Action,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type NProps = {
|
|
|
|
|
key?: React.Key,
|
|
|
|
|
type: string,
|
|
|
|
|
cancelable?: boolean;
|
|
|
|
|
title: string;
|
|
|
|
@ -128,12 +122,11 @@ const ActionContent = styled.div`
|
|
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const Notification = (props: NProps): React$Element<string> => {
|
|
|
|
|
const Notification = (props: Props): React$Element<string> => {
|
|
|
|
|
const close: Function = typeof props.close === 'function' ? props.close : () => {}; // TODO: add default close action
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Wrapper type={props.type}>
|
|
|
|
|
<Wrapper key={props.key} type={props.type}>
|
|
|
|
|
{props.loading && <Loader size={50} /> }
|
|
|
|
|
{props.cancelable && (
|
|
|
|
|
<CloseClick onClick={() => close()}>
|
|
|
|
@ -167,7 +160,6 @@ export const Notification = (props: NProps): React$Element<string> => {
|
|
|
|
|
<NotificationButton
|
|
|
|
|
key={action.label}
|
|
|
|
|
type={props.type}
|
|
|
|
|
text={action.label}
|
|
|
|
|
onClick={() => { close(); action.callback(); }}
|
|
|
|
|
>{action.label}
|
|
|
|
|
</NotificationButton>
|
|
|
|
@ -179,26 +171,15 @@ export const Notification = (props: NProps): React$Element<string> => {
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const NotificationGroup = (props: Props) => {
|
|
|
|
|
const { notifications, close } = props;
|
|
|
|
|
return notifications.map(n => (
|
|
|
|
|
<Notification
|
|
|
|
|
key={n.title}
|
|
|
|
|
type={n.type}
|
|
|
|
|
title={n.title}
|
|
|
|
|
message={n.message}
|
|
|
|
|
cancelable={n.cancelable}
|
|
|
|
|
actions={n.actions}
|
|
|
|
|
close={close}
|
|
|
|
|
/>
|
|
|
|
|
));
|
|
|
|
|
Notification.propTypes = {
|
|
|
|
|
key: PropTypes.string,
|
|
|
|
|
type: PropTypes.string.isRequired,
|
|
|
|
|
cancelable: PropTypes.bool,
|
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
|
message: PropTypes.string,
|
|
|
|
|
actions: PropTypes.arrayOf(PropTypes.func),
|
|
|
|
|
close: PropTypes.func,
|
|
|
|
|
loading: PropTypes.bool,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
state => ({
|
|
|
|
|
notifications: state.notifications,
|
|
|
|
|
}),
|
|
|
|
|
dispatch => ({
|
|
|
|
|
close: bindActionCreators(NotificationActions.close, dispatch),
|
|
|
|
|
}),
|
|
|
|
|
)(NotificationGroup);
|
|
|
|
|
export default Notification;
|