diff --git a/src/actions/statistics.js b/src/actions/statistics.js index 74063c586ceeff9ab23a1145c57023f5c9c859f2..ce42a10bbfc018c5f3b322ff9fe70c7c7a394e7c 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -26,6 +26,20 @@ export const getStaffEvents = () => ( } ); +export const getStudentEvents = () => ( + async (dispatch) => { + try { + const response = await axios.get('/api/v1/student_events/'); + dispatch({ + type: GET_EVENTS, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); + export const getEventById = id => ( async (dispatch) => { try { @@ -86,7 +100,7 @@ export const eventDate = (name, value) => ( export const addEvent = ({ name, date }) => ( async (dispatch) => { try { - const response = await axios.post('/api/v1/events/', { + const response = await axios.post('/api/v1/staff_events/', { name, date, }); @@ -108,7 +122,7 @@ export const addEvent = ({ name, date }) => ( export const deleteEvent = event => ( async (dispatch) => { try { - const response = await axios.delete(`/api/v1/events/${event.id}/`); + const response = await axios.delete(`/api/v1/staff_events/${event.id}/`); if (!response.data.id) { alert('Sikeres tĂśrlĂŠs!'); dispatch({ diff --git a/src/components/pages/EventDetail.js b/src/components/pages/EventDetail.js index 685697d0259b8fc4a10255e4ac59988948c0b584..dc2dffe01bcb2f1342b282afbb640e472644f5f0 100644 --- a/src/components/pages/EventDetail.js +++ b/src/components/pages/EventDetail.js @@ -138,8 +138,7 @@ class EventDetail extends Component { </Table.Row> </Table.Header> <Table.Body> - { this.props.trainees && - this.props.selectedEvent ? + { this.props.selectedEvent ? this.renderTrainees() : '' diff --git a/src/components/pages/Schedule.js b/src/components/pages/Schedule.js index d6a6ac619ed242e3c78a0af5d41896f4c227df90..db3877fad2df7893212e1164a84a5fe6595d41e2 100644 --- a/src/components/pages/Schedule.js +++ b/src/components/pages/Schedule.js @@ -1,26 +1,77 @@ import React, { Component } from 'react'; -import { Container, Header, Segment } from 'semantic-ui-react'; +import { Container, Accordion, Icon, Grid } from 'semantic-ui-react'; +import { connect } from 'react-redux'; +import moment from 'moment'; +import { getStudentEvents } from '../../actions/statistics'; + +class Schedule extends Component { + state = { activeIndex: 0 } + + componentWillMount() { + this.props.getStudentEvents(); + } + + handleClick = (e, titleProps) => { + const { index } = titleProps + const { activeIndex } = this.state + const newIndex = activeIndex === index ? -1 : index + + this.setState({ activeIndex: newIndex }) + } -export default class Schedule extends Component { render() { + const { activeIndex } = this.state + + const events = this.props.events; + const panels = events.map(event => ( + <> + <Accordion.Title + active={activeIndex === event.id} + index={event.id} + onClick={this.handleClick} + > + <h2> + <Grid> + <Grid.Column floated='left' width={5} textAlign='left'> + <Icon name='quidditch' color='blue' />{event.name} + </Grid.Column> + <Grid.Column floated='right' width={8} textAlign='right'> + {moment(event.date).locale('hu').format('LLLL')} + </Grid.Column> + </Grid> + </h2> + </Accordion.Title> + <Accordion.Content active={activeIndex === event.id}> + <p> + {event.description} + </p> + </Accordion.Content> + </> + )); + return ( - <div> - <Segment inverted textAlign='center' vertical> - <Container> - <Header - as='h1' - content='Ătemterv - Hamarosan' - inverted - style={{ - fontSize: '3em', - fontWeight: 'normal', - marginBottom: 0, - marginTop: '0.5em', - }} - /> - </Container> - </Segment> - </div> + <Container + textAlign='center' + style={{ + padding: '60px' + }} + > + <h2>KĂŠpzĂŠs alkalmak:</h2> + <Accordion + fluid + styled + defaultActiveIndex={-1} + panels={panels} + > + {panels} + </Accordion> + <h2>TĂĄbor:</h2> + </Container> ); } } + + +const mapStateToProps = ({ events: { events }, user }) => ({ events, user }); + +export default connect(mapStateToProps, { getStudentEvents })(Schedule); diff --git a/src/reducers/EventReducer.js b/src/reducers/EventReducer.js index 0766ddda7af07dc775f6b45087b8ccbd5b9b7ea8..071ede590c9dae1997cfc73c2b5a49a98ccc2c94 100644 --- a/src/reducers/EventReducer.js +++ b/src/reducers/EventReducer.js @@ -7,7 +7,7 @@ import { DELETE_EVENT, } from '../actions/types'; -const INITIAL_STATE = { newEvent: {} }; +const INITIAL_STATE = { events: [], newEvent: {} }; export default (state = INITIAL_STATE, action) => { switch (action.type) {