PromucFlow_constructor/app/client/src/LandingScreen.tsx
Satish Gandham 7f7f6f666b
Development: Add eslint rules for code consistency (#4083)
Co-authored-by: Satish Gandham <satish@appsmith.com>
Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2021-04-28 15:58:39 +05:30

36 lines
1.1 KiB
TypeScript
Executable File

import React from "react";
import { AppState } from "reducers";
import { getCurrentUser, getUserAuthError } from "selectors/usersSelectors";
import { connect } from "react-redux";
import { ANONYMOUS_USERNAME, User } from "constants/userConstants";
import { Redirect } from "react-router";
import { APPLICATIONS_URL, AUTH_LOGIN_URL, BASE_URL } from "constants/routes";
import PageLoadingBar from "pages/common/PageLoadingBar";
import ServerUnavailable from "pages/common/ServerUnavailable";
type Props = {
user?: User;
authError: string;
};
function LandingScreen(props: Props) {
if (props.user && window.location.pathname === BASE_URL) {
if (props.user.email === ANONYMOUS_USERNAME) {
return <Redirect to={AUTH_LOGIN_URL} />;
} else {
return <Redirect to={APPLICATIONS_URL} />;
}
}
if (props.authError && props.authError.length) {
return <ServerUnavailable />;
}
return <PageLoadingBar />;
}
const mapStateToProps = (state: AppState) => ({
user: getCurrentUser(state),
authError: getUserAuthError(state),
});
export default connect(mapStateToProps)(LandingScreen);