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 marked = require ( 'marked' )
const format = require ( '../../../../common/format' )
// generate titles and bodies from activity json data
const pathPrefix = ` /nonprofits/ ${ app . nonprofit _id } `
module . exports = exports = { }
const viewPaymentLink = data =>
h ( 'p' , [ h ( 'a' , { props : { href : ` ${ pathPrefix } /payments?pid= ${ data . attachment _id } ` } } , 'View payment details.' ) ] )
exports . RecurringDonation = ( data , state ) => {
return {
title : ` Paid $ ${ format . centsToDollars ( data . json _data . gross _amount ) } towards a recurring donation `
, body : [
viewDedication ( data )
, h ( 'p' , ` Started on ${ format . date . toSimple ( data . json _data . start _date ) } . ` )
, viewPaymentLink ( data )
]
, icon : 'fa-heart'
}
}
const viewDedication = data =>
data . json _data . dedication && data . json _data . dedication . name
? h ( "p" , [
` Dedicated in ${ data . json _data . dedication . type || 'honor' } of `
, h ( 'a' , { props : { href : ` /nonprofits/ ${ ENV . nonprofitID } /supporters?sid= ${ data . json _data . dedication . supporter _id } ` } } , data . json _data . dedication . name )
] )
: ''
exports . Donation = ( data , state ) => {
const desig = data . json _data . designation ? h ( 'p' , ` Designation: ${ data . json _data . designation } . ` ) : ''
return {
title : ` Donated $ ${ format . centsToDollars ( data . json _data . gross _amount ) } `
, body : [
desig
, viewDedication ( data )
, viewPaymentLink ( data )
]
, icon : 'fa-heart'
}
}
exports . Ticket = ( data , state ) => {
var paren = data . json _data . gross _amount ? ` (totalling $ ${ format . centsToDollars ( data . json _data . gross _amount ) } ) ` : '(for free)'
return {
title : ` Redeemed ${ data . json _data . quantity } tickets ${ paren } for the event: ${ data . json _data . event _name } `
, body : ''
, icon : 'fa-ticket'
}
}
exports . Refund = ( data , state ) => {
return {
title : ` Refunded $ ${ format . centsToDollars ( - data . json _data . gross _amount ) } `
, body : [
h ( 'span' , ` Reason: ${ format . snake _to _words ( data . json _data . reason || 'none' ) } . ` )
, h ( 'br' )
, viewPaymentLink ( data )
]
, icon : 'fa-reply'
}
}
exports . Dispute = ( data , state ) => {
return {
title : ` This supporter disputed (made a charge-back) on their payment for $ ${ format . centsToDollars ( data . json _data . gross _amount ) } on ${ format . date . toSimple ( data . json _data . original _date ) } `
, body : [
h ( 'span' , ` Reason given: ${ format . snake _to _words ( data . json _data . reason || 'none' ) } . ` )
, h ( 'br' )
, viewPaymentLink ( data )
]
, icon : 'fa-ban'
}
}
exports . SupporterNote = ( data , state ) => {
const action = data . created _at === data . updated _at ? 'added' : 'edited'
const canEdit = data . user _id === app . user _id
return {
title : ` Note ${ action } ${ data . json _data . user _email ? ' by ' + data . json _data . user _email : '' } `
, body : [
h ( 'span' , { props : { innerHTML : marked ( data . json _data . content ? data . json _data . content : '' ) } } )
, canEdit
? h ( 'span' , [
h ( 'a.u-marginRight--10' , { on : { click : [ state . editNote$ , data ] } } , 'Edit ' )
, h ( 'span.u-color--red.u-pointer' , { on : { click : [ state . deleteNote$ , data ] } } , 'Delete' )
] )
: ''
]
, icon : 'fa-pencil'
}
}
exports . SupporterEmail = ( data , state ) => {
var jd = data . json _data
var canView = jd . from === state . gmail . from$ ( )
var body = [ h ( 'span' , ` Subject: ${ jd . subject } ` ) , h ( 'br' ) ]
var thread = h ( 'a' , { props : { href : '#' } , on : { click : [ state . threadId$ , jd . gmail _thread _id ] } } , 'View thread' )
var signIn = h ( 'small' , [
h ( 'a' , { props : { href : '#' } , on : { click : state . gmail . newSignIn$ } } , 'Sign in' )
, ` as ${ jd . from } to view thread ` ] )
return {
title : ` Email thread started by ${ jd . from } `
, icon : 'fa-envelope'
, body : canView ? R . concat ( body , thread ) : R . concat ( body , signIn )
}
}
exports . OffsitePayment = ( data , state ) => {
const desig = data . json _data . designation ? ` Designation: ${ data . json _data . designation } . ` : ''
return {
title : ` Donated $ ${ format . centsToDollars ( data . json _data . gross _amount ) } (offsite) `
, body : [
h ( 'span' , desig )
, desig ? h ( 'br' ) : ''
, viewPaymentLink ( data )
]
, icon : 'fa-money'
}
}