Skip to content

Commit

Permalink
feat: Home page announcement (#2710)
Browse files Browse the repository at this point in the history
  • Loading branch information
novakzaballa committed Aug 31, 2023
1 parent ef0ca42 commit 9de235b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
39 changes: 37 additions & 2 deletions frontend/web/components/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { Component, Fragment } from 'react'
import { matchPath } from 'react-router'
import { withRouter } from 'react-router-dom'
import amplitude from 'amplitude-js'
Expand All @@ -22,6 +22,7 @@ import { getOrganisationUsage } from 'common/services/useOrganisationUsage'
import Button from './base/forms/Button'
import Icon from 'components/Icon'
import AccountStore from 'common/stores/account-store'
import InfoMessage from './InfoMessage'

const App = class extends Component {
static propTypes = {
Expand All @@ -38,6 +39,7 @@ const App = class extends Component {
lastEnvironmentId: '',
lastProjectId: '',
pin: '',
showAnnouncement: true,
totalApiCalls: 0,
}

Expand Down Expand Up @@ -210,6 +212,11 @@ const App = class extends Component {
this.context.router.history.replace('/')
}

closeAnnouncement = (announcementId) => {
this.setState({ showAnnouncement: false })
flagsmith.setTrait(`dismissed_announcement`, announcementId)
}

render() {
if (
Utils.getFlagsmithHasFeature('dark_mode') &&
Expand Down Expand Up @@ -276,6 +283,11 @@ const App = class extends Component {
if (document.location.href.includes('widget')) {
return <div>{this.props.children}</div>
}
const announcementValue = JSON.parse(
Utils.getFlagsmithValue('announcement'),
)
const dismissed = flagsmith.getTrait('dismissed_announcement')
const showBanner = !dismissed || dismissed !== announcementValue.id

return (
<Provider store={getStore()}>
Expand Down Expand Up @@ -471,7 +483,30 @@ const App = class extends Component {
<Loader />
</div>
) : (
this.props.children
<Fragment>
{user &&
showBanner &&
Utils.getFlagsmithHasFeature('announcement') &&
this.state.showAnnouncement && (
<Row>
<InfoMessage
title={announcementValue.title}
infoMessageClass={'announcement'}
isClosable={announcementValue.isClosable}
close={() =>
this.closeAnnouncement(announcementValue.id)
}
buttonText={announcementValue.buttonText}
url={announcementValue.url}
>
<div>
<div>{announcementValue.description}</div>
</div>
</InfoMessage>
</Row>
)}
{this.props.children}
</Fragment>
)}
</div>
)}
Expand Down
28 changes: 26 additions & 2 deletions frontend/web/components/InfoMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,40 @@ import Icon from './Icon'
export default class InfoMessage extends PureComponent {
static displayName = 'InfoMessage'

handleOpenNewWindow = () => {
window.open(this.props.url, '_blank')
if (this.props.isClosable) {
this.props.close()
}
}

render() {
const infoMessageClass = `alert alert-info ${
this.props.infoMessageClass || 'flex-1'
}`
const titleDescClass = this.props.infoMessageClass
? `${this.props.infoMessageClass} body mr-2`
: ''

return (
<div className='alert alert-info flex-1'>
<div className={infoMessageClass}>
<span className='icon-alert'>
<Icon name='info' />
</span>
<div>
<div className={titleDescClass}>
<div className='title'>{this.props.title || 'NOTE'}</div>
{this.props.children}
</div>
{this.props.url && (
<Button className='btn my-2' onClick={this.handleOpenNewWindow}>
{this.props.buttonText}
</Button>
)}
{this.props.isClosable && (
<a onClick={this.props.close} className='mt-n2 mr-n2 pl-2'>
<span className='icon ion-md-close' />
</a>
)}
</div>
)
}
Expand Down
12 changes: 12 additions & 0 deletions frontend/web/styles/project/_alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
color: $text-icon-dark;
}
}

.announcement {
margin: auto;
margin-top: 10px;
display: flex;
flex-direction: row;
.body {
flex-direction: column;
justify-content: flex-start;
}
}

.dark {
.alert {
color: $alert-color-dark;
Expand Down

3 comments on commit 9de235b

@vercel
Copy link

@vercel vercel bot commented on 9de235b Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 9de235b Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs.flagsmith.com
docs.bullet-train.io
docs-flagsmith.vercel.app
docs-git-main-flagsmith.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 9de235b Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.