diff --git a/src/actions/statistics.js b/src/actions/statistics.js index 7e181f79e6ba67e920efd0562dfc34224442f2b4..74063c586ceeff9ab23a1145c57023f5c9c859f2 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -7,7 +7,9 @@ import { WRITE_EVENT, ADD_EVENT, DELETE_EVENT, - GET_TRAINEE_BY_ID, + GET_PROFILES, + GET_SELECTED_PROFILE, + SET_STATUS, } from './types'; export const getStaffEvents = () => ( @@ -38,20 +40,6 @@ export const getEventById = id => ( } ); -export const getTraineeById = id => ( - async (dispatch) => { - try { - const response = await axios.get(`/api/v1/profiles/${id}`); - dispatch({ - type: GET_TRAINEE_BY_ID, - payload: response.data, - }); - } catch (e) { - console.log(e); - } - } -); - export const getTrainees = () => ( async (dispatch) => { try { @@ -134,3 +122,49 @@ export const deleteEvent = event => ( console.log(e); } }); + +export const getProfiles = () => ( + async (dispatch) => { + try { + const response = await axios.get('/api/v1/profiles/'); + dispatch({ + type: GET_PROFILES, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); + +export const setStatus = (id, status) => ( + async (dispatch) => { + try { + const response = await axios.patch(`/api/v1/profiles/${id}/`, { + role: status, + }); + if (response.data.id) { + dispatch({ + type: SET_STATUS, + payload: response.data, + }); + } + } catch (e) { + console.log(e); + } + } +); + +export const getSelectedProfile = id => ( + async (dispatch) => { + try { + const response = await axios.get(`/api/v1/profiles/${id}/`); + dispatch({ + type: GET_SELECTED_PROFILE, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); diff --git a/src/actions/types.js b/src/actions/types.js index d98b3229726dabb3b7c5c7963d0306224437ee61..70b3b996856e90c25d81f5711eb40309ddda009a 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -15,7 +15,6 @@ export const GET_EVENTS = 'get_events'; export const GET_EVENT_BY_ID = 'get_event_by_id'; export const GET_TRAINEES = 'get_trainees'; -export const GET_TRAINEE_BY_ID = 'get_trainee_by_id'; export const VISITOR_CHANGE = 'visitor_change'; export const GET_NOTES_BY_EVENT = 'get_notes_by_event'; @@ -26,3 +25,7 @@ export const DELETE_EVENT = 'delete_event'; export const WRITE_NOTE = 'write_note'; export const CLEAR_NOTE = 'clear_note'; export const ADD_EVENT_NOTE = 'add_note'; + +export const GET_PROFILES = 'get_profiles'; +export const SET_STATUS = 'set_status'; +export const GET_SELECTED_PROFILE = 'get_selected_profile'; diff --git a/src/components/Header.js b/src/components/Header.js index 0a750b792a43063e04670055607e5543e64171d9..f1413a412c25404e53d4c61042661a3881031890 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -43,7 +43,12 @@ const menuItems = [ prefix: '', permissionLevel: 3, }, -]; + { + text: 'JelentkezĂŠsek', + to: '/applications', + prefix: '', + }, +] const FixedMenu = ({ user }) => ( <Menu fixed='top' size='large' pointing> diff --git a/src/components/Main.js b/src/components/Main.js index 8f917c698f0801312f9870b569a30b4a5b83a1d1..b9a90787a4da001d8d3855c54cf0230037bcb02c 100644 --- a/src/components/Main.js +++ b/src/components/Main.js @@ -9,7 +9,9 @@ import Profile from './pages/Profile'; import Statistics from './pages/Statistics'; import Groups from './pages/Groups'; import News from './pages/News'; +import Applications from './pages/Applications'; import EventDetail from './pages/EventDetail'; +import ApplicantProfile from './pages/ApplicantProfile'; const Main = () => ( <Switch> @@ -22,6 +24,8 @@ const Main = () => ( <Route path='/statistics' component={Statistics} /> <Route path='/groups' component={Groups} /> <Route path='/events/:id' component={EventDetail} /> + <Route path='/applications' component={Applications} /> + <Route path='/applicant/:id' component={ApplicantProfile} /> <Route component={NotFound} /> </Switch> ); diff --git a/src/components/forms/ConfirmModal.js b/src/components/forms/ConfirmModal.js new file mode 100644 index 0000000000000000000000000000000000000000..586d624b7caceb695bbb8154e553e29b0aa03b00 --- /dev/null +++ b/src/components/forms/ConfirmModal.js @@ -0,0 +1,61 @@ +import React, { Component } from 'react'; +import { Button, Header, Icon, Modal } from 'semantic-ui-react'; + +class ConfirmModal extends Component { + constructor(props) { + super(props); + this.state = { + showModal: false, + }; + } + + close = () => this.setState({ showModal: false }) + + open = () => this.setState({ showModal: true}) + + render() { + const { button, text, onAccept } = this.props; + const open = this.state.showModal; + return ( + <Modal + open={open} + closeOnDimmerClick + trigger={button} + onOpen={this.open} + onClose={this.close} + size='small' + basic + > + <Header icon='question' content='Confirm' /> + <Modal.Content> + <p> + Biztos hogy {text}? + </p> + </Modal.Content> + <Modal.Actions> + <Button + basic + color='red' + inverted + inverted + onClick={() => this.close()} + > + <Icon name='remove' /> No + </Button> + <Button + color='green' + inverted + onClick={() => { onAccept(); + this.close(); + } + } + > + <Icon name='checkmark' /> Yes + </Button> + </Modal.Actions> + </Modal> + ); + } +} + +export default ConfirmModal; diff --git a/src/components/pages/Applications.js b/src/components/pages/Applications.js new file mode 100644 index 0000000000000000000000000000000000000000..6fac3330108f0610c51405e8b85772edbd6aab6c --- /dev/null +++ b/src/components/pages/Applications.js @@ -0,0 +1,95 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; +import { Container, Table, Label, Button } from 'semantic-ui-react'; +import { connect } from 'react-redux'; +import { getProfiles, setStatus } from '../../actions/statistics'; +import ConfirmModal from '../forms/ConfirmModal'; + +class Applications extends Component { + componentWillMount() { + this.props.getProfiles(); + } + + renderApplicants() { + return this.props.profiles.map((profile) => + { return ( + <Table.Row> + <Table.Cell> + <Link to={`applicant/${profile.id}`}> + {profile.full_name} + </Link> + </Table.Cell> + { profile.signed ? + <Table.Cell textAlign='center'> + { profile.role === 'Student' ? + <Label color='green'>Elfogadva</Label> + : + null + } + { profile.role === 'Staff' ? + <Label color='blue'>Staff</Label> + : + null + } + { profile.role === 'Applicant' ? + <Label color='orange'>Jelentkezett</Label> + : + null + } + { profile.role === 'Denied' ? + <Label color='red'>ElutasĂtva</Label> + : + null + } + </Table.Cell> + : + <Table.Cell textAlign='center'> + <Label color='red'>Nem jelentkezett</Label> + </Table.Cell> + } + <Table.Cell> + <ConfirmModal + button = {<Button + color='blue' + size='tiny' + > + ADD STAFF STATUS + </Button>} + text='staff jogot adsz neki' + onAccept={() => this.props.setStatus(profile.id, 'Staff')} + /> + </Table.Cell> + </Table.Row> + ); + }); + } + + render() { + return ( + <Container + textAlign='center' + style={{ + padding: '80px' + }} + > + <Table color='blue' celled selectable compact> + <Table.Header> + <Table.Row> + <Table.HeaderCell>Jelentkezettek</Table.HeaderCell> + <Table.HeaderCell textAlign='center'>JelentkezĂŠs stĂĄtusza:</Table.HeaderCell> + <Table.HeaderCell /> + </Table.Row> + </Table.Header> + + <Table.Body> + {this.renderApplicants()} + </Table.Body> + </Table> + </Container> + ); + } +} + +const mapStateToProps = ({ trainees: { profiles }, user }) => ({ profiles, user }); + +export default connect(mapStateToProps, { getProfiles, setStatus })(Applications); diff --git a/src/reducers/TraineeReducer.js b/src/reducers/TraineeReducer.js index f7fa38e0d7e2645d76da834af90dc272cee159ef..526cd7ace95c4e1b758d31e7e81d84242e46a927 100644 --- a/src/reducers/TraineeReducer.js +++ b/src/reducers/TraineeReducer.js @@ -1,13 +1,22 @@ -import { GET_TRAINEES, GET_TRAINEE_BY_ID } from '../actions/types'; +import { GET_TRAINEES, GET_PROFILES, GET_SELECTED_PROFILE, SET_STATUS } from '../actions/types'; -const INITIAL_STATE = {}; +const INITIAL_STATE = { profiles: [], selectedProfile: {} }; export default (state = INITIAL_STATE, action) => { switch (action.type) { case GET_TRAINEES: return { ...state, trainees: [...action.payload] }; - case GET_TRAINEE_BY_ID: - return { ...state, selectedTrainee: action.payload }; + case GET_PROFILES: + return { ...state, profiles: [...action.payload] }; + case GET_SELECTED_PROFILE: + return { ...state, selectedProfile: action.payload }; + case SET_STATUS: + const index = state.profiles.findIndex(item => item.id === action.payload.id); + state.profiles.splice(index, 1, action.payload); + if (action.payload.id === state.selectedProfile.id) { + return { ...state, profiles: [...state.profiles], selectedProfile: action.payload }; + } + return { ...state, profiles: [...state.profiles] } default: return state; }