2019-12-23 12:16:33 +00:00
|
|
|
import React from "react";
|
2020-07-08 10:14:03 +00:00
|
|
|
import { useHistory, Link } from "react-router-dom";
|
2019-12-23 12:16:33 +00:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import StyledHeader from "components/designSystems/appsmith/StyledHeader";
|
|
|
|
|
import CustomizedDropdown from "./CustomizedDropdown";
|
2020-06-17 10:19:56 +00:00
|
|
|
import DropdownProps from "./CustomizedDropdown/HeaderDropdownData";
|
2019-12-23 12:16:33 +00:00
|
|
|
import { AppState } from "reducers";
|
2020-07-08 10:14:03 +00:00
|
|
|
import { User, ANONYMOUS_USERNAME } from "constants/userConstants";
|
2020-06-17 10:19:56 +00:00
|
|
|
import Logo from "assets/images/appsmith_logo.png";
|
2020-07-08 10:14:03 +00:00
|
|
|
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { AUTH_LOGIN_URL, APPLICATIONS_URL } from "constants/routes";
|
|
|
|
|
import Button from "components/editorComponents/Button";
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
const StyledPageHeader = styled(StyledHeader)`
|
2020-06-17 10:19:56 +00:00
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
2019-12-23 12:16:33 +00:00
|
|
|
justify-content: space-between;
|
2020-06-17 10:19:56 +00:00
|
|
|
padding: ${props => props.theme.spaces[4]}px
|
|
|
|
|
${props => props.theme.spaces[4]}px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledDropDownContainer = styled.div``;
|
|
|
|
|
|
|
|
|
|
const LogoContainer = styled.div`
|
|
|
|
|
.logoimg {
|
|
|
|
|
width: 15%;
|
|
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
type PageHeaderProps = {
|
|
|
|
|
user?: User;
|
2020-07-08 10:14:03 +00:00
|
|
|
fetchCurrentUser: () => void;
|
2019-12-23 12:16:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const PageHeader = (props: PageHeaderProps) => {
|
2020-07-08 10:14:03 +00:00
|
|
|
const { user, fetchCurrentUser } = props;
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchCurrentUser();
|
|
|
|
|
}, [fetchCurrentUser]);
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
|
|
|
|
<StyledPageHeader>
|
2020-06-17 10:19:56 +00:00
|
|
|
<LogoContainer>
|
2020-07-08 10:14:03 +00:00
|
|
|
<Link to={APPLICATIONS_URL}>
|
2020-06-17 13:53:01 +00:00
|
|
|
<img className="logoimg" src={Logo} alt="Appsmith Logo" />
|
2020-07-08 10:14:03 +00:00
|
|
|
</Link>
|
2020-06-17 10:19:56 +00:00
|
|
|
</LogoContainer>
|
|
|
|
|
<StyledDropDownContainer>
|
2020-07-08 10:14:03 +00:00
|
|
|
{user && user.username !== ANONYMOUS_USERNAME ? (
|
|
|
|
|
<CustomizedDropdown {...DropdownProps(user, user.username)} />
|
|
|
|
|
) : (
|
|
|
|
|
<Button
|
|
|
|
|
filled
|
|
|
|
|
text="Sign In"
|
|
|
|
|
intent={"primary"}
|
|
|
|
|
size="small"
|
|
|
|
|
onClick={() => history.push(AUTH_LOGIN_URL)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-06-17 10:19:56 +00:00
|
|
|
</StyledDropDownContainer>
|
2019-12-23 12:16:33 +00:00
|
|
|
</StyledPageHeader>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
|
|
|
user: getCurrentUser(state),
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-08 10:14:03 +00:00
|
|
|
const mapDispatchToProps = (dispatch: any) => ({
|
|
|
|
|
fetchCurrentUser: () => dispatch({ type: ReduxActionTypes.FETCH_USER_INIT }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(PageHeader);
|