diff --git a/src/actions/auth.js b/src/actions/auth.js index fbe16645ab94567d0ae6261d85d84ff761c733c1..5950df0b84dcb31f76e8d85c6539c584420ff72e 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -1,5 +1,5 @@ import axios from './session'; -import { GET_USERDATA, PROFILE_CHANGE, GROUP_CHANGE } from './types'; +import { GET_USERDATA, PROFILE_CHANGE, GROUP_CHANGE, GET_DEADLINE } from './types'; export const getUserData = () => ( @@ -45,6 +45,21 @@ export const getUserData = () => ( } ); +export const getDeadline = () => ( + async (dispatch) => { + try { + const response = await axios.get('/api/v1/profiles/deadline'); + + dispatch({ + type: GET_DEADLINE, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); + export const textChange = ({ target: { name, value } }) => ( (dispatch) => { dispatch({ type: PROFILE_CHANGE, payload: value, target: name }); diff --git a/src/actions/types.js b/src/actions/types.js index d298902813c530d2731c32a493f51f6dba6eb547..df9349efd28b1685578424277f959ea18f976bde 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -1,5 +1,6 @@ export const GET_USERDATA = 'get_userdata'; export const GET_NEWS = 'get_news'; +export const GET_DEADLINE = 'get_deadline'; export const PROFILE_CHANGE = 'profile_change'; export const GROUP_CHANGE = 'group_change'; diff --git a/src/components/pages/Profile.js b/src/components/pages/Profile.js index 719a4b97332ce0b211431d4f919a7abf91bda686..be3166ea50ace5dc3f34c93d1d1e74b8eb1fbf8a 100644 --- a/src/components/pages/Profile.js +++ b/src/components/pages/Profile.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { Container, Form, Dropdown, Divider, Segment } from 'semantic-ui-react'; import { connect } from 'react-redux'; import { textChange, submitRegistration, groupChange } from '../../actions'; +import { getDeadline } from '../../actions/auth' import HiddenForm from '../forms/HiddenForm' const options = [ @@ -14,6 +15,7 @@ const options = [ class Profile extends Component { componentWillMount() { + this.props.getDeadline() if (!this.props.id) { this.props.history.push('/home'); } @@ -21,22 +23,25 @@ class Profile extends Component { render() { const { - nick, groups, motivationAbout, motivationProfession, motivationExercise, signed, id, + nick, groups, motivationAbout, motivationProfession, motivationExercise, signed, id, deadline, text: deadlineText } = this.props; - const endDate = new Date(2020, 2, 14, 23, 59, 59) - const endDateText = `februĂĄr 14. 23:59-ig` + const endDate = new Date(deadline) + const endDateText = deadlineText let canEdit = Date.now()<endDate return ( <Container style={{ - marginTop: '0.5em', + marginTop: '1em', }} > + {canEdit ? <Segment inverted color='red' tertiary> <p style={{ fontSize: '1.33em' }}> A profilod mentĂŠs utĂĄn is mĂłdosĂthatĂł a kĂŠsĹbbiekben, egĂŠszen {endDateText}. </p> </Segment> + : ''} + <Form> {canEdit ? <Form.Input @@ -194,11 +199,12 @@ class Profile extends Component { } checked={signed} readOnly={!canEdit} + style={ !canEdit ? { marginBottom: '5em' } : null} /> {canEdit ? <Form.Button primary - style={{ marginBottom: '10em' }} + style={{ marginBottom: '5em' }} onClick={() => this.props.submitRegistration({ nick, motivationAbout, motivationProfession, motivationExercise, signed, groups, id, })} @@ -214,8 +220,8 @@ class Profile extends Component { const mapStateToProps = ({ user: { - nick, groups, motivationAbout, motivationProfession, motivationExercise, signed, id, - }, + nick, groups, motivationAbout, motivationProfession, motivationExercise, signed, id, deadline, text + } }) => ({ nick, groups, @@ -224,6 +230,8 @@ const mapStateToProps = ({ motivationExercise, signed, id, + deadline, + text }); -export default connect(mapStateToProps, { textChange, submitRegistration, groupChange })(Profile); +export default connect(mapStateToProps, { textChange, submitRegistration, groupChange, getDeadline })(Profile); diff --git a/src/reducers/UserReducer.js b/src/reducers/UserReducer.js index 839a47eb435192c9bbac2d2f7a23c134a3bcaed6..bcf9492cee8754beb866cc3c3b55fdd47b2f1905 100644 --- a/src/reducers/UserReducer.js +++ b/src/reducers/UserReducer.js @@ -2,6 +2,7 @@ import { GET_USERDATA, PROFILE_CHANGE, GROUP_CHANGE, + GET_DEADLINE, } from '../actions/types'; const INITIAL_STATE = { @@ -11,6 +12,8 @@ export default (state = INITIAL_STATE, action) => { switch (action.type) { case GET_USERDATA: return { ...state, ...action.payload }; + case GET_DEADLINE: + return { ...state, ...action.payload }; case PROFILE_CHANGE: return { ...state, [action.target]: action.payload }; case GROUP_CHANGE: