Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a system notification that can be configured in the admin #1294

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions src/ui/EditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import defaultTemplateUrl from "./../assets/templates/crater.spoke";
import tutorialTemplateUrl from "./../assets/templates/tutorial.spoke";

import { TERMS, PRIVACY } from "../constants";
import NotificationDialog from "./dialogs/NotificationDialog";

const StyledEditorContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -104,23 +105,43 @@ class EditorContainer extends Component {
const projectId = match.params.projectId;
const queryParams = new URLSearchParams(location.search);

if (projectId === "new") {
if (queryParams.has("template")) {
this.loadProjectTemplate(queryParams.get("template"));
} else if (queryParams.has("sceneId")) {
this.loadScene(queryParams.get("sceneId"));
const load = () => {
if (projectId === "new") {
if (queryParams.has("template")) {
this.loadProjectTemplate(queryParams.get("template"));
} else if (queryParams.has("sceneId")) {
this.loadScene(queryParams.get("sceneId"));
} else {
this.loadProjectTemplate(defaultTemplateUrl);
}
} else if (projectId === "tutorial") {
this.loadProjectTemplate(tutorialTemplateUrl, true);
} else {
this.loadProjectTemplate(defaultTemplateUrl);
this.loadProject(projectId);
}
} else if (projectId === "tutorial") {
this.loadProjectTemplate(tutorialTemplateUrl, true);
} else {
this.loadProject(projectId);
}

if (projectId === "tutorial") {
trackEvent("Tutorial Start");
this.setState({ onboardingContext: { enabled: true } });
if (projectId === "tutorial") {
trackEvent("Tutorial Start");
this.setState({ onboardingContext: { enabled: true } });
}
};

const features = {
show_global_notification: true,
global_notification_body: "COPY HERE",
global_notification_link: "https://mozilla.org"
};
if (features["show_global_notification"]) {
this.showDialog(NotificationDialog, {
title: "Admin notification",
message: features["global_notification_body"],
link: features["global_notification_link"],
onClosed: load,
onConfirm: load,
onCancel: null
});
} else {
load();
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/ui/dialogs/NotificationDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import Dialog, { DialogContent } from "./Dialog";
import styled from "styled-components";
import { Button } from "../inputs/Button";

const NotificationDialogContainer = styled(Dialog)`
max-width: 600px;

${DialogContent} {
padding: 0;
}
`;

const NotificationMessage = styled.code`
white-space: pre-wrap;
overflow-wrap: break-word;
overflow-x: hidden;
overflow-y: auto;
padding: 16px;
color: ${props => props.theme.red};
`;

export default class NotificationDialog extends Component {
componentDidMount() {}

openLink = () => {
window.open(this.props.link);
this.props.onClosed();
};

renderBottomNav() {
return this.props.link ? <Button onClick={this.openLink}>Learn More</Button> : null;
}

render() {
const { message, onClosed, ...props } = this.props;

return (
<NotificationDialogContainer {...props} bottomNav={this.renderBottomNav()}>
<NotificationMessage>{message}</NotificationMessage>
</NotificationDialogContainer>
);
}
}

NotificationDialog.propTypes = {
title: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
link: PropTypes.string,
onClosed: PropTypes.func
};

NotificationDialog.defaultProps = {
title: "Notification"
};
60 changes: 60 additions & 0 deletions src/ui/layout/Notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";

const NotificationContainer = styled.div`
display: flex;
align-items: center;
justify-content: center;
`;

const StyledNotification = styled.div`
min-height: 24px;
margin: 1em 20px;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.1em;
padding: 1em;
border-radius: 6px;
background-color: ${props => props.theme.red};
`;

const Content = styled.span`
max-width: 50vw;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
`;

const ViewMore = styled.div`
text-align: center;
margin-left: 1em;
a {
color: ${props => props.theme.blue};
}
`;

export default class Notification extends Component {
render() {
const { body, link } = this.props;
return (
<NotificationContainer>
<StyledNotification>
<Content>{body}</Content>
<ViewMore>
<a href={link} target="_blank" rel="noopener noreferrer">
Learn more
</a>
</ViewMore>
</StyledNotification>
</NotificationContainer>
);
}
}

Notification.propTypes = {
body: PropTypes.string.isRequired,
link: PropTypes.string,
onClosed: PropTypes.func
};
15 changes: 14 additions & 1 deletion src/ui/projects/ProjectsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Link } from "react-router-dom";
import LatestUpdate from "../whats-new/LatestUpdate";
import { connectMenu, ContextMenu, MenuItem } from "../layout/ContextMenu";
import styled from "styled-components";
import Notification from "../layout/Notification";

export const ProjectsSection = styled.section`
padding-bottom: 100px;
Expand Down Expand Up @@ -87,7 +88,10 @@ class ProjectsPage extends Component {
scenes: [],
loading: isAuthenticated,
isAuthenticated,
error: null
error: null,
showGlobalNotification: false,
globalNotificationBody: null,
globalNotificationLink: null
};
}

Expand Down Expand Up @@ -122,6 +126,12 @@ class ProjectsPage extends Component {
this.setState({ error, loading: false });
});
}

this.setState({
showGlobalNotification: true,
globalNotificationBody: "COPY HERE",
globalNotificationLink: "https://mozilla.org"
});
}

onDeleteProject = project => {
Expand Down Expand Up @@ -172,6 +182,9 @@ class ProjectsPage extends Component {
<h1>Projects</h1>
</ProjectsHeader>
<ProjectGridContainer>
{this.state.showGlobalNotification && (
<Notification body={this.state.globalNotificationBody} link={this.state.globalNotificationLink} />
)}
<ProjectGridHeader>
<ProjectGridHeaderRow></ProjectGridHeaderRow>
<ProjectGridHeaderRow>
Expand Down
Loading