Newer
Older
import React, { Component } from 'react';
import { Container, Item, Dropdown, Button, Label, Comment, Form, Header } from 'semantic-ui-react';
import { connect } from 'react-redux';
import moment from 'moment';
import { getEventById, getTrainees, visitorChange, getNotesByEvent, submitVisitors } from '../../actions/statistics';
class EventDetail extends Component {
componentWillMount() {
this.props.getEventById(this.props.match.params.id);
this.props.getTrainees();
this.props.getNotesByEvent(this.props.match.params.id);
const { id, name, date, visitors } = this.props.selectedEvent;
const usernames = this.props.trainees.map((item) => {
return ({
key: item.id,
text: item.full_name,
value: item.id,
});
});
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<Item>
<Item.Header as='h2'>{name}</Item.Header>
<Item.Header as='h3'>Dátum: {moment(date).format('LL')}</Item.Header>
<Label>Jelen voltak:</Label>
<Dropdown
multiple
selection
placeholder='Újoncok hozzáadása'
style={{
minWidth: '150px',
maxWidth: '200px',
}}
onChange={(_, v) => this.props.visitorChange(v.value)}
defaultValue={visitors}
options={usernames}
/>
<Button onCLick={this.props.submitVisitors({id, visitors})}>
Megerősítés
</Button>
</Item>
);
}
renderComments() {
const notes = this.props.eventNotes;
return notes.map(note => (
<Comment>
<Comment.Content>
<Comment.Author>{note.created_by_name}</Comment.Author>
<Comment.Metadata>
{moment(note.created_at).format('LL')}
</Comment.Metadata>
<Comment.Text>
{note.note}
</Comment.Text>
</Comment.Content>
</Comment>
)
);
}
render() {
return (
<Container>
<Container textAlign='center'>
{ this.props.selectedEvent && this.props.trainees ?
this.renderEvent()
:
''
</Container>
<Container
style={{
padding: '80px'
}}
>
<Comment.Group>
<Header dividing>
Megjegyzések
</Header>
{this.props.eventNotes ?
this.renderComments()
:
''
}
<Form reply>
<Form.TextArea />
<Button content='Megjegyzés hozzáadása' labelPosition='left' icon='edit' primary />
</Form>
</Comment.Group>
</Container>
</Container>
);
}
}
const mapStateToProps = ({ notes: { eventNotes }, events: { selectedEvent }, trainees: { trainees } }) => ({ eventNotes, selectedEvent, trainees });
export default connect(mapStateToProps, { getEventById, getTrainees, visitorChange, getNotesByEvent, submitVisitors })(EventDetail);