PromucFlow_constructor/app/client/src/pages/common/PageHeader.tsx

252 lines
6.8 KiB
TypeScript
Raw Normal View History

2022-03-03 10:56:53 +00:00
import React, { useState, useMemo, useEffect } from "react";
import { Link, useLocation } from "react-router-dom";
2022-03-03 10:56:53 +00:00
import { connect, useDispatch } from "react-redux";
import { getCurrentUser } from "selectors/usersSelectors";
2022-03-03 10:56:53 +00:00
import styled from "styled-components";
import StyledHeader from "components/designSystems/appsmith/StyledHeader";
import { ReactComponent as AppsmithLogo } from "assets/svg/appsmith_logo_primary.svg";
import { AppState } from "reducers";
import { User, ANONYMOUS_USERNAME } from "constants/userConstants";
2022-03-03 10:56:53 +00:00
import {
AUTH_LOGIN_URL,
APPLICATIONS_URL,
matchApplicationPath,
matchTemplatesPath,
TEMPLATES_URL,
TEMPLATES_ID_PATH,
matchTemplatesIdPath,
} from "constants/routes";
import history from "utils/history";
2022-03-03 10:56:53 +00:00
import Button from "components/editorComponents/Button";
import ProfileDropdown from "./ProfileDropdown";
2021-06-09 14:32:17 +00:00
import Bell from "notifications/Bell";
import { Colors } from "constants/Colors";
import { useIsMobileDevice } from "utils/hooks/useDeviceDetect";
import { ReactComponent as TwoLineHamburger } from "assets/icons/ads/two-line-hamburger.svg";
import MobileSideBar from "./MobileSidebar";
import { Indices } from "constants/Layers";
import Icon, { IconSize } from "components/ads/Icon";
2022-03-03 10:56:53 +00:00
import { TemplatesTabItem } from "pages/Templates/TemplatesTabItem";
import { getTemplateNotificationSeenAction } from "actions/templateActions";
import getFeatureFlags from "utils/featureFlags";
2021-06-09 14:32:17 +00:00
const StyledPageHeader = styled(StyledHeader)<{
hideShadow?: boolean;
isMobile?: boolean;
showSeparator?: boolean;
2022-03-03 10:56:53 +00:00
showingTabs: boolean;
}>`
2022-03-03 10:56:53 +00:00
box-shadow: 0px 1px 0px ${Colors.GALLERY_2};
justify-content: normal;
background: white;
2020-08-18 06:40:11 +00:00
height: 48px;
color: white;
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
position: fixed;
top: 0;
z-index: ${Indices.Layer9};
2022-03-03 10:56:53 +00:00
box-shadow: ${(props) => {
if (props.isMobile) {
return `0px 4px 4px rgba(0, 0, 0, 0.05)`;
}
if (props.hideShadow) {
// solid line
return `0px 1px 0px ${Colors.GALLERY_2}`;
} else {
return `0px 4px 4px rgba(0, 0, 0, 0.05)`;
}
}};
${(props) =>
props.showingTabs &&
!props.isMobile &&
`box-shadow: 0px 1px 0px ${Colors.GALLERY_2};`}
${({ isMobile }) =>
isMobile &&
`
padding: 0 12px;
padding-left: 10px;
2022-03-03 10:56:53 +00:00
`};
2020-08-18 06:40:11 +00:00
`;
const HeaderSection = styled.div`
display: flex;
2020-08-18 06:40:11 +00:00
align-items: center;
.t--appsmith-logo {
svg {
max-width: 110px;
width: 110px;
}
}
`;
const StyledDropDownContainer = styled.div``;
const StyledTwoLineHamburger = styled(TwoLineHamburger)`
fill: ${Colors.BLACK};
width: 22px;
height: 22px;
cursor: pointer;
`;
2022-03-03 10:56:53 +00:00
const Tabs = styled.div`
display: flex;
font-size: 16px;
line-height: 24px;
box-sizing: border-box;
margin-left: ${(props) => props.theme.spaces[16]}px;
height: 100%;
gap: ${(props) => `${props.theme.spaces[0]}px ${props.theme.spaces[12]}px`};
flex: 1;
padding-top: ${(props) => props.theme.spaces[1]}px;
`;
const TabName = styled.div<{ isSelected: boolean }>`
color: ${Colors.GRAY};
border-bottom: 2px solid transparent;
text-align: center;
display: flex;
align-items: center;
${(props) =>
props.isSelected &&
`border-bottom: 2px solid ${Colors.CRUSTA};
color: ${Colors.COD_GRAY};`}
cursor: pointer;
`;
type PageHeaderProps = {
user?: User;
hideShadow?: boolean;
showSeparator?: boolean;
};
export function PageHeader(props: PageHeaderProps) {
const { user } = props;
const location = useLocation();
2022-03-03 10:56:53 +00:00
const dispatch = useDispatch();
const queryParams = new URLSearchParams(location.search);
const isMobile = useIsMobileDevice();
const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState(false);
let loginUrl = AUTH_LOGIN_URL;
if (queryParams.has("redirectUrl")) {
loginUrl += `?redirectUrl
=${queryParams.get("redirectUrl")}`;
}
2022-03-03 10:56:53 +00:00
useEffect(() => {
dispatch(getTemplateNotificationSeenAction());
}, []);
const tabs = [
{
title: "Apps",
path: APPLICATIONS_URL,
matcher: matchApplicationPath,
},
{
title: "Templates",
path: TEMPLATES_URL,
matcher: matchTemplatesPath,
},
{
title: "Templates id",
path: TEMPLATES_ID_PATH,
matcher: matchTemplatesIdPath,
},
];
const showTabs = useMemo(() => {
return (
tabs.some((tab) => tab.matcher(location.pathname)) &&
getFeatureFlags().APP_TEMPLATE
);
}, [location.pathname]);
return (
<StyledPageHeader
hideShadow={props.hideShadow || false}
isMobile={isMobile}
showSeparator={props.showSeparator || false}
2022-03-03 10:56:53 +00:00
showingTabs={showTabs}
>
2020-08-18 06:40:11 +00:00
<HeaderSection>
<Link className="t--appsmith-logo" to={APPLICATIONS_URL}>
<AppsmithLogo />
</Link>
2020-08-18 06:40:11 +00:00
</HeaderSection>
2022-03-03 10:56:53 +00:00
<Tabs>
{showTabs && !isMobile && (
<>
<TabName
isSelected={matchApplicationPath(location.pathname)}
onClick={() => history.push(APPLICATIONS_URL)}
>
<div>Apps</div>
</TabName>
<TemplatesTabItem>
<TabName
className="t--templates-tab"
isSelected={
matchTemplatesPath(location.pathname) ||
matchTemplatesIdPath(location.pathname)
}
onClick={() => history.push(TEMPLATES_URL)}
>
<div>Templates</div>
</TabName>
</TemplatesTabItem>
</>
)}
</Tabs>
{user && !isMobile && (
2021-06-09 14:32:17 +00:00
<>
{user.username !== ANONYMOUS_USERNAME && <Bell />}
2021-06-09 14:32:17 +00:00
<StyledDropDownContainer>
{user.username === ANONYMOUS_USERNAME ? (
<Button
filled
intent={"primary"}
onClick={() => history.push(loginUrl)}
size="small"
text="Sign In"
/>
) : (
<ProfileDropdown
name={user.name}
photoId={user?.photoId}
userName={user.username}
/>
2021-06-09 14:32:17 +00:00
)}
</StyledDropDownContainer>
</>
)}
{isMobile && !isMobileSidebarOpen && (
<StyledTwoLineHamburger onClick={() => setIsMobileSidebarOpen(true)} />
)}
{isMobile && isMobileSidebarOpen && (
<Icon
fillColor={Colors.CRUSTA}
name="close-x"
onClick={() => setIsMobileSidebarOpen(false)}
size={IconSize.XXXXL}
/>
)}
{isMobile && user && (
<MobileSideBar
isOpen={isMobileSidebarOpen}
name={user.name}
userName={user.username}
/>
)}
</StyledPageHeader>
);
}
const mapStateToProps = (state: AppState) => ({
user: getCurrentUser(state),
hideShadow: state.ui.theme.hideHeaderShadow,
showSeparator: state.ui.theme.showHeaderSeparator,
});
export default connect(mapStateToProps)(PageHeader);