From 4307d721aa60bb336837e1bbaf443d0b653a5ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chifgeri97@gmail.com> Date: Fri, 25 Jan 2019 22:43:56 +0100 Subject: [PATCH] Fix trainee note creation, add local state to write. --- src/actions/notes.js | 2 +- src/components/pages/Applications.js | 6 ++- src/components/pages/EventDetail.js | 1 - src/components/pages/TraineeTableRow.js | 63 ++++++++++--------------- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/actions/notes.js b/src/actions/notes.js index 04362ab..52074a9 100644 --- a/src/actions/notes.js +++ b/src/actions/notes.js @@ -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) { diff --git a/src/components/pages/Applications.js b/src/components/pages/Applications.js index 6fac333..eb49ad9 100644 --- a/src/components/pages/Applications.js +++ b/src/components/pages/Applications.js @@ -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> diff --git a/src/components/pages/EventDetail.js b/src/components/pages/EventDetail.js index e48fe9b..97ec923 100644 --- a/src/components/pages/EventDetail.js +++ b/src/components/pages/EventDetail.js @@ -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 ( diff --git a/src/components/pages/TraineeTableRow.js b/src/components/pages/TraineeTableRow.js index d7276eb..e861fe8 100644 --- a/src/components/pages/TraineeTableRow.js +++ b/src/components/pages/TraineeTableRow.js @@ -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) -- GitLab