Skip to content

Commit

Permalink
TASK: migrate newsletter view to new UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip committed Aug 25, 2017
1 parent 41535a5 commit b65bd4a
Show file tree
Hide file tree
Showing 11 changed files with 783 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules

6 changes: 5 additions & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ Neos:
fusion:
autoInclude:
Psmb.Newsletter: true

Ui:
resources:
javascript:
'Psmb.Newsletter:NewsletterView':
resource: resource://Psmb.Newsletter/Public/JavaScript/NewsletterView/Plugin.js
#Psmb:
# Newsletter:
# globalSettings:
Expand Down
14 changes: 14 additions & 0 deletions Resources/Private/NewsletterView/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{yml,yaml}]
indent_size = 2

[*.{md}]
indent_size = 2
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions Resources/Private/NewsletterView/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.3.0
15 changes: 15 additions & 0 deletions Resources/Private/NewsletterView/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"description": "NewsletterView",
"license": "MIT",
"private": true,
"scripts": {
"build": "neos-react-scripts build",
"watch": "neos-react-scripts watch"
},
"devDependencies": {
"@neos-project/neos-ui-extensibility": "@dev"
},
"neos": {
"buildTargetDirectory": "../../Public/JavaScript/NewsletterView"
}
}
101 changes: 101 additions & 0 deletions Resources/Private/NewsletterView/src/NewsletterView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React, {PropTypes, Component} from 'react';
import {SelectBox, Button, Dialog, TextInput} from '@neos-project/react-ui-components';
import {connect} from 'react-redux';
import {selectors} from '@neos-project/neos-ui-redux-store';
import {neos} from '@neos-project/neos-ui-decorators';
import {$get} from 'plow-js';
import TestConfirmationDialog from './TestConfirmationDialog';

const fetchSubscriptions = nodeType => fetch(`/newsletter/getSubscriptions?nodeType=${nodeType}`, {
credentials: 'include'
}).then(response => response.json());

const sendNewsletter = (isTest, email) => {
const sendEndpointUrl = isTest ? '/newsletter/testSend' : '/newsletter/send';
const csrfToken = document.getElementById('appContainer').dataset.csrfToken;
const data = new URLSearchParams();
data.set('node', this.props.focusedNodeContextPath.replace(/user-.+\;/, 'live;'));
data.set('subscription', this.state.selectedSubscription);
data.set('__csrfToken', csrfToken);
if (isTest && email) {
data.set('email', email);
}
fetch(sendEndpointUrl, {
credentials: 'include',
method: 'POST',
body: data
})
.then(response => response.json());
};

@neos(globalRegistry => ({
i18nRegistry: globalRegistry.get('i18n')
}))
@connect(state => ({
focusedNodeContextPath: selectors.CR.Nodes.focusedNodePathSelector(state),
getNodeByContextPath: selectors.CR.Nodes.nodeByContextPath(state)
}))
export default class NewsletterView extends Component {

static propTypes = {
focusedNodeContextPath: PropTypes.string,
getNodeByContextPath: PropTypes.func.isRequired
};

constructor(props) {
super(props);
this.state = {
subscriptions: [],
selectedSubscription: null,
confirmationDialogIsOpen: false,
isError: null,
isSent: null
};
this.selectSubscription = this.selectSubscription.bind(this);
this.sendTestNewsletter = this.sendTestNewsletter.bind(this);
this.toggleTestConfirmationDialog = this.toggleTestConfirmationDialog.bind(this);
}

componentDidMount() {
const node = this.props.getNodeByContextPath(this.props.focusedNodeContextPath);
const nodeType = $get('nodeType', node);
if (nodeType) {
fetchSubscriptions(nodeType).then(json => this.setState({subscriptions: json}));
}
}

toggleTestConfirmationDialog(isOpen) {
this.setState({confirmationDialogIsOpen: isOpen})
}

selectSubscription(value) {
this.setState({selectedSubscription: value});
}

sendTestNewsletter(email) {
const isTest = true;
sendNewsletter(isTest, email).then(json => json.status === 'success' ? this.setState({isSent: true}) : this.setState({isError: true}));
this.toggleTestConfirmationDialog(false);
}

render() {
return (
<div>
<SelectBox
value={this.state.selectedSubscription}
options={this.state.subscriptions}
onValueChange={this.selectSubscription}
/>
<Button style="brand" onClick={() => this.toggleTestConfirmationDialog(true)}>{this.props.i18nRegistry.translate('Psmb.Newsletter:Main:js.send')}</Button>
<Button style="clean" onClick={() => this.toggleTestConfirmationDialog(true)}>{this.props.i18nRegistry.translate('Psmb.Newsletter:Main:js.test')}</Button>

<TestConfirmationDialog
isOpen={this.state.confirmationDialogIsOpen}
translate={this.props.i18nRegistry.translate.bind(this.props.i18nRegistry)}
close={() => toggleTestConfirmationDialog(false)}
send={this.sendTestNewsletter}
/>
</div>
);
}
}
40 changes: 40 additions & 0 deletions Resources/Private/NewsletterView/src/TestConfirmationDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {PropTypes, Component} from 'react';
import {SelectBox, Button, Dialog, TextInput} from '@neos-project/react-ui-components';

export default class TestConfirmationDialog extends Component {

static propTypes = {
isOpen: PropTypes.bool,
translate: PropTypes.func.isRequired,
close: PropTypes.func.isRequired,
send: PropTypes.func.isRequired
};

constructor(props) {
super(props);
this.state = {
email: ''
};
}

render() {
const {isOpen, translate, close, send} = this.props;
return (
<Dialog
isOpen={isOpen}
title={translate('Psmb.Newsletter:Main:js.testConfirmationTitle')}
onRequestClose={close}
actions={[
<Button onClick={close} style="clean">{translate('Neos.Neos:Main:cancel')}</Button>,
<Button onClick={() => send(this.state.email)} style="brand">{translate('Psmb.Newsletter:Main:js.send')}</Button>
]}
>
{translate('Psmb.Newsletter:Main:js.testEmailLabel')}
<TextInput
onChange={email => this.setState({email})}
value={this.state.email}
/>
</Dialog>
);
}
}
1 change: 1 addition & 0 deletions Resources/Private/NewsletterView/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./manifest');
10 changes: 10 additions & 0 deletions Resources/Private/NewsletterView/src/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import manifest from '@neos-project/neos-ui-extensibility';
import NewsletterView from './NewsletterView';

manifest('Psmb.Newsletter:NewsletterView', {}, globalRegistry => {
const viewsRegistry = globalRegistry.get('inspector').get('views');

viewsRegistry.add('Psmb.Newsletter/Views/NewsletterView', {
component: NewsletterView
});
});
Loading

0 comments on commit b65bd4a

Please sign in to comment.