don't show announcement when signed in

main
Mike Fix 5 years ago
parent 520e19ab44
commit a44756b2ab

@ -1,39 +1,44 @@
import React from 'react' import React from 'react'
import { useAuth } from './AuthContext'
const key = 'CARBON_CTA_1' const key = 'CARBON_CTA_1'
class Toast extends React.Component { function Toast() {
state = { const [open, setState] = React.useState(false)
open: false
}
close = () => { React.useEffect(() => {
this.setState({ open: false })
window.localStorage.setItem(key, true)
}
componentDidMount() {
window.localStorage.removeItem('CARBON_CTA') window.localStorage.removeItem('CARBON_CTA')
if (!window.localStorage.getItem(key)) { if (!window.localStorage.getItem(key)) {
this.setState({ open: true }) setState(true)
}
} }
}, [])
const user = useAuth()
render() {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
return null return null
} }
if (!this.state.open) { if (!open) {
return null return null
} }
if (user) {
return null
}
function close() {
setState(false)
window.localStorage.setItem(key, true)
}
return ( return (
<div className="toast mb4"> <div className="toast mb4">
<div className="toast-content"> <div className="toast-content">
<p>Never lose a Carbon again - save your work automatically!</p> <p>Never lose a Carbon again - save your work automatically!</p>
Click &quot;Sign up&quot; to try it out! Click &quot;Sign up&quot; to try it out!
<button className="close-toast" onClick={this.close}> <button className="close-toast" onClick={close}>
&times; &times;
</button> </button>
</div> </div>
@ -87,7 +92,6 @@ class Toast extends React.Component {
</style> </style>
</div> </div>
) )
}
} }
export default Toast export default Toast

@ -11,9 +11,9 @@ class Page extends React.Component {
return ( return (
<main className="main mt4 mb4"> <main className="main mt4 mb4">
<Meta /> <Meta />
<AuthContext>
<Announcement /> <Announcement />
<Header enableHeroText={enableHeroText} /> <Header enableHeroText={enableHeroText} />
<AuthContext>
<div className="page">{children}</div> <div className="page">{children}</div>
</AuthContext> </AuthContext>

Loading…
Cancel
Save