import { connect } from 'react-redux';
import * as PropTypes from 'prop-types';
import GlobalLoading from './GlobalLoading';
+import { CurrentUser } from '../types';
import { fetchCurrentUser } from '../../store/users/actions';
import { fetchLanguages, fetchAppState } from '../../store/rootActions';
import { fetchMyOrganizations } from '../../apps/account/organizations/actions';
interface Props {
children: JSX.Element;
fetchAppState: () => Promise<any>;
- fetchCurrentUser: () => Promise<void>;
+ fetchCurrentUser: () => Promise<CurrentUser>;
fetchLanguages: () => Promise<void>;
fetchMyOrganizations: () => Promise<void>;
}
componentDidMount() {
this.mounted = true;
- this.props
- .fetchCurrentUser()
- .then(() => Promise.all([this.fetchAppState(), this.props.fetchLanguages()]))
- .then(
- ([appState]) => {
- if (this.mounted) {
- if (appState.organizationsEnabled) {
- this.props.fetchMyOrganizations();
+ this.props.fetchCurrentUser().then(
+ currentUser => {
+ Promise.all([this.fetchAppState(), this.props.fetchLanguages()]).then(
+ ([appState]) => {
+ if (this.mounted) {
+ if (appState.organizationsEnabled && currentUser.isLoggedIn) {
+ this.props.fetchMyOrganizations();
+ }
+ this.setState({ loading: false });
}
- this.setState({ loading: false });
- }
- },
- () => {}
- );
+ },
+ () => {}
+ );
+ },
+ () => {}
+ );
}
componentWillUnmount() {
import { getHomePageUrl } from '../../helpers/urls';
interface Props {
- currentUser: CurrentUser;
+ currentUser: CurrentUser | undefined;
onSonarCloud: boolean;
}
componentDidMount() {
const { currentUser, onSonarCloud } = this.props;
- if (isLoggedIn(currentUser)) {
+ if (currentUser && isLoggedIn(currentUser)) {
if (currentUser.homepage) {
const homepage = getHomePageUrl(currentUser.homepage);
this.context.router.replace(homepage);
export const skipOnboarding = () => ({ type: SKIP_ONBOARDING });
export const fetchCurrentUser = () => (dispatch: Dispatch<any>) => {
- return api.getCurrentUser().then(user => dispatch(receiveCurrentUser(user)));
+ return api.getCurrentUser().then(user => {
+ dispatch(receiveCurrentUser(user));
+ return user;
+ });
};
export const setHomePage = (homepage: HomePage) => (dispatch: Dispatch<any>) => {