Skip to content

Commit

Permalink
show protocol form only after election day ends
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Jun 7, 2024
1 parent 46d2357 commit 064062b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/components/embeds/MiniResultsGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
9 changes: 7 additions & 2 deletions src/components/layout/Header.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -115,6 +117,7 @@ const MobileNavMenu = styled.div`

export default () => {
const [menuOpen, setMenuOpen] = useState(false)
const { meta } = useContext(ElectionContext)

return (
<>
Expand All @@ -125,7 +128,9 @@ export default () => {
<LogoImage src="/brand/logo_horizontal_white.png?v=2" />
</Link>
<Navigation>
<Link to={ROUTES.protocolForm}>Изпрати протокол</Link>
{shouldAllowSendingProtocols(meta) && (
<Link to={ROUTES.protocolForm}>Изпрати протокол</Link>
)}
<Link to={ROUTES.violationForm}>Подай сигнал</Link>
{/*<a href="/signup">Запиши се</a>*/}
{/*<a href="/about">Kампанията</a>*/}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/visibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const shouldAllowSendingProtocols = (meta) => {
if (!meta?.endOfElectionDayTimestamp) {
return false
}

return new Date() > new Date(meta.endOfElectionDayTimestamp)
}

0 comments on commit 064062b

Please sign in to comment.