mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 12:43:11 +10:00
Check tx ref when initializing state
This commit is contained in:
parent
8925b1bd3a
commit
ebeb100e4b
1 changed files with 9 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import pick from 'lodash/pick';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import { types as sdkTypes } from '../../util/sdkLoader';
|
||||
import { isTransactionsTransitionInvalidTransition, storableError } from '../../util/errors';
|
||||
import {
|
||||
|
|
@ -27,8 +28,6 @@ const CUSTOMER = 'customer';
|
|||
|
||||
export const SET_INITAL_VALUES = 'app/TransactionPage/SET_INITIAL_VALUES';
|
||||
|
||||
export const RESET_STATE = 'app/TransactionPage/RESET_STATE';
|
||||
|
||||
export const FETCH_TRANSACTION_REQUEST = 'app/TransactionPage/FETCH_TRANSACTION_REQUEST';
|
||||
export const FETCH_TRANSACTION_SUCCESS = 'app/TransactionPage/FETCH_TRANSACTION_SUCCESS';
|
||||
export const FETCH_TRANSACTION_ERROR = 'app/TransactionPage/FETCH_TRANSACTION_ERROR';
|
||||
|
|
@ -91,9 +90,6 @@ export default function checkoutPageReducer(state = initialState, action = {}) {
|
|||
case SET_INITAL_VALUES:
|
||||
return { ...initialState, ...payload };
|
||||
|
||||
case RESET_STATE:
|
||||
return { ...state, sendMessageError: null, sendReviewError: null, messages: [] };
|
||||
|
||||
case FETCH_TRANSACTION_REQUEST:
|
||||
return { ...state, fetchTransactionInProgress: true, fetchTransactionError: null };
|
||||
case FETCH_TRANSACTION_SUCCESS: {
|
||||
|
|
@ -173,9 +169,6 @@ export const setInitialValues = initialValues => ({
|
|||
payload: pick(initialValues, Object.keys(initialState)),
|
||||
});
|
||||
|
||||
// clears tx page message and review sending errors
|
||||
const resetState = () => ({ type: RESET_STATE });
|
||||
|
||||
const fetchTransactionRequest = () => ({ type: FETCH_TRANSACTION_REQUEST });
|
||||
const fetchTransactionSuccess = response => ({
|
||||
type: FETCH_TRANSACTION_SUCCESS,
|
||||
|
|
@ -479,11 +472,16 @@ export const sendReview = (role, tx, reviewRating, reviewContent) => (dispatch,
|
|||
|
||||
// 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 => {
|
||||
export const loadData = params => (dispatch, getState) => {
|
||||
const txId = new UUID(params.id);
|
||||
const state = getState().TransactionPage;
|
||||
const txRef = state.transactionRef;
|
||||
|
||||
// Clear the send error since the message form is emptied as well.
|
||||
dispatch(resetState());
|
||||
// In case a transaction reference is found from a previous
|
||||
// data load -> clear the state. Otherwise keep the non-null
|
||||
// values which may have been set from a previous page.
|
||||
const initialValues = txRef ? {} : pickBy(state, v => !!v);
|
||||
dispatch(setInitialValues(initialValues));
|
||||
|
||||
// Sale / order (i.e. transaction entity in API)
|
||||
return Promise.all([dispatch(fetchTransaction(txId)), dispatch(fetchMessages(txId, 1))]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue