| import React from "react"; | |||||
| import PropTypes from "prop-types"; | |||||
| import { LogoutButtonContainer, LogoutIcon } from "./LogoutButton.styled"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| import { useDispatch } from "react-redux"; | |||||
| import { logoutAdmin } from "../../../../store/actions/login/loginActions"; | |||||
| const LogoutButton = () => { | |||||
| const { t } = useTranslation(); | |||||
| const dispatch = useDispatch(); | |||||
| const logoutHandler = () => { | |||||
| dispatch(logoutAdmin()); | |||||
| }; | |||||
| return ( | |||||
| <LogoutButtonContainer onClick={logoutHandler}> | |||||
| <LogoutIcon /> {t("admin.navigation.logout")} | |||||
| </LogoutButtonContainer> | |||||
| ); | |||||
| }; | |||||
| LogoutButton.propTypes = { | |||||
| children: PropTypes.node, | |||||
| }; | |||||
| export default LogoutButton; |
| import { Box } from "@mui/material"; | |||||
| import styled from "styled-components"; | |||||
| import { ReactComponent as Logout } from "../../../../assets/images/svg/log-out.svg"; | |||||
| import selectedTheme from "../../../../themes"; | |||||
| export const LogoutButtonContainer = styled(Box)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| padding-top: 1.7vh; | |||||
| padding-bottom: 1.7vh; | |||||
| padding-left: 18px; | |||||
| margin-bottom: 18px; | |||||
| margin-left: 18px; | |||||
| border-radius: 4px; | |||||
| border-top-right-radius: 0; | |||||
| border-bottom-right-radius: 0; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| cursor: pointer; | |||||
| &:hover { | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| } | |||||
| `; | |||||
| export const LogoutIcon = styled(Logout)` | |||||
| position: relative; | |||||
| top: 3px; | |||||
| `; |
| import React from "react"; | |||||
| import PropTypes from "prop-types"; | |||||
| import { HOME_PAGE } from "../../../../constants/pages"; | |||||
| import { | |||||
| ArrowUpRightIcon, | |||||
| MarketplaceButtonContainer, | |||||
| MarketplaceIcon, | |||||
| } from "./MarketplaceButton.styled"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| const MarketplaceButton = () => { | |||||
| const { t } = useTranslation(); | |||||
| const handleButtonClick = () => { | |||||
| history.push({ | |||||
| pathname: HOME_PAGE, | |||||
| }); | |||||
| }; | |||||
| return ( | |||||
| <MarketplaceButtonContainer onClick={handleButtonClick}> | |||||
| <MarketplaceIcon /> {t("admin.navigation.marketplace")} | |||||
| <ArrowUpRightIcon /> | |||||
| </MarketplaceButtonContainer> | |||||
| ); | |||||
| }; | |||||
| MarketplaceButton.propTypes = { | |||||
| children: PropTypes.node, | |||||
| }; | |||||
| export default MarketplaceButton; |
| import { Box } from "@mui/material"; | |||||
| import styled from "styled-components"; | |||||
| import { ReactComponent as ArrowUpRight } from "../../../../assets/images/svg/arrow-up-right-from-square.svg"; | |||||
| import { ReactComponent as Marketplace } from "../../../../assets/images/svg/package.svg"; | |||||
| import selectedTheme from "../../../../themes"; | |||||
| export const MarketplaceButtonContainer = styled(Box)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| padding-top: 1.7vh; | |||||
| padding-bottom: 1.7vh; | |||||
| padding-left: 18px; | |||||
| margin-top: 8vh; | |||||
| margin-left: 18px; | |||||
| border-radius: 4px; | |||||
| border-top-right-radius: 0; | |||||
| border-bottom-right-radius: 0; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| cursor: pointer; | |||||
| &:hover { | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| } | |||||
| `; | |||||
| export const MarketplaceIcon = styled(Marketplace)` | |||||
| position: relative; | |||||
| top: 3px; | |||||
| width: 18px; | |||||
| height: 18px; | |||||
| `; | |||||
| export const ArrowUpRightIcon = styled(ArrowUpRight)` | |||||
| position: relative; | |||||
| left: 4px; | |||||
| `; |
| import { | import { | ||||
| SidebarContainer, | SidebarContainer, | ||||
| SidebarContent, | SidebarContent, | ||||
| SidebarHeader, | |||||
| SidebarProfileImageContainer, | |||||
| SidebarProfileImage, | |||||
| SidebarProfileName, | |||||
| SidebarNavigation, | |||||
| SidebarNavigationMeni, | |||||
| SidebarNavigationMeniItemUl, | |||||
| SidebarNavigationMeniItem, | |||||
| SidebarNavigationMeniItemIcon, | |||||
| SidebarProfileRole, | |||||
| SidebarNavigationMeniLogout, | |||||
| LogoutIcon, | |||||
| SidebarNavigationMeniMarketplace, | |||||
| MarketplaceIcon, | |||||
| ButtonsContainer, | ButtonsContainer, | ||||
| ArrowUpRightIcon, | |||||
| } from "./Sidebar.styled"; | } from "./Sidebar.styled"; | ||||
| import { ReactComponent as LogoHorizontal } from "../../../assets/images/svg/logo-horizontal.svg"; | |||||
| import { useHistory } from "react-router-dom"; | |||||
| import { useSelector } from "react-redux"; | |||||
| import { selectMineProfile } from "../../../store/selectors/profileSelectors"; | |||||
| import { getImageUrl, variants } from "../../../util/helpers/imageUrlGetter"; | |||||
| import useIsMobile from "../../../hooks/useIsMobile"; | |||||
| import { ADMIN_NAVIGATION } from "../../../constants/adminNavigation"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| import { useDispatch } from "react-redux"; | |||||
| import { logoutAdmin } from "../../../store/actions/login/loginActions"; | |||||
| import { isInRoute, routeMatches } from "../../../util/helpers/routeHelpers"; | |||||
| import { | |||||
| ADMIN_HOME_PAGE, | |||||
| ADMIN_USERS_PAGE, | |||||
| HOME_PAGE, | |||||
| } from "../../../constants/pages"; | |||||
| import SidebarHeader from "./SidebarHeader/SidebarHeader"; | |||||
| import SidebarProfile from "./SidebarProfile/SidebarProfile"; | |||||
| import SidebarNavigation from "./SidebarNavigation/SidebarNavigation"; | |||||
| import MarketplaceButton from "./MarketplaceButton/MarketplaceButton"; | |||||
| import LogoutButton from "./LogoutButton/LogoutButton"; | |||||
| const Sidebar = () => { | const Sidebar = () => { | ||||
| const history = useHistory(); | |||||
| const profile = useSelector(selectMineProfile); | |||||
| const dispatch = useDispatch(); | |||||
| const { isMobile } = useIsMobile(); | |||||
| const { t } = useTranslation(); | |||||
| const routeToItem = (route) => { | |||||
| history.push(route); | |||||
| }; | |||||
| const marketplaceHandler = () => { | |||||
| history.push({ | |||||
| pathname: HOME_PAGE, | |||||
| }); | |||||
| }; | |||||
| const logoutHandler = () => { | |||||
| dispatch(logoutAdmin()); | |||||
| }; | |||||
| return ( | return ( | ||||
| <SidebarContainer> | <SidebarContainer> | ||||
| <SidebarHeader> | |||||
| <LogoHorizontal /> | |||||
| </SidebarHeader> | |||||
| <SidebarHeader /> | |||||
| <SidebarContent> | <SidebarContent> | ||||
| <SidebarProfileImageContainer> | |||||
| <SidebarProfileImage | |||||
| src={getImageUrl(profile.image, variants.profileImage, isMobile)} | |||||
| /> | |||||
| <SidebarProfileName>{profile.company.name}</SidebarProfileName> | |||||
| <SidebarProfileRole>{t("admin.navigation.role")}</SidebarProfileRole> | |||||
| </SidebarProfileImageContainer> | |||||
| <SidebarNavigation> | |||||
| <SidebarNavigationMeni> | |||||
| {t("admin.navigation.menu")} | |||||
| </SidebarNavigationMeni> | |||||
| <SidebarNavigationMeniItemUl> | |||||
| {ADMIN_NAVIGATION.map((value) => { | |||||
| let isRouteActive = isInRoute(value.route); | |||||
| if ( | |||||
| routeMatches(ADMIN_HOME_PAGE) && | |||||
| routeMatches(ADMIN_USERS_PAGE, value.route) | |||||
| ) | |||||
| isRouteActive = true; | |||||
| return ( | |||||
| <SidebarNavigationMeniItem | |||||
| active={isRouteActive} | |||||
| key={value.text} | |||||
| onClick={() => routeToItem(value.route)} | |||||
| > | |||||
| <SidebarNavigationMeniItemIcon active={isRouteActive}> | |||||
| {value.icon} | |||||
| </SidebarNavigationMeniItemIcon> | |||||
| {value.text} | |||||
| </SidebarNavigationMeniItem> | |||||
| ); | |||||
| })} | |||||
| </SidebarNavigationMeniItemUl> | |||||
| </SidebarNavigation> | |||||
| <SidebarProfile /> | |||||
| <SidebarNavigation /> | |||||
| <ButtonsContainer> | <ButtonsContainer> | ||||
| <SidebarNavigationMeniMarketplace onClick={marketplaceHandler}> | |||||
| <MarketplaceIcon /> {t("admin.navigation.marketplace")} | |||||
| <ArrowUpRightIcon /> | |||||
| </SidebarNavigationMeniMarketplace> | |||||
| <SidebarNavigationMeniLogout onClick={logoutHandler}> | |||||
| <LogoutIcon /> {t("admin.navigation.logout")} | |||||
| </SidebarNavigationMeniLogout> | |||||
| <MarketplaceButton /> | |||||
| <LogoutButton /> | |||||
| </ButtonsContainer> | </ButtonsContainer> | ||||
| </SidebarContent> | </SidebarContent> | ||||
| </SidebarContainer> | </SidebarContainer> |
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| import { Box, Typography } from "@mui/material"; | |||||
| import { ReactComponent as Marketplace } from "../../../assets/images/svg/package.svg"; | |||||
| import { ReactComponent as Logout } from "../../../assets/images/svg/log-out.svg"; | |||||
| import { ReactComponent as ArrowUpRight } from "../../../assets/images/svg/arrow-up-right-from-square.svg"; | |||||
| import selectedTheme from "../../../themes"; | |||||
| import { Box } from "@mui/material"; | |||||
| export const SidebarContainer = styled(Box)` | export const SidebarContainer = styled(Box)` | ||||
| margin-top: -30px; | margin-top: -30px; | ||||
| } | } | ||||
| `; | `; | ||||
| export const SidebarHeader = styled(Box)` | |||||
| background-color: #f5edff; | |||||
| padding-top: 3.3vh; | |||||
| padding-left: 36px; | |||||
| padding-bottom: 3.3vh; | |||||
| `; | |||||
| export const SidebarContent = styled(Box)` | export const SidebarContent = styled(Box)` | ||||
| display: flex; | display: flex; | ||||
| flex-direction: column; | flex-direction: column; | ||||
| justify-content: space-between; | justify-content: space-between; | ||||
| `; | `; | ||||
| export const SidebarProfileImageContainer = styled(Box)` | |||||
| display: flex; | |||||
| flex-direction: column; | |||||
| align-items: center; | |||||
| padding: 0; | |||||
| `; | |||||
| export const SidebarProfileImage = styled.img` | |||||
| width: 108px; | |||||
| height: 108px; | |||||
| border-radius: 100%; | |||||
| `; | |||||
| export const SidebarProfileName = styled(Typography)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| font-weight: 700; | |||||
| margin-top: 19px; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| `; | |||||
| export const SidebarProfileRole = styled(Typography)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 12px; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| `; | |||||
| export const SidebarNavigation = styled(Box)` | |||||
| margin-left: 18px; | |||||
| display: flex; | |||||
| flex-direction: column; | |||||
| /* flex: 1; */ | |||||
| `; | |||||
| export const SidebarNavigationMeni = styled(Typography)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 24px; | |||||
| font-weight: 700; | |||||
| margin-bottom: 4vh; | |||||
| margin-left: 18px; | |||||
| `; | |||||
| export const SidebarNavigationMeniItemUl = styled.ul``; | |||||
| export const SidebarNavigationMeniItem = styled.li` | |||||
| padding-top: 1.7vh; | |||||
| padding-bottom: 1.7vh; | |||||
| padding-left: 18px; | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| font-weight: 400; | |||||
| display: flex; | |||||
| border-radius: 4px; | |||||
| border-top-right-radius: 0; | |||||
| border-bottom-right-radius: 0; | |||||
| align-items: center; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| cursor: pointer; | |||||
| ${(props) => | |||||
| props.active && | |||||
| ` | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| `} | |||||
| path { | |||||
| stroke: #c4c4c4; | |||||
| } | |||||
| &:hover { | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| path { | |||||
| stroke: #feb005; | |||||
| } | |||||
| } | |||||
| `; | |||||
| export const SidebarNavigationMeniItemIcon = styled(Box)` | |||||
| margin-right: 9px; | |||||
| position: relative; | |||||
| top: 2px; | |||||
| ${(props) => | |||||
| props.active && | |||||
| ` | |||||
| path { | |||||
| stroke: #feb005; | |||||
| } | |||||
| `} | |||||
| `; | |||||
| export const ButtonsContainer = styled(Box)``; | export const ButtonsContainer = styled(Box)``; | ||||
| export const SidebarNavigationMeniMarketplace = styled(Box)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| padding-top: 1.7vh; | |||||
| padding-bottom: 1.7vh; | |||||
| padding-left: 18px; | |||||
| margin-top: 8vh; | |||||
| margin-left: 18px; | |||||
| border-radius: 4px; | |||||
| border-top-right-radius: 0; | |||||
| border-bottom-right-radius: 0; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| cursor: pointer; | |||||
| &:hover { | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| } | |||||
| `; | |||||
| export const MarketplaceIcon = styled(Marketplace)` | |||||
| position: relative; | |||||
| top: 5px; | |||||
| `; | |||||
| export const SidebarNavigationMeniLogout = styled(Box)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| padding-top: 1.7vh; | |||||
| padding-bottom: 1.7vh; | |||||
| padding-left: 18px; | |||||
| margin-bottom: 18px; | |||||
| margin-left: 18px; | |||||
| border-radius: 4px; | |||||
| border-top-right-radius: 0; | |||||
| border-bottom-right-radius: 0; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| cursor: pointer; | |||||
| &:hover { | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| } | |||||
| `; | |||||
| export const LogoutIcon = styled(Logout)` | |||||
| position: relative; | |||||
| top: 3px; | |||||
| `; | |||||
| export const ArrowUpRightIcon = styled(ArrowUpRight)` | |||||
| margin-left: 4px; | |||||
| `; |
| import React from "react"; | |||||
| import PropTypes from "prop-types"; | |||||
| import { | |||||
| LogoHorizontalIcon, | |||||
| SidebarHeaderContainer, | |||||
| } from "./SidebarHeader.styled"; | |||||
| import history from "../../../../store/utils/history"; | |||||
| import { ADMIN_HOME_PAGE } from "../../../../constants/pages"; | |||||
| const SidebarHeader = () => { | |||||
| const handleLogoClick = () => { | |||||
| history.push(ADMIN_HOME_PAGE); | |||||
| }; | |||||
| return ( | |||||
| <SidebarHeaderContainer> | |||||
| <LogoHorizontalIcon onClick={handleLogoClick} /> | |||||
| </SidebarHeaderContainer> | |||||
| ); | |||||
| }; | |||||
| SidebarHeader.propTypes = { | |||||
| children: PropTypes.node, | |||||
| }; | |||||
| export default SidebarHeader; |
| import { Box } from "@mui/material"; | |||||
| import { ReactComponent as LogoHorizontal } from "../../../../assets/images/svg/logo-horizontal.svg"; | |||||
| import styled from "styled-components"; | |||||
| export const SidebarHeaderContainer = styled(Box)` | |||||
| background-color: #f5edff; | |||||
| padding-top: 3.3vh; | |||||
| padding-left: 36px; | |||||
| padding-bottom: 3.3vh; | |||||
| `; | |||||
| export const LogoHorizontalIcon = styled(LogoHorizontal)` | |||||
| cursor: pointer; | |||||
| `; |
| import React from "react"; | |||||
| import PropTypes from "prop-types"; | |||||
| import { | |||||
| SidebarNavigationContainer, | |||||
| SidebarNavigationItem, | |||||
| SidebarNavigationItemIcon, | |||||
| SidebarNavigationListContainer, | |||||
| SidebarNavigationTitle, | |||||
| } from "./SidebarNavigation.styled"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| import { isInRoute, routeMatches } from "../../../../util/helpers/routeHelpers"; | |||||
| import { ADMIN_HOME_PAGE, ADMIN_USERS_PAGE } from "../../../../constants/pages"; | |||||
| import { ADMIN_NAVIGATION } from "../../../../constants/adminNavigation"; | |||||
| const SidebarNavigation = () => { | |||||
| const { t } = useTranslation(); | |||||
| const goToRoute = (route) => { | |||||
| history.push(route); | |||||
| }; | |||||
| return ( | |||||
| <SidebarNavigationContainer> | |||||
| <SidebarNavigationTitle> | |||||
| {t("admin.navigation.menu")} | |||||
| </SidebarNavigationTitle> | |||||
| <SidebarNavigationListContainer> | |||||
| {ADMIN_NAVIGATION.map((value) => { | |||||
| let isRouteActive = isInRoute(value.route); | |||||
| if ( | |||||
| routeMatches(ADMIN_HOME_PAGE) && | |||||
| routeMatches(ADMIN_USERS_PAGE, value.route) | |||||
| ) | |||||
| isRouteActive = true; | |||||
| return ( | |||||
| <SidebarNavigationItem | |||||
| active={isRouteActive} | |||||
| key={value.text} | |||||
| onClick={() => goToRoute(value.route)} | |||||
| > | |||||
| <SidebarNavigationItemIcon active={isRouteActive}> | |||||
| {value.icon} | |||||
| </SidebarNavigationItemIcon> | |||||
| {value.text} | |||||
| </SidebarNavigationItem> | |||||
| ); | |||||
| })} | |||||
| </SidebarNavigationListContainer> | |||||
| </SidebarNavigationContainer> | |||||
| ); | |||||
| }; | |||||
| SidebarNavigation.propTypes = { | |||||
| children: PropTypes.node, | |||||
| }; | |||||
| export default SidebarNavigation; |
| import { Box, Typography } from "@mui/material"; | |||||
| import styled from "styled-components"; | |||||
| import selectedTheme from "../../../../themes"; | |||||
| export const SidebarNavigationContainer = styled(Box)` | |||||
| margin-left: 18px; | |||||
| display: flex; | |||||
| flex-direction: column; | |||||
| /* flex: 1; */ | |||||
| `; | |||||
| export const SidebarNavigationTitle = styled(Typography)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 24px; | |||||
| font-weight: 700; | |||||
| margin-bottom: 4vh; | |||||
| margin-left: 18px; | |||||
| `; | |||||
| export const SidebarNavigationListContainer = styled.ul``; | |||||
| export const SidebarNavigationItem = styled.li` | |||||
| padding-top: 1.7vh; | |||||
| padding-bottom: 1.7vh; | |||||
| padding-left: 18px; | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| font-weight: 400; | |||||
| display: flex; | |||||
| border-radius: 4px; | |||||
| border-top-right-radius: 0; | |||||
| border-bottom-right-radius: 0; | |||||
| align-items: center; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| cursor: pointer; | |||||
| ${(props) => | |||||
| props.active && | |||||
| ` | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| `} | |||||
| path { | |||||
| stroke: #c4c4c4; | |||||
| } | |||||
| &:hover { | |||||
| background-color: #f5edff; | |||||
| font-weight: 700; | |||||
| path { | |||||
| stroke: #feb005; | |||||
| } | |||||
| } | |||||
| `; | |||||
| export const SidebarNavigationItemIcon = styled(Box)` | |||||
| margin-right: 9px; | |||||
| position: relative; | |||||
| top: 2px; | |||||
| ${(props) => | |||||
| props.active && | |||||
| ` | |||||
| path { | |||||
| stroke: #feb005; | |||||
| } | |||||
| `} | |||||
| `; |
| import React from "react"; | |||||
| import PropTypes from "prop-types"; | |||||
| import { | |||||
| SidebarProfileContainer, | |||||
| SidebarProfileImage, | |||||
| SidebarProfileName, | |||||
| SidebarProfileRole, | |||||
| } from "./SidebarProfile.styled"; | |||||
| import { getImageUrl, variants } from "../../../../util/helpers/imageUrlGetter"; | |||||
| import useIsMobile from "../../../../hooks/useIsMobile"; | |||||
| import { useTranslation } from "react-i18next"; | |||||
| import { useSelector } from "react-redux"; | |||||
| import { selectMineProfile } from "../../../../store/selectors/profileSelectors"; | |||||
| const SidebarProfile = () => { | |||||
| const { isMobile } = useIsMobile(); | |||||
| const profile = useSelector(selectMineProfile); | |||||
| const { t } = useTranslation(); | |||||
| return ( | |||||
| <SidebarProfileContainer> | |||||
| <SidebarProfileImage | |||||
| src={getImageUrl(profile.image, variants.profileImage, isMobile)} | |||||
| /> | |||||
| <SidebarProfileName>{profile.company.name}</SidebarProfileName> | |||||
| <SidebarProfileRole>{t("admin.navigation.role")}</SidebarProfileRole> | |||||
| </SidebarProfileContainer> | |||||
| ); | |||||
| }; | |||||
| SidebarProfile.propTypes = { | |||||
| profile: PropTypes.shape({ | |||||
| image: PropTypes.string, | |||||
| company: PropTypes.shape({ | |||||
| name: PropTypes.string, | |||||
| }), | |||||
| }), | |||||
| }; | |||||
| export default SidebarProfile; |
| import { Box, Typography } from "@mui/material"; | |||||
| import styled from "styled-components"; | |||||
| import selectedTheme from "../../../../themes"; | |||||
| export const SidebarProfileContainer = styled(Box)` | |||||
| display: flex; | |||||
| flex-direction: column; | |||||
| align-items: center; | |||||
| padding: 0; | |||||
| `; | |||||
| export const SidebarProfileImage = styled.img` | |||||
| width: 108px; | |||||
| height: 108px; | |||||
| border-radius: 100%; | |||||
| `; | |||||
| export const SidebarProfileName = styled(Typography)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 16px; | |||||
| font-weight: 700; | |||||
| margin-top: 19px; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| `; | |||||
| export const SidebarProfileRole = styled(Typography)` | |||||
| font-family: "DM Sans"; | |||||
| font-size: 12px; | |||||
| color: ${selectedTheme.colors.primaryPurple}; | |||||
| `; |
| } else | } else | ||||
| history.push( | history.push( | ||||
| replaceInRoute(PROFILE_PAGE, { | replaceInRoute(PROFILE_PAGE, { | ||||
| idProfile: userId, | |||||
| profileId: userId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| closeCreateOfferModal(); | closeCreateOfferModal(); |
| import { selectUserId } from "../../../store/selectors/loginSelectors"; | import { selectUserId } from "../../../store/selectors/loginSelectors"; | ||||
| import { formatDateLocale } from "../../../util/helpers/dateHelpers"; | import { formatDateLocale } from "../../../util/helpers/dateHelpers"; | ||||
| import { startChat } from "../../../util/helpers/chatHelper"; | import { startChat } from "../../../util/helpers/chatHelper"; | ||||
| import Information from "./Information/Information"; | |||||
| import Information from "./OfferInformations/SingleInformation/SingleInformation"; | |||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| import OfferDetails from "./OfferDetails/OfferDetails"; | import OfferDetails from "./OfferDetails/OfferDetails"; | ||||
| import { useRouteMatch } from "react-router-dom"; | import { useRouteMatch } from "react-router-dom"; | ||||
| const offer = useMemo(() => { | const offer = useMemo(() => { | ||||
| if (props.offer) { | if (props.offer) { | ||||
| if ( | if ( | ||||
| props.offer.offer._id === routeMatch.params.idProizvod || | |||||
| props.offer.offer._id === routeMatch.params?.offerId || | |||||
| props.createOffer | props.createOffer | ||||
| ) { | ) { | ||||
| return props.offer; | return props.offer; | ||||
| editOffer: true, | editOffer: true, | ||||
| offer: offer?.offer, | offer: offer?.offer, | ||||
| isAdmin: props.isAdmin, | isAdmin: props.isAdmin, | ||||
| customUserId: offer?.offer?.userId | |||||
| customUserId: offer?.offer?.userId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; |
| import React from "react"; | import React from "react"; | ||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import selectedTheme from "../../../../themes"; | |||||
| import { InfoGroup, InfoIcon, InfoText } from "./Information.styled"; | |||||
| import selectedTheme from "../../../../../themes"; | |||||
| import { InfoGroup, InfoIcon, InfoText } from "./SingleInformation.styled"; | |||||
| const Information = (props) => { | |||||
| const SingleInformation = (props) => { | |||||
| return ( | return ( | ||||
| <InfoGroup hide={props.hide}> | <InfoGroup hide={props.hide}> | ||||
| <InfoIcon | <InfoIcon | ||||
| color={selectedTheme.colors.iconStrokeColor} | color={selectedTheme.colors.iconStrokeColor} | ||||
| component="span" | component="span" | ||||
| size="16px" | |||||
| > | > | ||||
| {/* <CategoryIcon width={"14px"} /> */} | |||||
| {props.icon} | {props.icon} | ||||
| </InfoIcon> | </InfoIcon> | ||||
| {/* <InfoText>{offer?.offer?.category?.name}</InfoText> */} | |||||
| <InfoText>{props.value}</InfoText> | <InfoText>{props.value}</InfoText> | ||||
| </InfoGroup> | </InfoGroup> | ||||
| ); | ); | ||||
| }; | }; | ||||
| Information.propTypes = { | |||||
| SingleInformation.propTypes = { | |||||
| icon: PropTypes.node, | icon: PropTypes.node, | ||||
| value: PropTypes.string, | value: PropTypes.string, | ||||
| hide: PropTypes.bool, | hide: PropTypes.bool, | ||||
| }; | }; | ||||
| export default Information; | |||||
| export default SingleInformation; |
| import { Box, Typography } from "@mui/material"; | import { Box, Typography } from "@mui/material"; | ||||
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| import selectedTheme from "../../../../themes"; | |||||
| import selectedTheme from "../../../../../themes"; | |||||
| export const InfoGroup = styled(Box)` | export const InfoGroup = styled(Box)` | ||||
| display: ${props => props.hide ? 'none' : 'flex'}; | display: ${props => props.hide ? 'none' : 'flex'}; | ||||
| export const InfoIcon = styled(Box)` | export const InfoIcon = styled(Box)` | ||||
| display: flex; | display: flex; | ||||
| align-items: center; | align-items: center; | ||||
| width: 16px; | |||||
| height: 16px; | |||||
| `; | `; | ||||
| export const InfoText = styled(Typography)` | export const InfoText = styled(Typography)` | ||||
| font-family: ${selectedTheme.fonts.textFont}; | font-family: ${selectedTheme.fonts.textFont}; |
| const changeChat = () => { | const changeChat = () => { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(DIRECT_CHAT_PAGE, { | replaceInRoute(DIRECT_CHAT_PAGE, { | ||||
| idChat: props?.chat?.chat?._id, | |||||
| chatId: props?.chat?.chat?._id, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; |
| const routeToItem = (itemId) => { | const routeToItem = (itemId) => { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(ITEM_DETAILS_PAGE, { | replaceInRoute(ITEM_DETAILS_PAGE, { | ||||
| idProizvod: itemId, | |||||
| offerId: itemId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; |
| if (props.isAdmin) { | if (props.isAdmin) { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(ADMIN_ITEM_DETAILS_PAGE, { | replaceInRoute(ADMIN_ITEM_DETAILS_PAGE, { | ||||
| idProizvod: itemId, | |||||
| offerId: itemId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| } else { | } else { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(ITEM_DETAILS_PAGE, { | replaceInRoute(ITEM_DETAILS_PAGE, { | ||||
| idProizvod: itemId, | |||||
| offerId: itemId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| } | } |
| const goToUser = () => { | const goToUser = () => { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(ADMIN_SINGLE_USER_PAGE, { | replaceInRoute(ADMIN_SINGLE_USER_PAGE, { | ||||
| idProfile: props.profile?._id, | |||||
| profileId: props.profile?._id, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; |
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||
| const profileFromRedux = useSelector(selectProfile); | const profileFromRedux = useSelector(selectProfile); | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const idProfile = useMemo(() => { | |||||
| return routeMatch.params.idProfile; | |||||
| }, [routeMatch.params.idProfile]); | |||||
| const profileId = useMemo(() => { | |||||
| return routeMatch.params.profileId; | |||||
| }, [routeMatch.params.profileId]); | |||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const profile = useMemo(() => { | const profile = useMemo(() => { | ||||
| if (profileFromRedux) { | if (profileFromRedux) { | ||||
| if (profileFromRedux._id === routeMatch.params.idProfile) { | |||||
| if (profileFromRedux._id === routeMatch.params.profileId) { | |||||
| return profileFromRedux; | return profileFromRedux; | ||||
| } | } | ||||
| } | } | ||||
| }, [profileFromRedux]); | }, [profileFromRedux]); | ||||
| const isMyProfile = useMemo( | const isMyProfile = useMemo( | ||||
| () => userId === idProfile && !props.isAdmin, | |||||
| [userId, idProfile] | |||||
| () => userId === profileId && !props.isAdmin, | |||||
| [userId, profileId] | |||||
| ); | ); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (idProfile?.length > 0) { | |||||
| if (profileId?.length > 0) { | |||||
| reFetchProfile(); | reFetchProfile(); | ||||
| } | } | ||||
| }, [idProfile]); | |||||
| }, [profileId]); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| if (profile && isMyProfile !== undefined) { | if (profile && isMyProfile !== undefined) { | ||||
| if (!isMyProfile && profile._blocked && !props.isAdmin) | if (!isMyProfile && profile._blocked && !props.isAdmin) | ||||
| }, [profile, isMyProfile, props.isAdmin]); | }, [profile, isMyProfile, props.isAdmin]); | ||||
| const reFetchProfile = () => { | const reFetchProfile = () => { | ||||
| dispatch(fetchProfile(idProfile)); | |||||
| dispatch(fetchProfileOffers(idProfile)); | |||||
| dispatch(fetchProfile(profileId)); | |||||
| dispatch(fetchProfileOffers(profileId)); | |||||
| }; | }; | ||||
| let percentOfSucceededExchanges; | let percentOfSucceededExchanges; |
| if (isAdminRoute()) { | if (isAdminRoute()) { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(ADMIN_SINGLE_USER_PAGE, { | replaceInRoute(ADMIN_SINGLE_USER_PAGE, { | ||||
| idProfile: props.profile?._id, | |||||
| profileId: props.profile?._id, | |||||
| }) | }) | ||||
| ); | ); | ||||
| } | } |
| const exchange = useSelector(selectExchange); | const exchange = useSelector(selectExchange); | ||||
| const requester = useSelector(selectRequester); | const requester = useSelector(selectRequester); | ||||
| console.log(props); | |||||
| const handleAcceptExchange = () => { | const handleAcceptExchange = () => { | ||||
| acceptExchangeSocket( | acceptExchangeSocket( | ||||
| props.chatId, | props.chatId, |
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||
| const routeToUser = () => { | const routeToUser = () => { | ||||
| history.push(replaceInRoute(PROFILE_PAGE, { | history.push(replaceInRoute(PROFILE_PAGE, { | ||||
| idProfile: props.userId | |||||
| profileId: props.userId | |||||
| })) | })) | ||||
| } | } | ||||
| return ( | return ( |
| const handleRemove = () => { | const handleRemove = () => { | ||||
| props.handleRemove(); | props.handleRemove(); | ||||
| }; | }; | ||||
| console.log(props.review); | |||||
| return ( | return ( | ||||
| <ReviewContainer | <ReviewContainer | ||||
| lastReview={props.lastReview} | lastReview={props.lastReview} |
| // Fetch chat after it is created | // Fetch chat after it is created | ||||
| // (renders after state of location changes) | // (renders after state of location changes) | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (routeMatch.params.idChat) { | |||||
| if (routeMatch.params?.chatId) { | |||||
| refreshChat(); | refreshChat(); | ||||
| } | } | ||||
| }, [routeMatch.params.idChat, location.state?.offerId]); | |||||
| }, [routeMatch.params?.chatId, location.state?.offerId]); | |||||
| // Listener to socket.IO chat | // Listener to socket.IO chat | ||||
| useEffect(() => { | useEffect(() => { | ||||
| } | } | ||||
| } else { | } else { | ||||
| dispatch(fetchChats()); | dispatch(fetchChats()); | ||||
| dispatch(fetchOneChat(routeMatch.params.idChat)); | |||||
| dispatch(fetchOneChat(routeMatch.params?.chatId)); | |||||
| makeErrorToastMessage(t("apiErrors.somethingWentWrong")); | makeErrorToastMessage(t("apiErrors.somethingWentWrong")); | ||||
| } | } | ||||
| }); | }); | ||||
| return () => removeMessageListener(); | return () => removeMessageListener(); | ||||
| }, [allChats, routeMatch]); | }, [allChats, routeMatch]); | ||||
| const refreshChat = () => { | const refreshChat = () => { | ||||
| if (routeMatch.params.idChat === "newMessage") { | |||||
| if (routeMatch.params?.chatId === "newMessage") { | |||||
| dispatch(fetchOneOffer(location.state.offerId)); | dispatch(fetchOneOffer(location.state.offerId)); | ||||
| dispatch(setOneChat({})); | dispatch(setOneChat({})); | ||||
| } else { | } else { | ||||
| dispatch(fetchOneChat(routeMatch.params.idChat)); | |||||
| dispatch(fetchOneChat(routeMatch.params?.chatId)); | |||||
| } | } | ||||
| }; | }; | ||||
| const handleAcceptExchange = () => { | const handleAcceptExchange = () => { |
| if (!props?.interlucator?._blocked) | if (!props?.interlucator?._blocked) | ||||
| history.push( | history.push( | ||||
| replaceInRoute(PROFILE_PAGE, { | replaceInRoute(PROFILE_PAGE, { | ||||
| idProfile: props?.interlucator?.userId, | |||||
| profileId: props?.interlucator?.userId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }; | }; |
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const offer = useMemo(() => { | const offer = useMemo(() => { | ||||
| if (props.offer) { | if (props.offer) { | ||||
| if (props.offer.offer._id === routeMatch.params.idProizvod) { | |||||
| if (props.offer.offer._id === routeMatch.params.offerId) { | |||||
| return props.offer; | return props.offer; | ||||
| } | } | ||||
| } | } |
| } else closeModalHandler(); | } else closeModalHandler(); | ||||
| }; | }; | ||||
| const handleSubmit = (values) => { | const handleSubmit = (values) => { | ||||
| console.log(props); | |||||
| dispatch( | dispatch( | ||||
| fetchAdminMethod({ | fetchAdminMethod({ | ||||
| type: props.type, | type: props.type, |
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const routeMatch = useRouteMatch(); | const routeMatch = useRouteMatch(); | ||||
| const idProfile = useMemo(() => routeMatch.params?.idProfile, [routeMatch]); | |||||
| const profileId = useMemo(() => routeMatch.params?.profileId, [routeMatch]); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| if (idProfile?.length > 0) { | |||||
| dispatch(fetchProfile(idProfile)); | |||||
| if (profileId?.length > 0) { | |||||
| dispatch(fetchProfile(profileId)); | |||||
| } | } | ||||
| }, [idProfile]); | |||||
| }, [profileId]); | |||||
| const isMyProfile = useMemo(() => { | const isMyProfile = useMemo(() => { | ||||
| return userId === routeMatch.params.idProfile; | |||||
| return userId === routeMatch.params?.profileId; | |||||
| }, [userId, routeMatch]); | }, [userId, routeMatch]); | ||||
| return ( | return ( | ||||
| <ProfileContainer className={props.className}> | <ProfileContainer className={props.className}> | ||||
| <ProfileOffers | <ProfileOffers | ||||
| isAdmin={props.isAdmin} | isAdmin={props.isAdmin} | ||||
| isMyProfile={isMyProfile} | isMyProfile={isMyProfile} | ||||
| idProfile={idProfile} | |||||
| idProfile={profileId} | |||||
| /> | /> | ||||
| </ProfileContainer> | </ProfileContainer> | ||||
| ); | ); |
| onChange: props.onChange, | onChange: props.onChange, | ||||
| }; | }; | ||||
| console.log(suggestions); | |||||
| return ( | return ( | ||||
| <AutoSuggestTextFieldContainer | <AutoSuggestTextFieldContainer | ||||
| editLocation={props.editLocation} | editLocation={props.editLocation} |
| ) | ) | ||||
| ); | ); | ||||
| console.log("userr", props) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| let idProfile = routeMatch.params.idProfile; | |||||
| let idProfile = routeMatch.params?.profileId; | |||||
| if (idProfile) { | if (idProfile) { | ||||
| if (props.isAdmin) { | if (props.isAdmin) { | ||||
| dispatch(fetchReviewsAsAdmin(idProfile)); | dispatch(fetchReviewsAsAdmin(idProfile)); | ||||
| } | } | ||||
| } | } | ||||
| // if (props.profileReviews && routeMatch.params?.idProfile) { | |||||
| // let idProfile = routeMatch.params.idProfile; | |||||
| // if (props.profileReviews && routeMatch.params?.profileId) { | |||||
| // let idProfile = routeMatch.params?.profileId; | |||||
| // dispatch(fetchReviews(idProfile)); | // dispatch(fetchReviews(idProfile)); | ||||
| // } | // } | ||||
| }, [props.profileReviews, routeMatch]); | }, [props.profileReviews, routeMatch]); |
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const selectedOffer = useSelector(selectOffer); | const selectedOffer = useSelector(selectOffer); | ||||
| const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | ||||
| const offerId = props.match.params.idProizvod; | |||||
| const offerId = props.match.params?.offerId; | |||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchOneOffer(offerId)); | dispatch(fetchOneOffer(offerId)); | ||||
| AdminItemDetailsPage.propTypes = { | AdminItemDetailsPage.propTypes = { | ||||
| match: PropTypes.shape({ | match: PropTypes.shape({ | ||||
| params: PropTypes.shape({ | params: PropTypes.shape({ | ||||
| idProizvod: PropTypes.string, | |||||
| offerId: PropTypes.string, | |||||
| }), | }), | ||||
| }), | }), | ||||
| }; | }; |
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const selectedOffer = useSelector(selectOffer); | const selectedOffer = useSelector(selectOffer); | ||||
| const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | const [isInitiallyLoaded, setIsInitiallyLoaded] = useState(false); | ||||
| const offerId = props.match.params.idProizvod; | |||||
| const offerId = props.match.params.offerId; | |||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchOneOffer(offerId)); | dispatch(fetchOneOffer(offerId)); | ||||
| ItemDetailsPage.propTypes = { | ItemDetailsPage.propTypes = { | ||||
| match: PropTypes.shape({ | match: PropTypes.shape({ | ||||
| params: PropTypes.shape({ | params: PropTypes.shape({ | ||||
| idProizvod: PropTypes.string, | |||||
| offerId: PropTypes.string, | |||||
| }), | }), | ||||
| }), | }), | ||||
| }; | }; |
| setTimeout(() => { | setTimeout(() => { | ||||
| history.push( | history.push( | ||||
| replaceInRoute(DIRECT_CHAT_PAGE, { | replaceInRoute(DIRECT_CHAT_PAGE, { | ||||
| idChat: chatId, | |||||
| chatId: chatId, | |||||
| }) | }) | ||||
| ); | ); | ||||
| }, 120); | }, 120); |
| }} | }} | ||||
| /> | /> | ||||
| {console.log(formik)} | |||||
| {formik.errors.mail && formik.touched.mail ? ( | {formik.errors.mail && formik.touched.mail ? ( | ||||
| <ErrorMessage>{formik.errors.mail}</ErrorMessage> | <ErrorMessage>{formik.errors.mail}</ErrorMessage> | ||||
| ) : formik.errors.registerPassword && formik.touched.registerPassword ? ( | ) : formik.errors.registerPassword && formik.touched.registerPassword ? ( |
| function* fetchAdminMethod({ payload }) { | function* fetchAdminMethod({ payload }) { | ||||
| try { | try { | ||||
| yield call(console.log, "admin", payload); | |||||
| if (payload.type === CATEGORIES_TYPE) { | if (payload.type === CATEGORIES_TYPE) { | ||||
| if (payload.method === ADD_TYPE) | if (payload.method === ADD_TYPE) | ||||
| yield call(addCategory, { values: payload.values, id: payload.id }); | yield call(addCategory, { values: payload.values, id: payload.id }); |
| const data = yield call(attemptFetchChats, { userId, queryString }); | const data = yield call(attemptFetchChats, { userId, queryString }); | ||||
| yield put(setChats([...data.data.chatsWithData])); | yield put(setChats([...data.data.chatsWithData])); | ||||
| yield put(setChatsTotal(data.data.total)) | yield put(setChatsTotal(data.data.total)) | ||||
| console.log(data); | |||||
| const newChatId = newChatData.data.chatId; | const newChatId = newChatData.data.chatId; | ||||
| yield put(startNewChatSuccess()); | yield put(startNewChatSuccess()); | ||||
| yield call( | yield call( |
| try { | try { | ||||
| const data = yield call(attemptFetchLocations); | const data = yield call(attemptFetchLocations); | ||||
| if (!data?.data) throw new Error(); | if (!data?.data) throw new Error(); | ||||
| yield put(setLocations(data.data.value)); | |||||
| yield put(setLocations(data.data)); | |||||
| yield put(fetchLocationsSuccess()); | yield put(fetchLocationsSuccess()); | ||||
| } catch (e) { | } catch (e) { | ||||
| yield put(fetchLocationsError()); | yield put(fetchLocationsError()); |
| import { replaceInRoute } from "./routeHelpers"; | import { replaceInRoute } from "./routeHelpers"; | ||||
| export const messageUserHelper = (chats, userId, offer) => { | export const messageUserHelper = (chats, userId, offer) => { | ||||
| const chatItem = chats.find( | |||||
| (item) => item.chat.offerId === offer?.offer?._id | |||||
| ); | |||||
| if (chatItem !== undefined) { | |||||
| history.push( | |||||
| replaceInRoute(DIRECT_CHAT_PAGE, { idChat: chatItem.chat._id }) | |||||
| ); | |||||
| } else { | |||||
| if (offer?.offer?.userId !== userId) { | |||||
| history.push( | |||||
| replaceInRoute(DIRECT_CHAT_PAGE, { idChat: "newMessage" }), | |||||
| { | |||||
| offerId: offer?.offer?._id, | |||||
| } | |||||
| ); | |||||
| } | |||||
| } | |||||
| } | |||||
| const chatItem = chats.find( | |||||
| (item) => item.chat.offerId === offer?.offer?._id | |||||
| ); | |||||
| if (chatItem !== undefined) { | |||||
| history.push( | |||||
| replaceInRoute(DIRECT_CHAT_PAGE, { chatId: chatItem.chat._id }) | |||||
| ); | |||||
| } else { | |||||
| if (offer?.offer?.userId !== userId) { | |||||
| history.push(replaceInRoute(DIRECT_CHAT_PAGE, { chatId: "newMessage" }), { | |||||
| offerId: offer?.offer?._id, | |||||
| }); | |||||
| } | |||||
| } | |||||
| }; |