Skip to content
Snippets Groups Projects
Commit 4307d721 authored by Chif Gergő's avatar Chif Gergő
Browse files

Fix trainee note creation, add local state to write.

parent 79fc4395
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ export const postEventNote = ({ eventid, userid, note }) => (
try {
const response = await axios.post('/api/v1/notes/', {
event: eventid ? eventid : '',
profile: userid ? eventid : '',
profile: userid ? userid : '',
note,
});
if (response.data.id) {
......
......@@ -44,7 +44,11 @@ class Applications extends Component {
</Table.Cell>
:
<Table.Cell textAlign='center'>
<Label color='red'>Nem jelentkezett</Label>
{ profile.role === 'Staff' ?
<Label color='blue'>Staff</Label>
:
<Label color='red'>Nem jelentkezett</Label>
}
</Table.Cell>
}
<Table.Cell>
......
......@@ -36,7 +36,6 @@ class EventDetail extends Component {
renderTrainees() {
const event = this.props.selectedEvent;
const note = this.props.actualNote;
return this.props.trainees.map((item) => {
const notes = this.props.eventNotes.filter(note => note.profile === item.id);
return (
......
......@@ -7,50 +7,38 @@ import {
Grid,
Button,
Form,
Dropdown,
} from 'semantic-ui-react';
import { connect } from 'react-redux';
import { visitorChange, submitVisitors } from '../../actions/statistics';
import { visitorChange } from '../../actions/statistics';
import { writeNote, clearWrite, postEventNote } from '../../actions/notes';
const visitStates = [
{
text: 'Igen',
value: 'Visitor',
},
{
text: 'Szólt h nem',
value: 'Absent',
},
{
text: 'Nem',
value: 'No',
}
]
class TraineeTableRow extends Component {
constructor(props) {
super(props);
this.state = {
showAddPopup: false,
showMorePopup: false,
};
note: '',
}
}
handleWrite = (e) => {
this.setState({ ...this.state, note: e.target.value });
}
triggerAdd = () => this.setState({ ...this.state, showAddPopup: !this.state.showAddPopup})
triggerMore = () => this.setState({ ...this.state, showMorePopup: !this.state.showMorePopup })
clearWrite = () => {
this.setState({ ...this.state, note: '' });
}
render() {
const note = this.props.actualNote;
const { trainee, edit, actualNote, selectedEvent, notes } = this.props;
const isVisitor = selectedEvent.visitors.includes(trainee.id);
const isAbsent = selectedEvent.absent.includes(trainee.id);
return (
<Table.Row>
<Table.Row key={trainee.id}>
<Table.Cell>
{trainee.full_name}
</Table.Cell>
{!this.props.edit ?
{!edit ?
<Table.Cell textAlign='center'>
{
isVisitor ?
......@@ -68,19 +56,19 @@ class TraineeTableRow extends Component {
compact
icon={<Icon color='green' name='checkmark' />}
color={isVisitor ? 'blue' : 'lightgrey'}
onClick={() => this.props.visitorChange({ id : trainee.id, value: 'Visitor' })}
onClick={() => this.props.visitorChange({ id: trainee.id, value: 'Visitor' })}
/>
<Button
compact
icon={<Icon color='orange' name='minus' />}
color={isAbsent ? 'blue' : 'lightgrey'}
onClick={() => this.props.visitorChange({ id : trainee.id, value: 'Absent' })}
onClick={() => this.props.visitorChange({ id: trainee.id, value: 'Absent' })}
/>
<Button
compact
icon={<Icon color='red' name='cancel' />}
color={!isVisitor && !isAbsent ? 'blue' : 'lightgrey'}
onClick={() => this.props.visitorChange({ id : trainee.id, value: 'No' })}
onClick={() => this.props.visitorChange({ id: trainee.id, value: 'No' })}
/>
</Table.Cell>
}
......@@ -104,11 +92,11 @@ class TraineeTableRow extends Component {
null
}
</Grid.Column>
<Grid.Column floated='right' width={3} textAlign='right'>
<Grid.Column floated='right' width={4} textAlign='right'>
{notes.length > 0 ?
<Popup
basic
open={this.state.showMorePopup}
on='click'
position='bottom left'
trigger={<Button icon='comment alternate outline' onClick={this.triggerMore} />}
content={notes.map((note) => {
return (
......@@ -125,20 +113,20 @@ class TraineeTableRow extends Component {
null}
<Popup
trigger={<Button icon='plus' onClick={this.triggerAdd}/>}
basic
open={this.state.showAddPopup}
on='click'
position='bottom left'
content={
<Form reply>
<Form.TextArea
value={note.note}
onChange={e => this.props.writeNote(e)}
value={this.state.note}
onChange={e => this.handleWrite(e)}
/>
<Button
onClick={() => {
this.props.postEventNote({ eventid:selectedEvent.id,
userid: trainee.id,
note: note.note });
this.props.clearWrite();
note: this.state.note });
this.clearWrite();
}
}
content='Megjegyzés hozzáadása'
......@@ -157,6 +145,5 @@ class TraineeTableRow extends Component {
);
}
}
const mapStateToProps = ({ notes: { actualNote } }) => ({ actualNote })
export default connect(mapStateToProps, { writeNote, clearWrite, postEventNote, visitorChange})(TraineeTableRow)
export default connect(() => {}, { writeNote, clearWrite, postEventNote, visitorChange})(TraineeTableRow)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment