mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
TransactionPage.duck: Fetch process transitions on loadData
This commit is contained in:
parent
3eb5f16544
commit
a3898f6341
1 changed files with 40 additions and 1 deletions
|
|
@ -35,6 +35,10 @@ export const FETCH_TRANSACTION_REQUEST = 'app/TransactionPage/FETCH_TRANSACTION_
|
|||
export const FETCH_TRANSACTION_SUCCESS = 'app/TransactionPage/FETCH_TRANSACTION_SUCCESS';
|
||||
export const FETCH_TRANSACTION_ERROR = 'app/TransactionPage/FETCH_TRANSACTION_ERROR';
|
||||
|
||||
export const FETCH_TRANSITIONS_REQUEST = 'app/TransactionPage/FETCH_TRANSITIONS_REQUEST';
|
||||
export const FETCH_TRANSITIONS_SUCCESS = 'app/TransactionPage/FETCH_TRANSITIONS_SUCCESS';
|
||||
export const FETCH_TRANSITIONS_ERROR = 'app/TransactionPage/FETCH_TRANSITIONS_ERROR';
|
||||
|
||||
export const ACCEPT_SALE_REQUEST = 'app/TransactionPage/ACCEPT_SALE_REQUEST';
|
||||
export const ACCEPT_SALE_SUCCESS = 'app/TransactionPage/ACCEPT_SALE_SUCCESS';
|
||||
export const ACCEPT_SALE_ERROR = 'app/TransactionPage/ACCEPT_SALE_ERROR';
|
||||
|
|
@ -82,6 +86,9 @@ const initialState = {
|
|||
sendReviewError: null,
|
||||
timeSlots: null,
|
||||
fetchTimeSlotsError: null,
|
||||
fetchTransitionsInProgress: false,
|
||||
fetchTransitionsError: null,
|
||||
processTransitions: null,
|
||||
};
|
||||
|
||||
// Merge entity arrays using ids, so that conflicting items in newer array (b) overwrite old values (a).
|
||||
|
|
@ -109,6 +116,14 @@ export default function checkoutPageReducer(state = initialState, action = {}) {
|
|||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, fetchTransactionInProgress: false, fetchTransactionError: payload };
|
||||
|
||||
case FETCH_TRANSITIONS_REQUEST:
|
||||
return { ...state, fetchTransitionsInProgress: true, fetchTransitionsError: null };
|
||||
case FETCH_TRANSITIONS_SUCCESS:
|
||||
return { ...state, fetchTransitionsInProgress: false, processTransitions: payload };
|
||||
case FETCH_TRANSITIONS_ERROR:
|
||||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, fetchTransitionsInProgress: false, fetchTransitionsError: payload };
|
||||
|
||||
case ACCEPT_SALE_REQUEST:
|
||||
return { ...state, acceptInProgress: true, acceptSaleError: null, declineSaleError: null };
|
||||
case ACCEPT_SALE_SUCCESS:
|
||||
|
|
@ -192,6 +207,13 @@ const fetchTransactionSuccess = response => ({
|
|||
});
|
||||
const fetchTransactionError = e => ({ type: FETCH_TRANSACTION_ERROR, error: true, payload: e });
|
||||
|
||||
const fetchTransitionsRequest = () => ({ type: FETCH_TRANSITIONS_REQUEST });
|
||||
const fetchTransitionsSuccess = response => ({
|
||||
type: FETCH_TRANSITIONS_SUCCESS,
|
||||
payload: response,
|
||||
});
|
||||
const fetchTransitionsError = e => ({ type: FETCH_TRANSITIONS_ERROR, error: true, payload: e });
|
||||
|
||||
const acceptSaleRequest = () => ({ type: ACCEPT_SALE_REQUEST });
|
||||
const acceptSaleSuccess = () => ({ type: ACCEPT_SALE_SUCCESS });
|
||||
const acceptSaleError = e => ({ type: ACCEPT_SALE_ERROR, error: true, payload: e });
|
||||
|
|
@ -564,6 +586,19 @@ const fetchTimeSlots = listingId => (dispatch, getState, sdk) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const fetchNextTransitions = id => (dispatch, getState, sdk) => {
|
||||
dispatch(fetchTransitionsRequest());
|
||||
|
||||
return sdk.processTransitions
|
||||
.query({ transactionId: id })
|
||||
.then(res => {
|
||||
dispatch(fetchTransitionsSuccess(res.data.data));
|
||||
})
|
||||
.catch(e => {
|
||||
dispatch(fetchTransitionsError(storableError(e)));
|
||||
});
|
||||
};
|
||||
|
||||
// loadData is a collection of async calls that need to be made
|
||||
// before page has all the info it needs to render itself
|
||||
export const loadData = params => (dispatch, getState) => {
|
||||
|
|
@ -579,5 +614,9 @@ export const loadData = params => (dispatch, getState) => {
|
|||
dispatch(setInitialValues(initialValues));
|
||||
|
||||
// Sale / order (i.e. transaction entity in API)
|
||||
return Promise.all([dispatch(fetchTransaction(txId, txRole)), dispatch(fetchMessages(txId, 1))]);
|
||||
return Promise.all([
|
||||
dispatch(fetchTransaction(txId, txRole)),
|
||||
dispatch(fetchMessages(txId, 1)),
|
||||
dispatch(fetchNextTransitions(txId)),
|
||||
]);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue