don't show announcement when signed in

main
Mike Fix 5 years ago
parent 520e19ab44
commit a44756b2ab

@ -1,93 +1,97 @@
import React from 'react' import React from 'react'
const key = 'CARBON_CTA_1' import { useAuth } from './AuthContext'
class Toast extends React.Component { const key = 'CARBON_CTA_1'
state = {
open: false
}
close = () => { function Toast() {
this.setState({ open: false }) const [open, setState] = React.useState(false)
window.localStorage.setItem(key, true)
}
componentDidMount() { React.useEffect(() => {
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()
if (process.env.NODE_ENV !== 'production') {
return null
} }
render() { if (!open) {
if (process.env.NODE_ENV !== 'production') { return null
return null }
}
if (!this.state.open) { if (user) {
return null return null
} }
return ( function close() {
<div className="toast mb4"> setState(false)
<div className="toast-content"> window.localStorage.setItem(key, true)
<p>Never lose a Carbon again - save your work automatically!</p> }
Click &quot;Sign up&quot; to try it out!
<button className="close-toast" onClick={this.close}>
&times;
</button>
</div>
<style jsx>
{`
@keyframes slide {
from {
transform: translateY(-128px);
}
to {
transform: translateY(0px);
}
}
.toast { return (
padding: 8px 16px; <div className="toast mb4">
color: #fff; <div className="toast-content">
border: 1px solid #fff; <p>Never lose a Carbon again - save your work automatically!</p>
border-radius: 2px; Click &quot;Sign up&quot; to try it out!
margin-top: calc(var(--x4) * -1); <button className="close-toast" onClick={close}>
animation-name: slide; &times;
animation-duration: 600ms; </button>
</div>
<style jsx>
{`
@keyframes slide {
from {
transform: translateY(-128px);
} }
to {
.toast-content { transform: translateY(0px);
display: flex;
align-items: center;
} }
}
a { .toast {
text-decoration: underline; padding: 8px 16px;
} color: #fff;
border: 1px solid #fff;
border-radius: 2px;
margin-top: calc(var(--x4) * -1);
animation-name: slide;
animation-duration: 600ms;
}
.close-toast { .toast-content {
padding-left: 0; display: flex;
padding-right: 0; align-items: center;
background: transparent; }
color: white;
border: none;
font-size: 100%;
margin-left: 32px;
text-decoration: none;
cursor: pointer;
}
p { a {
margin: 0; text-decoration: underline;
margin-right: 12px; }
}
`} .close-toast {
</style> padding-left: 0;
</div> padding-right: 0;
) background: transparent;
} color: white;
border: none;
font-size: 100%;
margin-left: 32px;
text-decoration: none;
cursor: pointer;
}
p {
margin: 0;
margin-right: 12px;
}
`}
</style>
</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 />
<Announcement />
<Header enableHeroText={enableHeroText} />
<AuthContext> <AuthContext>
<Announcement />
<Header enableHeroText={enableHeroText} />
<div className="page">{children}</div> <div className="page">{children}</div>
</AuthContext> </AuthContext>

Loading…
Cancel
Save