Commit 03d99a04 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Load registrations if necessary before opening event

parent 7327c4cb
......@@ -8,6 +8,4 @@ export const OPENDRAWER = 'OPENDRAWER';
export const CALENDARRETREIVED = 'CALENDARRETREIVED';
export const CALENDARERROR = 'CALENDARERROR';
export const LOADEVENTSUCCESS = 'LOADEVENTSUCCESS';
export const LOADEVENTFAILURE = 'LOADEVENTFAILURE';
export const LOADEVENTREGISTRATIONSSUCCESS = 'LOADEVENTREGISTRATIONSSUCCESS';
export const LOADEVENTREGISTRATIONSFAILURE = 'LOADEVENTREGISTRATIONSFAILURE';
export const LOADEVENTFAILURE = 'LOADEVENTFAILURE';
\ No newline at end of file
......@@ -2,49 +2,43 @@ import * as types from './actionTypes';
import { navigate } from './navigation';
import { url } from '../url';
export function success(type, data) {
export function success(data, registrations) {
return {
type,
type: types.LOADEVENTSUCCESS,
data,
registrations,
};
}
export function fail(type) {
export function fail() {
return {
type,
type: types.LOADEVENTFAILURE,
};
}
export function loadEvent(id, token) {
return (dispatch) => {
const data = {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Token ${token}`,
},
};
return fetch(`${url}/api/events/${id}/`, data)
.then(
response => response.json(),
)
.then(
(response) => {
dispatch(success(types.LOADEVENTSUCCESS, response));
dispatch(navigate('event'));
},
)
.catch(
() => {
dispatch(fail(types.LOADEVENTFAILURE));
dispatch(navigate('event'));
},
);
function loadRegistrations(id, token) {
const data = {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Token ${token}`,
},
};
return fetch(`${url}/api/events/${id}/registrations`, data)
.then(
response => response.json(),
)
.then(
response => response,
)
.catch(
() => [],
);
}
export function loadRegistrations(id, token) {
export function loadEvent(id, token) {
return (dispatch) => {
const data = {
method: 'GET',
......@@ -54,18 +48,28 @@ export function loadRegistrations(id, token) {
Authorization: `Token ${token}`,
},
};
return fetch(`${url}/api/events/${id}/registrations`, data)
return fetch(`${url}/api/events/${id}/`, data)
.then(
response => response.json(),
)
.then(
(response) => {
dispatch(success(types.LOADEVENTREGISTRATIONSSUCCESS, response));
if (response.status > -1) {
loadRegistrations(id, token)
.then((registrations) => {
dispatch(success(response, registrations));
dispatch(navigate('event'));
});
} else {
dispatch(success(response, []));
dispatch(navigate('event'));
}
},
)
.catch(
() => {
dispatch(fail(types.LOADEVENTREGISTRATIONSFAILURE));
dispatch(fail());
dispatch(navigate('event'));
},
);
};
......
import React from 'react';
import { Image, ScrollView, Text, View } from 'react-native';
import { connect } from 'react-redux';
import Moment from 'moment';
import 'moment/locale/nl';
import React from "react";
import {Image, ScrollView, Text, View} from "react-native";
import {connect} from "react-redux";
import Moment from "moment";
import "moment/locale/nl";
import styles from './style/event';
import * as actions from '../actions/events';
import MemberView from './MemberView';
import styles from "./style/event";
import MemberView from "./MemberView";
const REGISTRATION_NOT_NEEDED = -1;
const REGISTRATION_NOT_YET_OPEN = 0;
......@@ -18,8 +17,6 @@ const REGISTRATION_CLOSED_CANCEL_ONLY = 4;
const Event = (props) => {
if (props.success) {
props.loadRegistrations(props.data.pk, props.token);
const eventDesc = (data) => {
const startDate = Moment(data.start).format('D MMM YYYY, HH:mm');
const endDate = Moment(data.end).format('D MMM YYYY, HH:mm');
......@@ -228,19 +225,12 @@ Event.propTypes = {
name: React.PropTypes.string.isRequired,
})).isRequired,
success: React.PropTypes.bool.isRequired,
token: React.PropTypes.string.isRequired,
loadRegistrations: React.PropTypes.func.isRequired,
};
const mapStateToProps = state => ({
data: state.events.data,
registrations: state.events.registrations,
success: state.events.success,
token: state.session.token,
});
const mapDispatchToProps = dispatch => ({
loadRegistrations: (id, token) => dispatch(actions.loadRegistrations(id, token)),
});
export default connect(mapStateToProps, mapDispatchToProps)(Event);
export default connect(mapStateToProps, () => ({}))(Event);
......@@ -23,6 +23,7 @@ export default function loadEvent(state = initialState, action = {}) {
return {
...state,
data: action.data,
registrations: action.registrations,
success: true,
};
case types.LOADEVENTFAILURE:
......@@ -30,16 +31,6 @@ export default function loadEvent(state = initialState, action = {}) {
...state,
success: false,
};
case types.LOADEVENTREGISTRATIONSSUCCESS:
return {
...state,
registrations: action.data,
};
case types.LOADEVENTREGISTRATIONSFAILURE:
return {
...state,
registrations: action.data,
};
default:
return state;
}
......
......@@ -280,8 +280,9 @@
2A30344F7F0A4E50A76BDA3F /* Zocial.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Zocial.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Zocial.ttf"; sourceTree = "<group>"; };
2D02E47B1E0B4A5D006451C7 /* ThaliApp-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ThaliApp-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2D02E4901E0B4A5D006451C7 /* ThaliApp-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ThaliApp-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
3AF00CDF61D94356B607ED10 /* EvilIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = EvilIcons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf"; sourceTree = "<group>"; };
5A90BA3FF7F8422A9150FDAA /* BVLinearGradient.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = BVLinearGradient.xcodeproj; path = "../node_modules/react-native-linear-gradient/BVLinearGradient.xcodeproj"; sourceTree = "<group>"; };
36FBC99CE86E4E6FB2CC85CA /* libRNVectorIcons.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNVectorIcons.a; sourceTree = "<group>"; };
3AF00CDF61D94356B607ED10 /* EvilIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = EvilIcons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf"; sourceTree = "<group>"; };
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment