Skip to content

Commit

Permalink
store banner state in cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonjetz committed Jul 10, 2024
1 parent 42022ad commit a4f7f8e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ import React, { useState } from 'react'
import Alert from 'react-bootstrap/Alert'
import './Header.css'
import { Container } from 'react-bootstrap'
import { set as setCookie, get as getCookie } from 'es-cookie'

function AlertDismissibleExample(): JSX.Element | null {
const [show, setShow] = useState(true)
function InfoBanner(): JSX.Element | null {
const initialState = getCookie('eblShowInfoBanner') !== 'false'
const [show, setShow] = useState(initialState)

const midnight = new Date()
midnight.setHours(23, 59, 59)

return show ? (
<Container fluid className="Header__info-banner">
<Alert variant="warning" onClose={() => setShow(false)} dismissible>
<Alert
variant="warning"
onClose={() => {
setShow(false)
setCookie('eblShowInfoBanner', 'false', { expires: midnight })
}}
dismissible
>
<strong>Scheduled Maintenance Notice:</strong> Our servers will be
undergoing planned maintenance on{' '}
<strong>
Expand All @@ -21,4 +33,4 @@ function AlertDismissibleExample(): JSX.Element | null {
) : null
}

export default AlertDismissibleExample
export default InfoBanner

0 comments on commit a4f7f8e

Please sign in to comment.