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
Branches
Tags
No related merge requests found
...@@ -29,7 +29,7 @@ export const postEventNote = ({ eventid, userid, note }) => ( ...@@ -29,7 +29,7 @@ export const postEventNote = ({ eventid, userid, note }) => (
try { try {
const response = await axios.post('/api/v1/notes/', { const response = await axios.post('/api/v1/notes/', {
event: eventid ? eventid : '', event: eventid ? eventid : '',
profile: userid ? eventid : '', profile: userid ? userid : '',
note, note,
}); });
if (response.data.id) { if (response.data.id) {
......
...@@ -44,7 +44,11 @@ class Applications extends Component { ...@@ -44,7 +44,11 @@ class Applications extends Component {
</Table.Cell> </Table.Cell>
: :
<Table.Cell textAlign='center'> <Table.Cell textAlign='center'>
{ profile.role === 'Staff' ?
<Label color='blue'>Staff</Label>
:
<Label color='red'>Nem jelentkezett</Label> <Label color='red'>Nem jelentkezett</Label>
}
</Table.Cell> </Table.Cell>
} }
<Table.Cell> <Table.Cell>
......
...@@ -36,7 +36,6 @@ class EventDetail extends Component { ...@@ -36,7 +36,6 @@ class EventDetail extends Component {
renderTrainees() { renderTrainees() {
const event = this.props.selectedEvent; const event = this.props.selectedEvent;
const note = this.props.actualNote;
return this.props.trainees.map((item) => { return this.props.trainees.map((item) => {
const notes = this.props.eventNotes.filter(note => note.profile === item.id); const notes = this.props.eventNotes.filter(note => note.profile === item.id);
return ( return (
......
...@@ -7,50 +7,38 @@ import { ...@@ -7,50 +7,38 @@ import {
Grid, Grid,
Button, Button,
Form, Form,
Dropdown,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { visitorChange, submitVisitors } from '../../actions/statistics'; import { visitorChange } from '../../actions/statistics';
import { writeNote, clearWrite, postEventNote } from '../../actions/notes'; 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 { class TraineeTableRow extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
showAddPopup: false, note: '',
showMorePopup: false, }
}; }
handleWrite = (e) => {
this.setState({ ...this.state, note: e.target.value });
} }
triggerAdd = () => this.setState({ ...this.state, showAddPopup: !this.state.showAddPopup}) clearWrite = () => {
triggerMore = () => this.setState({ ...this.state, showMorePopup: !this.state.showMorePopup }) this.setState({ ...this.state, note: '' });
}
render() { render() {
const note = this.props.actualNote;
const { trainee, edit, actualNote, selectedEvent, notes } = this.props; const { trainee, edit, actualNote, selectedEvent, notes } = this.props;
const isVisitor = selectedEvent.visitors.includes(trainee.id); const isVisitor = selectedEvent.visitors.includes(trainee.id);
const isAbsent = selectedEvent.absent.includes(trainee.id); const isAbsent = selectedEvent.absent.includes(trainee.id);
return ( return (
<Table.Row> <Table.Row key={trainee.id}>
<Table.Cell> <Table.Cell>
{trainee.full_name} {trainee.full_name}
</Table.Cell> </Table.Cell>
{!this.props.edit ? {!edit ?
<Table.Cell textAlign='center'> <Table.Cell textAlign='center'>
{ {
isVisitor ? isVisitor ?
...@@ -104,11 +92,11 @@ class TraineeTableRow extends Component { ...@@ -104,11 +92,11 @@ class TraineeTableRow extends Component {
null null
} }
</Grid.Column> </Grid.Column>
<Grid.Column floated='right' width={3} textAlign='right'> <Grid.Column floated='right' width={4} textAlign='right'>
{notes.length > 0 ? {notes.length > 0 ?
<Popup <Popup
basic on='click'
open={this.state.showMorePopup} position='bottom left'
trigger={<Button icon='comment alternate outline' onClick={this.triggerMore} />} trigger={<Button icon='comment alternate outline' onClick={this.triggerMore} />}
content={notes.map((note) => { content={notes.map((note) => {
return ( return (
...@@ -125,20 +113,20 @@ class TraineeTableRow extends Component { ...@@ -125,20 +113,20 @@ class TraineeTableRow extends Component {
null} null}
<Popup <Popup
trigger={<Button icon='plus' onClick={this.triggerAdd}/>} trigger={<Button icon='plus' onClick={this.triggerAdd}/>}
basic on='click'
open={this.state.showAddPopup} position='bottom left'
content={ content={
<Form reply> <Form reply>
<Form.TextArea <Form.TextArea
value={note.note} value={this.state.note}
onChange={e => this.props.writeNote(e)} onChange={e => this.handleWrite(e)}
/> />
<Button <Button
onClick={() => { onClick={() => {
this.props.postEventNote({ eventid:selectedEvent.id, this.props.postEventNote({ eventid:selectedEvent.id,
userid: trainee.id, userid: trainee.id,
note: note.note }); note: this.state.note });
this.props.clearWrite(); this.clearWrite();
} }
} }
content='Megjegyzés hozzáadása' content='Megjegyzés hozzáadása'
...@@ -157,6 +145,5 @@ class TraineeTableRow extends Component { ...@@ -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.
Please register or to comment