2020-12-17 07:03:59 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { Link, useLocation } from "react-router-dom";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import StyledHeader from "components/designSystems/appsmith/StyledHeader";
|
2021-10-20 09:33:04 +00:00
|
|
|
import { ReactComponent as AppsmithLogo } from "assets/svg/appsmith_logo_primary.svg";
|
2020-12-17 07:03:59 +00:00
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import { User, ANONYMOUS_USERNAME } from "constants/userConstants";
|
|
|
|
|
import { AUTH_LOGIN_URL, APPLICATIONS_URL } from "constants/routes";
|
|
|
|
|
import Button from "components/editorComponents/Button";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import ProfileDropdown from "./ProfileDropdown";
|
|
|
|
|
import { flushErrorsAndRedirect, flushErrors } from "actions/errorActions";
|
|
|
|
|
import { getSafeCrash } from "selectors/errorSelectors";
|
|
|
|
|
|
|
|
|
|
const StyledPageHeader = styled(StyledHeader)`
|
2021-10-20 09:33:04 +00:00
|
|
|
background: ${Colors.ALABASTER_ALT};
|
2020-12-17 07:03:59 +00:00
|
|
|
height: 48px;
|
|
|
|
|
color: white;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
|
|
|
|
z-index: 10;
|
|
|
|
|
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.05);
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const HeaderSection = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
align-items: center;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledDropDownContainer = styled.div``;
|
|
|
|
|
|
2021-10-20 09:33:04 +00:00
|
|
|
const AppsmithLogoImg = styled(AppsmithLogo)`
|
2020-12-17 07:03:59 +00:00
|
|
|
max-width: 110px;
|
2021-10-20 09:33:04 +00:00
|
|
|
width: 110px;
|
2020-12-17 07:03:59 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
type ErrorPageHeaderProps = {
|
|
|
|
|
user?: User;
|
|
|
|
|
flushErrors?: any;
|
|
|
|
|
flushErrorsAndRedirect?: any;
|
|
|
|
|
safeCrash: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function ErrorPageHeader(props: ErrorPageHeaderProps) {
|
2021-05-13 08:35:39 +00:00
|
|
|
const { flushErrors, flushErrorsAndRedirect, safeCrash, user } = props;
|
2020-12-17 07:03:59 +00:00
|
|
|
const location = useLocation();
|
|
|
|
|
const queryParams = new URLSearchParams(location.search);
|
|
|
|
|
let loginUrl = AUTH_LOGIN_URL;
|
2021-05-18 05:52:54 +00:00
|
|
|
const redirectUrl = queryParams.get("redirectUrl");
|
|
|
|
|
if (redirectUrl != null) {
|
|
|
|
|
loginUrl += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
|
2020-12-17 07:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<StyledPageHeader>
|
|
|
|
|
<HeaderSection>
|
|
|
|
|
<Link
|
|
|
|
|
className="t--appsmith-logo"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (safeCrash) flushErrors();
|
|
|
|
|
}}
|
2021-04-28 10:28:39 +00:00
|
|
|
to={APPLICATIONS_URL}
|
2020-12-17 07:03:59 +00:00
|
|
|
>
|
2021-10-20 09:33:04 +00:00
|
|
|
<AppsmithLogoImg />
|
2020-12-17 07:03:59 +00:00
|
|
|
</Link>
|
|
|
|
|
</HeaderSection>
|
|
|
|
|
{user && (
|
|
|
|
|
<StyledDropDownContainer>
|
|
|
|
|
{user.username === ANONYMOUS_USERNAME ? (
|
|
|
|
|
<Button
|
|
|
|
|
filled
|
|
|
|
|
intent={"primary"}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
flushErrorsAndRedirect(loginUrl);
|
|
|
|
|
}}
|
2021-04-28 10:28:39 +00:00
|
|
|
size="small"
|
|
|
|
|
text="Sign In"
|
2020-12-17 07:03:59 +00:00
|
|
|
/>
|
|
|
|
|
) : (
|
2021-04-28 10:28:39 +00:00
|
|
|
<ProfileDropdown name={user.name} userName={user.username} />
|
2020-12-17 07:03:59 +00:00
|
|
|
)}
|
|
|
|
|
</StyledDropDownContainer>
|
|
|
|
|
)}
|
|
|
|
|
</StyledPageHeader>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2020-12-17 07:03:59 +00:00
|
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
|
|
|
user: getCurrentUser(state),
|
|
|
|
|
safeCrash: getSafeCrash(state),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
|
flushErrors,
|
|
|
|
|
flushErrorsAndRedirect,
|
|
|
|
|
})(ErrorPageHeader);
|