2019-12-23 12:16:33 +00:00
|
|
|
import React from "react";
|
2020-08-03 14:18:48 +00:00
|
|
|
import { Link, useLocation } 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 { AUTH_LOGIN_URL, APPLICATIONS_URL } from "constants/routes";
|
|
|
|
|
import Button from "components/editorComponents/Button";
|
2020-08-03 14:18:48 +00:00
|
|
|
import history from "utils/history";
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const PageHeader = (props: PageHeaderProps) => {
|
2020-08-03 14:18:48 +00:00
|
|
|
const { user } = props;
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const queryParams = new URLSearchParams(location.search);
|
|
|
|
|
let loginUrl = AUTH_LOGIN_URL;
|
|
|
|
|
if (queryParams.has("redirectTo")) {
|
|
|
|
|
loginUrl += `?redirectTo=${queryParams.get("redirectTo")}`;
|
|
|
|
|
}
|
2020-07-08 10:14:03 +00:00
|
|
|
|
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>
|
2020-08-03 14:18:48 +00:00
|
|
|
{user && (
|
|
|
|
|
<StyledDropDownContainer>
|
|
|
|
|
{user.username === ANONYMOUS_USERNAME ? (
|
|
|
|
|
<Button
|
|
|
|
|
filled
|
|
|
|
|
text="Sign In"
|
|
|
|
|
intent={"primary"}
|
|
|
|
|
size="small"
|
|
|
|
|
onClick={() => history.push(loginUrl)}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<CustomizedDropdown {...DropdownProps(user, user.username)} />
|
|
|
|
|
)}
|
|
|
|
|
</StyledDropDownContainer>
|
|
|
|
|
)}
|
2019-12-23 12:16:33 +00:00
|
|
|
</StyledPageHeader>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
|
|
|
user: getCurrentUser(state),
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-03 14:18:48 +00:00
|
|
|
export default connect(mapStateToProps)(PageHeader);
|