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

Add ability to show partner events

parent 8577c76a
...@@ -162,6 +162,8 @@ Calendar.propTypes = { ...@@ -162,6 +162,8 @@ Calendar.propTypes = {
price: PropTypes.string, price: PropTypes.string,
registered: PropTypes.bool, registered: PropTypes.bool,
pizza: PropTypes.bool, pizza: PropTypes.bool,
partner: PropTypes.bool,
url: PropTypes.string,
})).isRequired, })).isRequired,
loading: PropTypes.bool.isRequired, loading: PropTypes.bool.isRequired,
refresh: PropTypes.func.isRequired, refresh: PropTypes.func.isRequired,
......
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { View, Text, TouchableHighlight } from 'react-native'; import { View, Text, TouchableHighlight, Linking } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Moment from 'moment'; import Moment from 'moment';
import 'moment/locale/nl'; import 'moment/locale/nl';
...@@ -23,12 +23,22 @@ const getEventInfo = (event) => { ...@@ -23,12 +23,22 @@ const getEventInfo = (event) => {
const EventCard = props => ( const EventCard = props => (
<TouchableHighlight <TouchableHighlight
onPress={() => props.loadEvent(props.event.pk, props.token)} onPress={() => props.loadEvent(props.event, props.token)}
style={styles.button} style={styles.button}
> >
<View style={[styles.card, props.event.registered ? styles.registered : styles.unregistered]}> <View
<Text style={styles.eventTitle}>{props.event.title}</Text> style={[
<Text style={styles.eventInfo}>{getEventInfo(props.event)}</Text> styles.card,
props.event.registered ? styles.registered : null,
props.event.partner ? styles.partner : null,
]}
>
<Text style={[styles.eventTitle, props.event.partner ? styles.partnerEventTitle : null]}>
{props.event.title}
</Text>
<Text style={[styles.eventInfo, props.event.partner ? styles.partnerEventInfo : null]}>
{getEventInfo(props.event)}
</Text>
</View> </View>
</TouchableHighlight> </TouchableHighlight>
); );
...@@ -44,6 +54,8 @@ EventCard.propTypes = { ...@@ -44,6 +54,8 @@ EventCard.propTypes = {
pk: PropTypes.number, pk: PropTypes.number,
registered: PropTypes.bool, registered: PropTypes.bool,
pizza: PropTypes.bool, pizza: PropTypes.bool,
partner: PropTypes.bool,
url: PropTypes.string,
}).isRequired, }).isRequired,
loadEvent: PropTypes.func.isRequired, loadEvent: PropTypes.func.isRequired,
token: PropTypes.string.isRequired, token: PropTypes.string.isRequired,
...@@ -54,7 +66,13 @@ const mapStateToProps = state => ({ ...@@ -54,7 +66,13 @@ const mapStateToProps = state => ({
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
loadEvent: (pk, token) => dispatch(eventActions.event(pk, token)), loadEvent: (event, token) => {
if (event.partner) {
Linking.openURL(event.url);
} else {
dispatch(eventActions.event(event.pk, token));
}
},
}); });
export default connect(mapStateToProps, mapDispatchToProps)(EventCard); export default connect(mapStateToProps, mapDispatchToProps)(EventCard);
...@@ -13,22 +13,29 @@ const styles = StyleSheet.create({ ...@@ -13,22 +13,29 @@ const styles = StyleSheet.create({
card: { card: {
padding: 16, padding: 16,
borderRadius: 2, borderRadius: 2,
backgroundColor: colors.gray,
}, },
registered: { registered: {
backgroundColor: colors.magenta, backgroundColor: colors.magenta,
}, },
unregistered: { partner: {
backgroundColor: colors.gray, backgroundColor: colors.black,
}, },
eventTitle: { eventTitle: {
fontFamily: 'sans-serif-medium', fontFamily: 'sans-serif-medium',
color: colors.white, color: colors.white,
}, },
partnerEventTitle: {
color: colors.magenta,
},
eventInfo: { eventInfo: {
fontFamily: 'sans-serif-medium', fontFamily: 'sans-serif-medium',
color: colors.white, color: colors.white,
opacity: 0.8, opacity: 0.8,
}, },
partnerEventInfo: {
color: colors.magenta,
},
}); });
export default styles; export default styles;
...@@ -17,7 +17,18 @@ const calendar = function* calendar() { ...@@ -17,7 +17,18 @@ const calendar = function* calendar() {
try { try {
const events = yield call(apiRequest, 'events', data); const events = yield call(apiRequest, 'events', data);
yield put(calendarActions.success(events)); let partnerEvents = [];
try {
partnerEvents = yield call(apiRequest, 'partners/events', data);
partnerEvents = partnerEvents.map(event => ({
...event,
pk: -event.pk,
partner: true,
}));
} catch (error) {
// Swallow the error
}
yield put(calendarActions.success(events.concat(partnerEvents)));
} catch (error) { } catch (error) {
yield put(calendarActions.failure()); yield put(calendarActions.failure());
} }
......
Markdown is supported
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