From 7146f00c0510566a00f8a91f79a84c1e844dcdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 27 Nov 2015 13:36:42 +0100 Subject: [PATCH] Refactor webhooks: add source, clear state on create hide create on no items left --- js/actions/webhook_actions.js | 40 ++-------- .../ascribe_settings/webhook_settings.js | 65 +++++++++-------- .../components/pr_login_container.js | 0 js/fetchers/webhook_fetcher.js | 23 ------ js/sources/webhook_source.js | 46 ++++++++++++ js/stores/webhook_store.js | 73 +++++++++++++++++-- 6 files changed, 153 insertions(+), 94 deletions(-) create mode 100644 js/components/whitelabel/prize/portfolioreview/components/pr_login_container.js delete mode 100644 js/fetchers/webhook_fetcher.js create mode 100644 js/sources/webhook_source.js diff --git a/js/actions/webhook_actions.js b/js/actions/webhook_actions.js index 4e5b2462..f9555ce7 100644 --- a/js/actions/webhook_actions.js +++ b/js/actions/webhook_actions.js @@ -1,47 +1,19 @@ 'use strict'; import { alt } from '../alt'; -import WebhookFetcher from '../fetchers/webhook_fetcher'; class WebhookActions { constructor() { this.generateActions( - 'updateWebhooks', - 'updateEvents', - 'removeWebhook' + 'fetchWebhooks', + 'successFetchWebhooks', + 'fetchWebhookEvents', + 'successFetchWebhookEvents', + 'removeWebhook', + 'successRemoveWebhook' ); } - - fetchWebhooks() { - WebhookFetcher.fetch() - .then((res) => { - this.actions.updateWebhooks(res.webhooks); - }) - .catch((err) => { - console.logGlobal(err); - }); - } - - fetchWebhookEvents() { - WebhookFetcher.fetchEvents() - .then((res) => { - this.actions.updateEvents(res.events); - }) - .catch((err) => { - console.logGlobal(err); - }); - } - - deleteWebhook(id){ - WebhookFetcher.deleteWebhook(id) - .then((res) => { - this.actions.removeWebhook(id); - }) - .catch((err) => { - console.logGlobal(err); - }); - } } export default alt.createActions(WebhookActions); diff --git a/js/components/ascribe_settings/webhook_settings.js b/js/components/ascribe_settings/webhook_settings.js index 1f9eefc5..18c21aa6 100644 --- a/js/components/ascribe_settings/webhook_settings.js +++ b/js/components/ascribe_settings/webhook_settings.js @@ -11,6 +11,8 @@ import GlobalNotificationActions from '../../actions/global_notification_actions import Form from '../ascribe_forms/form'; import Property from '../ascribe_forms/property'; +import AclProxy from '../acl_proxy'; + import ActionPanel from '../ascribe_panel/action_panel'; import CollapsibleParagraph from '../ascribe_collapsible/collapsible_paragraph'; @@ -43,16 +45,18 @@ let WebhookSettings = React.createClass({ this.setState(state); }, - onDeleteWebhook(event) { - let webhookId = event.target.getAttribute('data-id'); - WebhookActions.deleteWebhook(webhookId); + onRemoveWebhook(webhookId) { + return (event) => { + WebhookActions.removeWebhook(webhookId); - let notification = new GlobalNotificationModel(getLangText('Webhook deleted'), 'success', 2000); - GlobalNotificationActions.appendGlobalNotification(notification); + let notification = new GlobalNotificationModel(getLangText('Webhook deleted'), 'success', 2000); + GlobalNotificationActions.appendGlobalNotification(notification); + }; }, handleCreateSuccess() { - WebhookActions.fetchWebhooks(); + this.refs.webhookCreateForm.reset(); + WebhookActions.fetchWebhooks(true); let notification = new GlobalNotificationModel(getLangText('Webhook successfully created'), 'success', 5000); GlobalNotificationActions.appendGlobalNotification(notification); }, @@ -60,7 +64,7 @@ let WebhookSettings = React.createClass({ getWebhooks(){ let content = ; - if (this.state.webhooks.length > -1) { + if (this.state.webhooks) { content = this.state.webhooks.map(function(webhook, i) { const event = webhook.event.split('.')[0]; return ( @@ -82,8 +86,7 @@ let WebhookSettings = React.createClass({
@@ -96,14 +99,13 @@ let WebhookSettings = React.createClass({ }, getEvents() { - if (this.state.events && this.state.events.length > 1) { + if (this.state.webhookEvents && this.state.webhookEvents.length) { return ( - + {this.state.webhookEvents.map((event, i) => { return (