mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
Fetch current user on app init instead of in various loadData fns
This commit is contained in:
parent
2bb3a6e63e
commit
0747fc170a
10 changed files with 6 additions and 34 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { pick } from 'lodash';
|
||||
import { fetchCurrentUser } from '../../ducks/user.duck';
|
||||
|
||||
// ================ Action types ================ //
|
||||
|
||||
|
|
@ -75,10 +74,3 @@ export const initiateOrder = params =>
|
|||
throw e;
|
||||
});
|
||||
};
|
||||
|
||||
// ================ Thunk ================ //
|
||||
|
||||
export const loadData = () =>
|
||||
dispatch => {
|
||||
return dispatch(fetchCurrentUser());
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import * as propTypes from '../../util/propTypes';
|
|||
import { withFlattenedRoutes } from '../../util/contextHelpers';
|
||||
import { AuthorInfo, BookingInfo, NamedRedirect, PageLayout } from '../../components';
|
||||
import { StripePaymentForm } from '../../containers';
|
||||
import { initiateOrder, setInitialValues, loadData } from './CheckoutPage.duck';
|
||||
import { initiateOrder, setInitialValues } from './CheckoutPage.duck';
|
||||
|
||||
import css from './CheckoutPage.css';
|
||||
|
||||
|
|
@ -275,6 +275,4 @@ CheckoutPage.setInitialValues = initialValues => setInitialValues(initialValues)
|
|||
|
||||
CheckoutPage.displayName = 'CheckoutPage';
|
||||
|
||||
CheckoutPage.loadData = loadData;
|
||||
|
||||
export default CheckoutPage;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { types } from '../../util/sdkLoader';
|
|||
import { NamedRedirect, PageLayout } from '../../components';
|
||||
import { EditListingForm } from '../../containers';
|
||||
import { getListingsById } from '../../ducks/sdk.duck';
|
||||
import { fetchCurrentUser } from '../../ducks/user.duck';
|
||||
import { createSlug } from '../../util/urlHelpers';
|
||||
import * as propTypes from '../../util/propTypes';
|
||||
import {
|
||||
|
|
@ -166,8 +165,4 @@ const EditListingPage = connect(mapStateToProps, mapDispatchToProps)(
|
|||
injectIntl(EditListingPageComponent)
|
||||
);
|
||||
|
||||
EditListingPage.loadData = () => {
|
||||
return fetchCurrentUser();
|
||||
};
|
||||
|
||||
export default EditListingPage;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { types } from '../../util/sdkLoader';
|
||||
import { addEntities } from '../../ducks/sdk.duck';
|
||||
import { fetchCurrentUser } from '../../ducks/user.duck';
|
||||
|
||||
// ================ Action types ================ //
|
||||
|
||||
|
|
@ -65,9 +64,6 @@ export const loadData = params =>
|
|||
dispatch => {
|
||||
const orderId = new types.UUID(params.id);
|
||||
|
||||
// Current user is needed to render Topbar
|
||||
dispatch(fetchCurrentUser());
|
||||
|
||||
// Order (i.e. transaction entity in API, but from buyers perspective) contains order details
|
||||
return dispatch(fetchOrder(orderId));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,8 +65,6 @@ const mapStateToProps = state => {
|
|||
|
||||
const OrderPage = connect(mapStateToProps)(injectIntl(OrderPageComponent));
|
||||
|
||||
OrderPage.loadData = params => {
|
||||
return loadData(params);
|
||||
};
|
||||
OrderPage.loadData = loadData;
|
||||
|
||||
export default OrderPage;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { types } from '../../util/sdkLoader';
|
||||
import { addEntities } from '../../ducks/sdk.duck';
|
||||
import { fetchCurrentUser } from '../../ducks/user.duck';
|
||||
|
||||
// Transition-to keys
|
||||
const TRANSITION_ACCEPT = 'transition/accept';
|
||||
|
|
@ -138,9 +137,6 @@ export const loadData = params =>
|
|||
dispatch => {
|
||||
const saleId = new types.UUID(params.id);
|
||||
|
||||
// Current user is needed to render Topbar
|
||||
dispatch(fetchCurrentUser());
|
||||
|
||||
// Sale (i.e. transaction entity in API, but from buyers perspective) contains sale details
|
||||
return dispatch(fetchSale(saleId));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -87,8 +87,6 @@ const mapDispatchToProps = dispatch => {
|
|||
|
||||
const SalePage = connect(mapStateToProps, mapDispatchToProps)(injectIntl(SalePageComponent));
|
||||
|
||||
SalePage.loadData = params => {
|
||||
return loadData(params);
|
||||
};
|
||||
SalePage.loadData = loadData;
|
||||
|
||||
export default SalePage;
|
||||
|
|
|
|||
|
|
@ -83,11 +83,10 @@ export const fetchCurrentUser = () =>
|
|||
.me()
|
||||
.then(response => {
|
||||
dispatch(usersMeSuccess(response.data.data));
|
||||
return response;
|
||||
})
|
||||
.catch(e => {
|
||||
// TODO: dispatch flash message
|
||||
dispatch(usersMeError(e));
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import {
|
|||
showMarketplace,
|
||||
showUsers,
|
||||
} from './ducks/sdk.duck';
|
||||
import { fetchCurrentUser } from './ducks/user.duck';
|
||||
import routeConfiguration from './routesConfiguration';
|
||||
|
||||
import './index.css';
|
||||
|
|
@ -41,6 +42,7 @@ const render = store => {
|
|||
const info = authInfoLoaded ? Promise.resolve({}) : store.dispatch(authInfo());
|
||||
info
|
||||
.then(() => {
|
||||
store.dispatch(fetchCurrentUser());
|
||||
ReactDOM.render(<ClientApp store={store} />, document.getElementById('root'));
|
||||
})
|
||||
.catch(e => {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,6 @@ const routesConfiguration = [
|
|||
name: 'CheckoutPage',
|
||||
setInitialValues: initialValues => CheckoutPage.setInitialValues(initialValues),
|
||||
component: props => <CheckoutPage {...props} />,
|
||||
loadData: (params, search) => CheckoutPage.loadData(params, search),
|
||||
},
|
||||
{
|
||||
auth: true,
|
||||
|
|
@ -91,7 +90,6 @@ const routesConfiguration = [
|
|||
exact: true,
|
||||
name: 'NewListingPage',
|
||||
component: props => <EditListingPage {...props} type={'new'} />,
|
||||
loadData: (params, search) => EditListingPage.loadData(params, search),
|
||||
},
|
||||
{
|
||||
auth: true,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue