mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-27 09:13:14 +10:00
Move clearUserId to Auth.duck.js
Clear user ID from the logger in logout thunk instead of the Topbar. Also call dispatch logging function also as the last action of a thunk function where possible.
This commit is contained in:
parent
de5ec59119
commit
2cfd3deaa1
6 changed files with 14 additions and 14 deletions
|
|
@ -9,7 +9,6 @@ import { withFlattenedRoutes, withViewport } from '../../util/contextHelpers';
|
|||
import { parse, stringify } from '../../util/urlHelpers';
|
||||
import { createResourceLocatorString, pathByRouteName } from '../../util/routes';
|
||||
import * as propTypes from '../../util/propTypes';
|
||||
import { clearUserId } from '../../util/log';
|
||||
import {
|
||||
Button,
|
||||
IconEmailAttention,
|
||||
|
|
@ -146,9 +145,6 @@ class TopbarComponent extends Component {
|
|||
window.location = path;
|
||||
}
|
||||
|
||||
// clear user id from logger
|
||||
clearUserId();
|
||||
|
||||
// TODO: show flash message
|
||||
console.log('logged out'); // eslint-disable-line
|
||||
});
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ export const initiateOrder = params =>
|
|||
return orderId;
|
||||
})
|
||||
.catch(e => {
|
||||
dispatch(logError(e, 'initiate-order-failed'));
|
||||
dispatch(initiateOrderError(e));
|
||||
dispatch(logError(e, 'initiate-order-failed'));
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -144,13 +144,13 @@ export const acceptSale = id =>
|
|||
return response;
|
||||
})
|
||||
.catch(e => {
|
||||
dispatch(acceptSaleError(e));
|
||||
dispatch(
|
||||
logError(e, 'accept-sale-failed', {
|
||||
txId: id,
|
||||
transition: propTypes.TX_TRANSITION_ACCEPT,
|
||||
})
|
||||
);
|
||||
dispatch(acceptSaleError(e));
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
|
@ -171,13 +171,13 @@ export const rejectSale = id =>
|
|||
return response;
|
||||
})
|
||||
.catch(e => {
|
||||
dispatch(rejectSaleError(e));
|
||||
dispatch(
|
||||
logError(e, 'redect-sale-failed', {
|
||||
txId: id,
|
||||
transition: propTypes.TX_TRANSITION_REJECT,
|
||||
})
|
||||
);
|
||||
dispatch(rejectSaleError(e));
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { clearCurrentUser, fetchCurrentUser } from './user.duck';
|
||||
import { logError } from './log.duck';
|
||||
import * as log from '../util/log';
|
||||
|
||||
const authenticated = authInfo => authInfo.grantType === 'refresh_token';
|
||||
|
||||
|
|
@ -157,7 +158,10 @@ export const logout = () =>
|
|||
.logout()
|
||||
.then(() => dispatch(clearCurrentUser()))
|
||||
.then(() => dispatch(logoutSuccess()))
|
||||
.then(() => dispatch(userLogout()))
|
||||
.then(() => {
|
||||
dispatch(userLogout());
|
||||
log.clearUserId();
|
||||
})
|
||||
.catch(e => dispatch(logoutError(e)));
|
||||
};
|
||||
|
||||
|
|
@ -176,7 +180,7 @@ export const signup = params =>
|
|||
.then(() => dispatch(signupSuccess()))
|
||||
.then(() => dispatch(login(email, password)))
|
||||
.catch(e => {
|
||||
dispatch(logError(e, 'signup-failed'));
|
||||
dispatch(signupError(e));
|
||||
dispatch(logError(e, 'signup-failed'));
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* A utility duck file that can be used to pass
|
||||
* error data to a logger.
|
||||
* A utility duck file that allows logger to be
|
||||
* used with Redux's `dispatch` function.
|
||||
*/
|
||||
|
||||
import * as log from '../util/log';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { authInfo } from './Auth.duck';
|
||||
import { updatedEntities, denormalisedEntities } from '../util/data';
|
||||
import { TX_TRANSITION_PREAUTHORIZE } from '../util/propTypes';
|
||||
import { setUserId } from '../util/log';
|
||||
import { logError } from './log.duck';
|
||||
import * as log from '../util/log';
|
||||
|
||||
// ================ Action types ================ //
|
||||
|
||||
|
|
@ -340,7 +340,7 @@ export const fetchCurrentUser = () =>
|
|||
const denormalised = denormalisedEntities(entities, 'current-user', [currentUserId]);
|
||||
const currentUser = denormalised[0];
|
||||
// set current user id to the logger
|
||||
setUserId(currentUser.id.uuid);
|
||||
log.setUserId(currentUser.id.uuid);
|
||||
dispatch(currentUserShowSuccess(currentUser));
|
||||
return currentUser;
|
||||
})
|
||||
|
|
@ -379,8 +379,8 @@ export const createStripeAccount = payoutDetails =>
|
|||
dispatch(stripeAccountCreateSuccess(accountResponse));
|
||||
})
|
||||
.catch(e => {
|
||||
dispatch(logError(e, 'create-stripe-account-failed'));
|
||||
dispatch(stripeAccountCreateError(e));
|
||||
dispatch(logError(e, 'create-stripe-account-failed'));
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue