|
| 1 | +import React, { Fragment } from "react" |
| 2 | +import Snackbar from "@material-ui/core/Snackbar" |
| 3 | +import IconButton from "@material-ui/core/IconButton" |
| 4 | +import CloseIcon from "@material-ui/icons/Close" |
| 5 | +import InfoIcon from "@material-ui/icons/Info" |
| 6 | +import styled from "styled-components" |
| 7 | +import { Typography } from "@material-ui/core" |
| 8 | +import LoginStateContext from "../contexes/LoginStateContext" |
| 9 | +import * as store from "store" |
| 10 | + |
| 11 | +const StyledInfoIcon = styled(InfoIcon)` |
| 12 | + vertical-align: middle; |
| 13 | + margin-right: 0.5rem; |
| 14 | +` |
| 15 | + |
| 16 | +const StyledTypography = styled(Typography)` |
| 17 | + display: inline-block !important; |
| 18 | + color: white !important; |
| 19 | + a { |
| 20 | + color: white !important; |
| 21 | + box-shadow: inset 0 -3px 0 0 white; |
| 22 | + } |
| 23 | +` |
| 24 | + |
| 25 | +export default class Notification extends React.Component { |
| 26 | + static contextType = LoginStateContext |
| 27 | + |
| 28 | + state = { |
| 29 | + render: false, |
| 30 | + open: true, |
| 31 | + } |
| 32 | + |
| 33 | + componentDidMount() { |
| 34 | + this.setState({ render: true }) |
| 35 | + store.set("paja.closed", true) |
| 36 | + } |
| 37 | + |
| 38 | + handleClick = () => { |
| 39 | + this.setState({ open: true }) |
| 40 | + } |
| 41 | + |
| 42 | + handleClose = (event, reason) => { |
| 43 | + if (reason === "clickaway") { |
| 44 | + return |
| 45 | + } |
| 46 | + |
| 47 | + this.setState({ open: false }) |
| 48 | + store.set("paja.closed", true) |
| 49 | + } |
| 50 | + |
| 51 | + handleRefresh = () => { |
| 52 | + window.location.reload() |
| 53 | + } |
| 54 | + |
| 55 | + render() { |
| 56 | + if ( |
| 57 | + !this.state.render || |
| 58 | + !this.context.loggedIn || |
| 59 | + store.get("paja.closed") |
| 60 | + ) { |
| 61 | + return <Fragment /> |
| 62 | + } |
| 63 | + return ( |
| 64 | + <Fragment> |
| 65 | + <Snackbar |
| 66 | + anchorOrigin={{ vertical: "top", horizontal: "center" }} |
| 67 | + open={this.state.open} |
| 68 | + onClose={this.handleClose} |
| 69 | + ContentProps={{ "aria-describedby": "message-id" }} |
| 70 | + message={ |
| 71 | + <Fragment> |
| 72 | + <StyledInfoIcon /> |
| 73 | + <StyledTypography> |
| 74 | + Pajaohjausta on nyt saatavilla! Ensimmäinen paja on huomenna |
| 75 | + torstaina 16.1. klo 12-19 Helsingin Kumpulan kampuksella. Muut |
| 76 | + paja-ajat ja tarkemmat ohjeet löytyvät{" "} |
| 77 | + <a href="/tukivaylat">tukiväylät</a>-sivulta. |
| 78 | + </StyledTypography> |
| 79 | + </Fragment> |
| 80 | + } |
| 81 | + action={[ |
| 82 | + <IconButton |
| 83 | + key="close" |
| 84 | + aria-label="Close" |
| 85 | + color="inherit" |
| 86 | + onClick={this.handleClose} |
| 87 | + > |
| 88 | + <CloseIcon /> |
| 89 | + </IconButton>, |
| 90 | + ]} |
| 91 | + /> |
| 92 | + </Fragment> |
| 93 | + ) |
| 94 | + } |
| 95 | +} |
0 commit comments