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

Merge branch 'token-selector-in-pizza-saga' into 'master'

Use tokenselector in pizza sagas and actions

See merge request thalia/ThaliApp-react!122
parents 6435c1ac fbde71fe
......@@ -7,10 +7,9 @@ export const CANCEL_SUCCESS = 'PIZZA_CANCEL_SUCCESS';
export const ORDER = 'PIZZA_ORDER';
export const ORDER_SUCCESS = 'PIZZA_ORDER_SUCCESS';
export function retrievePizzaInfo(token) {
export function retrievePizzaInfo() {
return {
type: PIZZA,
payload: { token },
};
}
......@@ -33,10 +32,9 @@ export function failure() {
};
}
export function cancelOrder(token) {
export function cancelOrder() {
return {
type: CANCEL,
payload: { token },
};
}
......@@ -46,10 +44,10 @@ export function cancelSuccess() {
};
}
export function orderPizza(token, pk, hasOrder) {
export function orderPizza(pk, hasOrder) {
return {
type: ORDER,
payload: { token, pk, hasOrder },
payload: { pk, hasOrder },
};
}
......
......@@ -46,7 +46,7 @@ const EventDetailCard = props => (
<View style={styles.buttonList}>
{props.event.pizza ? (
<TouchableOpacity
onPress={() => props.retrievePizzaInfo(props.token)}
onPress={() => props.retrievePizzaInfo()}
style={styles.button}
>
<Text style={styles.orderPizza}>PIZZA</Text>
......@@ -87,7 +87,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({
loadEvent: (pk, token) => dispatch(actions.event(pk, token)),
retrievePizzaInfo: token => dispatch(retrievePizzaInfo(token)),
retrievePizzaInfo: () => dispatch(retrievePizzaInfo()),
});
export default connect(mapStateToProps, mapDispatchToProps)(EventDetailCard);
......@@ -69,7 +69,7 @@ class Pizza extends Component {
</View>
{(!order.paid && !hasEnded) && (
<TouchableOpacity
onPress={() => this.props.cancelOrder(this.props.token)}
onPress={() => this.props.cancelOrder()}
style={styles.button}
>
<Icon
......@@ -105,7 +105,7 @@ class Pizza extends Component {
</View>
<TouchableOpacity
onPress={() => {
this.props.orderPizza(this.props.token, pizza.pk, hasOrder);
this.props.orderPizza(pizza.pk, hasOrder);
this.pizzaScroll.scrollTo({ x: 0, y: 0, animated: true });
}}
style={styles.button}
......@@ -123,7 +123,7 @@ class Pizza extends Component {
);
handleRefresh = () => {
this.props.retrievePizzaInfo(this.props.token);
this.props.retrievePizzaInfo();
};
render() {
......@@ -223,7 +223,6 @@ Pizza.propTypes = {
price: PropTypes.string.isRequired,
available: PropTypes.bool.isRequired,
})).isRequired,
token: PropTypes.string.isRequired,
retrievePizzaInfo: PropTypes.func.isRequired,
cancelOrder: PropTypes.func.isRequired,
orderPizza: PropTypes.func.isRequired,
......@@ -241,13 +240,12 @@ const mapStateToProps = state => ({
event: state.pizza.event,
order: state.pizza.order,
pizzaList: state.pizza.pizzaList,
token: state.session.token,
});
const mapDispatchToProps = dispatch => ({
retrievePizzaInfo: token => dispatch(retrievePizzaInfo(token)),
cancelOrder: token => dispatch(cancelOrder(token)),
orderPizza: (token, pk, hasOrder) => dispatch(orderPizza(token, pk, hasOrder)),
retrievePizzaInfo: () => dispatch(retrievePizzaInfo()),
cancelOrder: () => dispatch(cancelOrder()),
orderPizza: (pk, hasOrder) => dispatch(orderPizza(pk, hasOrder)),
});
export default connect(mapStateToProps, mapDispatchToProps)(Pizza);
import { call, put, takeEvery } from 'redux-saga/effects';
import { apiRequest } from '../url';
import { call, put, takeEvery, select } from 'redux-saga/effects';
import { apiRequest, tokenSelector } from '../url';
import * as pizzaActions from '../actions/pizza';
import * as navigationActions from '../actions/navigation';
const NOT_FOUND = 404;
const retrievePizzaInfo = function* retrievePizzaInfo(action) {
const { token } = action.payload;
const retrievePizzaInfo = function* retrievePizzaInfo() {
const token = yield select(tokenSelector);
yield put(pizzaActions.fetching());
yield put(navigationActions.navigate('pizza'));
......@@ -43,8 +43,8 @@ const retrievePizzaInfo = function* retrievePizzaInfo(action) {
}
};
const cancel = function* cancel(action) {
const { token } = action.payload;
const cancel = function* cancel() {
const token = yield select(tokenSelector);
const data = {
method: 'DELETE',
headers: {
......@@ -63,7 +63,8 @@ const cancel = function* cancel(action) {
};
const order = function* order(action) {
const { token, pk, hasOrder } = action.payload;
const { pk, hasOrder } = action.payload;
const token = yield select(tokenSelector);
const data = {
method: hasOrder ? 'PUT' : 'POST',
headers: {
......
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