-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect MySubscription + OrderHistory to API
- Loading branch information
Showing
16 changed files
with
352 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import axios from 'axios'; | ||
import { AsyncStorage } from 'react-native'; | ||
|
||
import actionTypes from '../constants/actionTypes/order'; | ||
import { baseURL } from '../utils/envConfig'; | ||
|
||
export const setSelectedOrder = order => { | ||
return { type: actionTypes.SET_SELECTED_ORDER, payload: order }; | ||
}; | ||
|
||
export const cancelOrder = orderId => async dispatch => { | ||
dispatch({ type: actionTypes.CANCEL_ORDER_PENDING }); | ||
const accessToken = await AsyncStorage.getItem('accessToken'); | ||
|
||
try { | ||
const res = await axios.post( | ||
baseURL, | ||
{ | ||
query: ` | ||
mutation { | ||
cancelOrder(orderId: "${orderId}") { | ||
id, | ||
cancelDate | ||
} | ||
} | ||
`, | ||
}, | ||
{ headers: { Authorization: accessToken } } | ||
); | ||
|
||
const { id, cancelDate } = res.data.data.cancelOrder; | ||
dispatch({ | ||
type: actionTypes.CANCEL_ORDER_SUCCESS, | ||
payload: { id, cancelDate }, | ||
}); | ||
} catch (err) { | ||
console.log('ERROR cancelOrder: ', err.response.data); | ||
dispatch({ type: actionTypes.CANCEL_ORDER_FAIL }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getAsyncActionType } from '../../utils/redux'; | ||
|
||
const SET_SELECTED_ORDER = 'SET_SELECTED_ORDER'; | ||
const CANCEL_ORDER = 'CANCEL_ORDER'; | ||
|
||
export default { | ||
SET_SELECTED_ORDER, | ||
...getAsyncActionType(CANCEL_ORDER), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import actionTypes from '../constants/actionTypes/order'; | ||
|
||
const INITIAL_STATE = { | ||
selectedOrder: {}, | ||
}; | ||
|
||
export default (state = INITIAL_STATE, { type, payload }) => { | ||
switch (type) { | ||
case actionTypes.SET_SELECTED_ORDER: | ||
return { | ||
...state, | ||
selectedOrder: payload, | ||
}; | ||
case actionTypes.CANCEL_ORDER_SUCCESS: | ||
return { | ||
...state, | ||
selectedOrder: { | ||
...state.selectedOrder, | ||
cancelDate: payload.cancelDate, | ||
}, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.