2020-12-17 07:03:59 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { Link, useLocation } from "react-router-dom";
|
2022-12-09 14:43:47 +00:00
|
|
|
import { connect, useSelector } from "react-redux";
|
2020-12-17 07:03:59 +00:00
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import StyledHeader from "components/designSystems/appsmith/StyledHeader";
|
2022-08-24 12:16:32 +00:00
|
|
|
import { AppState } from "@appsmith/reducers";
|
2020-12-17 07:03:59 +00:00
|
|
|
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";
|
2022-12-09 14:43:47 +00:00
|
|
|
import { Indices } from "constants/Layers";
|
|
|
|
|
import { getTenantConfig } from "@appsmith/selectors/tenantSelectors";
|
2020-12-17 07:03:59 +00:00
|
|
|
|
|
|
|
|
const StyledPageHeader = styled(StyledHeader)`
|
2022-12-09 14:43:47 +00:00
|
|
|
box-shadow: none;
|
|
|
|
|
justify-content: normal;
|
|
|
|
|
background: white;
|
2020-12-17 07:03:59 +00:00
|
|
|
height: 48px;
|
|
|
|
|
color: white;
|
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
2022-12-09 14:43:47 +00:00
|
|
|
z-index: ${Indices.Layer9};
|
|
|
|
|
box-shadow: 0px 1px 0px ${Colors.GALLERY_2};
|
2020-12-17 07:03:59 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const HeaderSection = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
align-items: center;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledDropDownContainer = styled.div``;
|
|
|
|
|
|
|
|
|
|
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();
|
2022-12-09 14:43:47 +00:00
|
|
|
const tenantConfig = useSelector(getTenantConfig);
|
2020-12-17 07:03:59 +00:00
|
|
|
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>
|
2022-12-09 14:43:47 +00:00
|
|
|
{tenantConfig.brandLogoUrl && (
|
|
|
|
|
<Link
|
|
|
|
|
className="t--appsmith-logo"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (safeCrash) flushErrors();
|
|
|
|
|
}}
|
|
|
|
|
to={APPLICATIONS_URL}
|
|
|
|
|
>
|
|
|
|
|
<img alt="Logo" className="h-6" src={tenantConfig.brandLogoUrl} />
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
2020-12-17 07:03:59 +00:00
|
|
|
</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-12-02 05:56:41 +00:00
|
|
|
<ProfileDropdown
|
|
|
|
|
name={user.name}
|
|
|
|
|
photoId={user?.photoId}
|
|
|
|
|
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);
|