diff --git a/src/components/embeds/MiniResultsGlobal.js b/src/components/embeds/MiniResultsGlobal.js index f88d003..26f62d1 100644 --- a/src/components/embeds/MiniResultsGlobal.js +++ b/src/components/embeds/MiniResultsGlobal.js @@ -41,14 +41,13 @@ const useQuery = () => { import { ElectionContext } from '../Election' import LoadingScreen from '../layout/LoadingScreen' +import { shouldAllowSendingProtocols } from '../../utils/visibility' // Only show results, when they are available and after election day end const shouldShowResults = (results, meta) => { - if (!results || !meta) return false + if (!results) return false - const { endOfElectionDayTimestamp } = meta - - return results.length > 0 && new Date() > new Date(endOfElectionDayTimestamp) + return results.length > 0 && shouldAllowSendingProtocols(meta) } export default (props) => { diff --git a/src/components/layout/Header.js b/src/components/layout/Header.js index f6fc41e..7741b7c 100644 --- a/src/components/layout/Header.js +++ b/src/components/layout/Header.js @@ -1,10 +1,12 @@ -import React, { useState } from 'react' +import React, { useContext, useState } from 'react' import { Link } from 'react-router-dom' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faBars } from '@fortawesome/free-solid-svg-icons' import { slide as Menu } from 'react-burger-menu' import styled from 'styled-components' import { ROUTES } from '../routes' +import { ElectionContext } from '../Election' +import { shouldAllowSendingProtocols } from '../../utils/visibility' const MOBILE_WIDTH = 952 @@ -115,6 +117,7 @@ const MobileNavMenu = styled.div` export default () => { const [menuOpen, setMenuOpen] = useState(false) + const { meta } = useContext(ElectionContext) return ( <> @@ -125,7 +128,9 @@ export default () => { - Изпрати протокол + {shouldAllowSendingProtocols(meta) && ( + Изпрати протокол + )} Подай сигнал {/*Запиши се*/} {/*Kампанията*/} diff --git a/src/utils/visibility.js b/src/utils/visibility.js new file mode 100644 index 0000000..6ed87f9 --- /dev/null +++ b/src/utils/visibility.js @@ -0,0 +1,7 @@ +export const shouldAllowSendingProtocols = (meta) => { + if (!meta?.endOfElectionDayTimestamp) { + return false + } + + return new Date() > new Date(meta.endOfElectionDayTimestamp) +}