2018-03-25 18:03:08 +00:00
// License: LGPL-3.0-or-later
2018-03-25 17:30:42 +00:00
const h = require ( 'snabbdom/h' )
const R = require ( 'ramda' )
const flyd = require ( 'flyd' )
const request = require ( '../../../common/request' )
const flyd _lift = require ( 'flyd/module/lift' )
const colors = require ( '../../../common/colors' )
function init ( ) {
var state = {
clickSync$ : flyd . stream ( )
, mailchimpKeyResp$ : request ( { method : 'get' , path : ` /nonprofits/ ${ app . nonprofit _id } /nonprofit_keys ` , query : { select : 'mailchimp_token' } } ) . load
}
state . mailchimpKey$ = flyd . map ( R . prop ( 'response' ) , flyd . filter ( resp => resp . status === 200 , state . mailchimpKeyResp$ ) )
return state
}
function view ( state ) {
return h ( 'section.integrations.settings-pane.nonprofit-settings' , {
style : { display : 'none' }
} , [
h ( 'header.pane-header' , [ h ( 'h3' , 'Integrations' ) ] )
, h ( 'p' , 'Connect your CommitChange account with other apps to take advantage of integration features.' )
, integrationSection ( state , state . mailchimpKey$ ( ) , 'MailChimp' , mailchimpConnectedMessage , mailchimpNotConnectedMessage )
, h ( 'br' )
] )
}
// A section fo each integration; pass in the API key for the integration, the
// name, and two functions for bodies: the first body function for when the API
// key is defined, the second body function for when the API key is undefined
const integrationSection = ( state , key , name , bodyConnected , bodyNotConnected ) => {
return h ( 'div.pane-inner.integrations' , [
h ( 'h6' , {
style : { color : key ? colors [ '$bluegrass' ] : colors [ '$grey' ] }
} , [
key ? h ( 'i.fa.fa-check' ) : h ( 'i.fa.fa-question-circle' )
, ' ' + name
] )
, key ? bodyConnected ( state ) : bodyNotConnected ( state )
] )
}
const mailchimpNotConnectedMessage = state => {
return h ( 'p' , [
'Connect with MailChimp to automatically sync supporter emails to your MailChimp Email Lists.'
, h ( 'br' )
, h ( 'a' , { props : { href : ` /nonprofits/ ${ app . nonprofit _id } /nonprofit_keys/mailchimp_login ` } } , 'Click here to connect your Mailchimp account.' )
] )
}
const mailchimpConnectedMessage = state => {
return h ( 'p' , [
'Congrats! You Mailchimp account has been connected successfully.'
, h ( 'br' )
, h ( 'a' , { props : { href : ` /nonprofits/ ${ app . nonprofit _id } /supporters?show-modal=mailchimpSettingsModal ` } } , 'Click here to manage your email list sync settings.' )
] )
}
module . exports = { view , init }