Header.js
217 lines
| 1 | /** |
| 2 | * External Dependencies |
| 3 | */ |
| 4 | import { |
| 5 | Box, |
| 6 | Button, |
| 7 | Container, |
| 8 | Drawer, |
| 9 | DrawerBody, |
| 10 | DrawerCloseButton, |
| 11 | DrawerContent, |
| 12 | DrawerHeader, |
| 13 | DrawerOverlay, |
| 14 | Image, |
| 15 | Link, |
| 16 | Stack, |
| 17 | Tag, |
| 18 | Text, |
| 19 | useDisclosure, |
| 20 | Divider, |
| 21 | Center, |
| 22 | Tooltip, |
| 23 | } from "@chakra-ui/react"; |
| 24 | import { __ } from "@wordpress/i18n"; |
| 25 | import React, { useEffect, useRef } from "react"; |
| 26 | import { NavLink } from "react-router-dom"; |
| 27 | |
| 28 | /** |
| 29 | * Internal Dependencies |
| 30 | */ |
| 31 | import ROUTES from "../../Constants"; |
| 32 | import announcement from "../../images/announcement.gif"; |
| 33 | import { EVF, ExternalLink } from "../Icon/Icon"; |
| 34 | import IntersectObserver from "../IntersectionObserver/IntersectionObserver"; |
| 35 | import Changelog from "../Changelog/Changelog"; |
| 36 | |
| 37 | const Header = () => { |
| 38 | const { isOpen, onOpen, onClose } = useDisclosure(); |
| 39 | const ref = useRef(); |
| 40 | |
| 41 | /* global _UR_DASHBOARD_ */ |
| 42 | const { version, isPro, upgradeURL } = |
| 43 | typeof _EVF_DASHBOARD_ !== "undefined" && _EVF_DASHBOARD_; |
| 44 | useEffect(() => { |
| 45 | if (isOpen) { |
| 46 | document.body.classList.add("ur-modal-open"); |
| 47 | } else { |
| 48 | document.body.classList.remove("ur-modal-open"); |
| 49 | } |
| 50 | return () => { |
| 51 | document.body.classList.remove("ur-modal-open"); |
| 52 | }; |
| 53 | }, [isOpen]); |
| 54 | |
| 55 | return ( |
| 56 | <> |
| 57 | <Box |
| 58 | position={{ |
| 59 | sm: "sticky", |
| 60 | }} |
| 61 | top="var(--wp-admin--admin-bar--height, 0)" |
| 62 | bg={"white"} |
| 63 | zIndex={1} |
| 64 | borderBottom="1px solid #E9E9E9" |
| 65 | width="100%" |
| 66 | > |
| 67 | <Container maxW="container.xl"> |
| 68 | <Stack |
| 69 | direction="row" |
| 70 | minH="70px" |
| 71 | justify="space-between" |
| 72 | px="6" |
| 73 | > |
| 74 | <Stack direction="row" align="center" gap="7"> |
| 75 | <Link as={NavLink} to="/dashboard"> |
| 76 | <EVF h="10" w="10" /> |
| 77 | </Link> |
| 78 | <IntersectObserver routes={ROUTES}> |
| 79 | {ROUTES.map(({ route, label }) => ( |
| 80 | <Link |
| 81 | data-target={route} |
| 82 | key={route} |
| 83 | as={NavLink} |
| 84 | to={route} |
| 85 | fontSize="sm" |
| 86 | fontWeight="semibold" |
| 87 | lineHeight="150%" |
| 88 | color="#383838" |
| 89 | _hover={{ |
| 90 | color: "primary.500", |
| 91 | }} |
| 92 | _focus={{ |
| 93 | boxShadow: "none", |
| 94 | }} |
| 95 | _activeLink={{ |
| 96 | color: "primary.500", |
| 97 | borderBottom: "3px solid", |
| 98 | borderColor: "primary.500", |
| 99 | marginBottom: "-2px", |
| 100 | }} |
| 101 | display="inline-flex" |
| 102 | alignItems="center" |
| 103 | px="2" |
| 104 | h="full" |
| 105 | > |
| 106 | {label} |
| 107 | {route === "/settings" && ( |
| 108 | <ExternalLink |
| 109 | h="4" |
| 110 | w="4" |
| 111 | marginLeft="4px" |
| 112 | marginBottom="3px" |
| 113 | /> |
| 114 | )} |
| 115 | </Link> |
| 116 | ))} |
| 117 | </IntersectObserver> |
| 118 | </Stack> |
| 119 | <Stack direction="row" align="center" spacing="12px"> |
| 120 | <Tooltip |
| 121 | label={sprintf( |
| 122 | __( |
| 123 | "You are currently using Everest Forms %s", |
| 124 | "everest-forms" |
| 125 | ), |
| 126 | (isPro && "Pro ") + "v" + version |
| 127 | )} |
| 128 | > |
| 129 | <Tag |
| 130 | variant="outline" |
| 131 | colorScheme="primary" |
| 132 | borderRadius="xl" |
| 133 | bgColor="#F8FAFF" |
| 134 | fontSize="xs" |
| 135 | > |
| 136 | {"v" + version} |
| 137 | </Tag> |
| 138 | </Tooltip> |
| 139 | <Center height="18px"> |
| 140 | <Divider orientation="vertical" /> |
| 141 | </Center> |
| 142 | {!isPro && ( |
| 143 | <Link |
| 144 | color="#2563EB" |
| 145 | fontSize="12px" |
| 146 | height="18px" |
| 147 | w="85px" |
| 148 | href={ |
| 149 | upgradeURL + |
| 150 | "&utm_source=dashboard-header&utm_medium=top-menu-link" |
| 151 | } |
| 152 | isExternal |
| 153 | > |
| 154 | {__("Upgrade To Pro", "everest-forms")} |
| 155 | </Link> |
| 156 | )} |
| 157 | <Button |
| 158 | onClick={onOpen} |
| 159 | variant="unstyled" |
| 160 | borderRadius="full" |
| 161 | border="2px" |
| 162 | borderColor="gray.200" |
| 163 | w="40px" |
| 164 | h="40px" |
| 165 | position="relative" |
| 166 | > |
| 167 | <Tooltip |
| 168 | label={__( |
| 169 | "Latest Updates", |
| 170 | "everest-forms" |
| 171 | )} |
| 172 | > |
| 173 | <Image |
| 174 | src={announcement} |
| 175 | alt="announcement" |
| 176 | h="35px" |
| 177 | w="35px" |
| 178 | position="absolute" |
| 179 | top="50%" |
| 180 | left="50%" |
| 181 | transform="translate(-40%, -50%)" |
| 182 | /> |
| 183 | </Tooltip> |
| 184 | </Button> |
| 185 | </Stack> |
| 186 | </Stack> |
| 187 | </Container> |
| 188 | </Box> |
| 189 | <Drawer |
| 190 | isOpen={isOpen} |
| 191 | placement="right" |
| 192 | onClose={onClose} |
| 193 | finalFocusRef={ref} |
| 194 | > |
| 195 | <DrawerOverlay |
| 196 | bgColor="rgb(0,0,0,0.05)" |
| 197 | sx={{ backdropFilter: "blur(1px)" }} |
| 198 | /> |
| 199 | <DrawerContent |
| 200 | className="everest-forms-announcement" |
| 201 | top="var(--wp-admin--admin-bar--height, 0) !important" |
| 202 | > |
| 203 | <DrawerCloseButton /> |
| 204 | <DrawerHeader> |
| 205 | {__("Latest Updates", "everest-forms")} |
| 206 | </DrawerHeader> |
| 207 | <DrawerBody> |
| 208 | <Changelog /> |
| 209 | </DrawerBody> |
| 210 | </DrawerContent> |
| 211 | </Drawer> |
| 212 | </> |
| 213 | ); |
| 214 | }; |
| 215 | |
| 216 | export default Header; |
| 217 |