Skip to content
Snippets Groups Projects
Commit 999661a3 authored by Chif Gergő's avatar Chif Gergő
Browse files

Create add event action

parent 7fb1f364
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
GET_TRAINEES, VISITOR_CHANGE, GET_TRAINEES, VISITOR_CHANGE,
GET_NOTES_BY_EVENT, GET_NOTES_BY_EVENT,
WRITE_EVENT, WRITE_EVENT,
ADD_EVENT,
} from './types'; } from './types';
export const getEvents = () => ( export const getEvents = () => (
...@@ -79,9 +80,9 @@ export const submitVisitors = ({ id, visitors }) => ( ...@@ -79,9 +80,9 @@ export const submitVisitors = ({ id, visitors }) => (
} }
); );
export const writeEvent = event => ( export const writeEvent = ({ target: { name, value } }) => (
(dispatch) => { (dispatch) => {
dispatch({ type: WRITE_EVENT, payload: event.target.value, target: event.name }); dispatch({ type: WRITE_EVENT, payload: value, target: name });
} }
); );
...@@ -91,3 +92,25 @@ export const eventDate = (name, value) => ( ...@@ -91,3 +92,25 @@ export const eventDate = (name, value) => (
dispatch({ type: WRITE_EVENT, payload: value, target: name }); dispatch({ type: WRITE_EVENT, payload: value, target: name });
} }
); );
export const addEvent = ({ name, date }) => (
async (dispatch) => {
try {
const response = await axios.post('/api/v1/events/', {
name,
date,
});
if (response.data.id) {
alert('Sikeres mentés!');
dispatch({
type: ADD_EVENT,
payload: response.data,
});
} else {
alert('Mentés nem sikerült!');
}
} catch (e) {
console.log(e);
}
}
);
...@@ -20,3 +20,4 @@ export const VISITOR_CHANGE = 'visitor_change'; ...@@ -20,3 +20,4 @@ export const VISITOR_CHANGE = 'visitor_change';
export const GET_NOTES_BY_EVENT = 'get_notes_by_event'; export const GET_NOTES_BY_EVENT = 'get_notes_by_event';
export const WRITE_EVENT = 'write_event'; export const WRITE_EVENT = 'write_event';
export const ADD_EVENT = 'add_event';
...@@ -3,8 +3,8 @@ import { Modal, Button, Form, Input, TextArea, Icon } from 'semantic-ui-react'; ...@@ -3,8 +3,8 @@ import { Modal, Button, Form, Input, TextArea, Icon } from 'semantic-ui-react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { DateTimeInput } from 'semantic-ui-calendar-react'; import { DateTimeInput } from 'semantic-ui-calendar-react';
import { clearWrite } from '../../actions/news'; // import { clearWrite } from '../../actions/news';
import { writeEvent, eventDate } from '../../actions/statistics' import { writeEvent, eventDate, addEvent } from '../../actions/statistics'
class AddEventForm extends Component { class AddEventForm extends Component {
constructor(props) { constructor(props) {
...@@ -59,6 +59,7 @@ class AddEventForm extends Component { ...@@ -59,6 +59,7 @@ class AddEventForm extends Component {
<DateTimeInput <DateTimeInput
name="date" name="date"
label="Dátum:" label="Dátum:"
dateFormat='YYYY-MM-DD'
placeholder="Date" placeholder="Date"
value={this.state.date} value={this.state.date}
iconPosition="left" iconPosition="left"
...@@ -79,8 +80,8 @@ class AddEventForm extends Component { ...@@ -79,8 +80,8 @@ class AddEventForm extends Component {
inverted inverted
color='green' color='green'
onClick={() => { onClick={() => {
this.props.addEvent(); this.props.addEvent(this.props.newEvent);
this.setState({ showModal: false }); this.setState({ showModal: false, date: '' });
}} }}
> >
<Icon name='checkmark' /> Add <Icon name='checkmark' /> Add
...@@ -93,4 +94,4 @@ class AddEventForm extends Component { ...@@ -93,4 +94,4 @@ class AddEventForm extends Component {
const mapStateToProps = ({ events: { newEvent } }) => ({ newEvent }); const mapStateToProps = ({ events: { newEvent } }) => ({ newEvent });
export default connect(mapStateToProps, { writeEvent, clearWrite, eventDate })(AddEventForm); export default connect(mapStateToProps, { writeEvent, addEvent, eventDate })(AddEventForm);
import { GET_EVENTS, GET_EVENT_BY_ID, VISITOR_CHANGE, WRITE_EVENT } from '../actions/types'; import { GET_EVENTS, GET_EVENT_BY_ID, VISITOR_CHANGE, WRITE_EVENT, ADD_EVENT } from '../actions/types';
const INITIAL_STATE = { newEvent: {} }; const INITIAL_STATE = { newEvent: {} };
...@@ -11,7 +11,9 @@ export default (state = INITIAL_STATE, action) => { ...@@ -11,7 +11,9 @@ export default (state = INITIAL_STATE, action) => {
case VISITOR_CHANGE: case VISITOR_CHANGE:
return { ...state, selectedEvent: { ...state.selectedEvent, visitors: action.payload } }; return { ...state, selectedEvent: { ...state.selectedEvent, visitors: action.payload } };
case WRITE_EVENT: case WRITE_EVENT:
return { ...state, newEvent: { ...state.selectedEvent, [action.target]: action.payload } }; return { ...state, newEvent: { ...state.newEvent, [action.target]: action.payload } };
case ADD_EVENT:
return { ...state, events: [...state.events, action.payload] };
default: default:
return state; return state;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment