Skip to content

Commit 064062b

Browse files
committed
show protocol form only after election day ends
1 parent 46d2357 commit 064062b

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/components/embeds/MiniResultsGlobal.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ const useQuery = () => {
4141

4242
import { ElectionContext } from '../Election'
4343
import LoadingScreen from '../layout/LoadingScreen'
44+
import { shouldAllowSendingProtocols } from '../../utils/visibility'
4445

4546
// Only show results, when they are available and after election day end
4647
const shouldShowResults = (results, meta) => {
47-
if (!results || !meta) return false
48+
if (!results) return false
4849

49-
const { endOfElectionDayTimestamp } = meta
50-
51-
return results.length > 0 && new Date() > new Date(endOfElectionDayTimestamp)
50+
return results.length > 0 && shouldAllowSendingProtocols(meta)
5251
}
5352

5453
export default (props) => {

src/components/layout/Header.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React, { useState } from 'react'
1+
import React, { useContext, useState } from 'react'
22
import { Link } from 'react-router-dom'
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
44
import { faBars } from '@fortawesome/free-solid-svg-icons'
55
import { slide as Menu } from 'react-burger-menu'
66
import styled from 'styled-components'
77
import { ROUTES } from '../routes'
8+
import { ElectionContext } from '../Election'
9+
import { shouldAllowSendingProtocols } from '../../utils/visibility'
810

911
const MOBILE_WIDTH = 952
1012

@@ -115,6 +117,7 @@ const MobileNavMenu = styled.div`
115117

116118
export default () => {
117119
const [menuOpen, setMenuOpen] = useState(false)
120+
const { meta } = useContext(ElectionContext)
118121

119122
return (
120123
<>
@@ -125,7 +128,9 @@ export default () => {
125128
<LogoImage src="/brand/logo_horizontal_white.png?v=2" />
126129
</Link>
127130
<Navigation>
128-
<Link to={ROUTES.protocolForm}>Изпрати протокол</Link>
131+
{shouldAllowSendingProtocols(meta) && (
132+
<Link to={ROUTES.protocolForm}>Изпрати протокол</Link>
133+
)}
129134
<Link to={ROUTES.violationForm}>Подай сигнал</Link>
130135
{/*<a href="/signup">Запиши се</a>*/}
131136
{/*<a href="/about">Kампанията</a>*/}

src/utils/visibility.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const shouldAllowSendingProtocols = (meta) => {
2+
if (!meta?.endOfElectionDayTimestamp) {
3+
return false
4+
}
5+
6+
return new Date() > new Date(meta.endOfElectionDayTimestamp)
7+
}

0 commit comments

Comments
 (0)