Skip to content

Commit 801883c

Browse files
author
Robert S
committed
add ToastCard
1 parent 24d7160 commit 801883c

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// import styles from './ToastCard.module.scss';
2+
3+
import * as React from 'react';
4+
import { connect } from 'react-redux';
5+
import { Button, Card } from 'semantic-ui-react';
6+
import ToastStatusEnum from '../../../constants/ToastStatusEnum';
7+
import ToastsAction from '../../../stores/toasts/ToastsAction';
8+
9+
const mapStateToProps = (state, ownProps) => ({});
10+
11+
class ToastCard extends React.Component {
12+
buttonColorMap = {
13+
[ToastStatusEnum.Error]: 'red',
14+
[ToastStatusEnum.Warning]: 'orange',
15+
[ToastStatusEnum.Success]: 'green',
16+
};
17+
18+
render() {
19+
const { item } = this.props;
20+
const buttonColor = this.buttonColorMap[item.type];
21+
22+
return (
23+
<Card>
24+
<Card.Content>
25+
<Card.Header content={item.type} />
26+
<Card.Description content={item.message} />
27+
</Card.Content>
28+
<Card.Content extra={true}>
29+
<Button color={buttonColor} onClick={this._onClickRemoveNotification}>
30+
Close
31+
</Button>
32+
</Card.Content>
33+
</Card>
34+
);
35+
}
36+
37+
_onClickRemoveNotification = (event, data) => {
38+
this.props.dispatch(ToastsAction.removeById(this.props.item.id));
39+
};
40+
}
41+
42+
export { ToastCard as Unconnected };
43+
export default connect(mapStateToProps)(ToastCard);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.wrapper {
2+
}

src/views/components/toasts/Toasts.jsx

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@ import styles from './Toasts.module.scss';
22

33
import React from 'react';
44
import { connect } from 'react-redux';
5-
import ToastsAction from '../../../stores/toasts/ToastsAction';
6-
import { Card, Button } from 'semantic-ui-react';
7-
import ToastStatusEnum from '../../../constants/ToastStatusEnum';
5+
import ToastCard from '../toast-card/ToastCard';
86

97
const mapStateToProps = (state, ownProps) => ({
108
toasts: state.toasts.items,
119
});
1210

1311
class Toasts extends React.Component {
14-
buttonColorMap = {
15-
[ToastStatusEnum.Error]: 'red',
16-
[ToastStatusEnum.Warning]: 'orange',
17-
[ToastStatusEnum.Success]: 'green',
18-
};
19-
2012
render() {
2113
const { toasts } = this.props;
2214

@@ -26,30 +18,12 @@ class Toasts extends React.Component {
2618

2719
return (
2820
<div className={styles.wrapper}>
29-
{toasts.map((item) => {
30-
const buttonColor = this.buttonColorMap[item.type];
31-
32-
return (
33-
<Card key={item.id}>
34-
<Card.Content>
35-
<Card.Header content={item.type} />
36-
<Card.Description content={item.message} />
37-
</Card.Content>
38-
<Card.Content extra={true}>
39-
<Button color={buttonColor} onClick={this._onClickRemoveNotification(item.id)}>
40-
Close
41-
</Button>
42-
</Card.Content>
43-
</Card>
44-
);
45-
})}
21+
{toasts.map((model) => (
22+
<ToastCard key={model.id} item={model} />
23+
))}
4624
</div>
4725
);
4826
}
49-
50-
_onClickRemoveNotification = (id) => (event, data) => {
51-
this.props.dispatch(ToastsAction.removeById(id));
52-
};
5327
}
5428

5529
export { Toasts as Unconnected };

0 commit comments

Comments
 (0)