forked from psmb/Psmb.Newsletter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: migrate newsletter view to new UI
- Loading branch information
Showing
11 changed files
with
783 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
Resources/Private/NewsletterView/src/TestConfirmationDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./manifest'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |
Oops, something went wrong.