Skip to content

Commit

Permalink
remove ramda from nonprofits (incomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
hejkal committed Dec 19, 2024
1 parent 90e9499 commit 749a267
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 50 deletions.
3 changes: 1 addition & 2 deletions client/js/nonprofits/dashboard/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ todos(function(data, url) {
})

// the only ff component so far on this page is events listings
const R = require('ramda')
const h = require('snabbdom/h')
const flyd = require('flyd')
const render = require('ff-core/render')
Expand All @@ -54,7 +53,7 @@ const view = state => {
return mixin([h('p.u-padding--15.u-centered', 'Loading...')])
if(!state.resp$().body.length)
return mixin([h('p.u-padding--15.u-centered', `None currently`)])
return mixin(R.map(listing, state.resp$().body))
return mixin(state.resp$().body.map(listing));
}

var container = document.querySelector('#js-eventsListing')
Expand Down
6 changes: 3 additions & 3 deletions client/js/nonprofits/donate/amount-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function amountFields(state) {
h('button.button.u-width--full.white.amount', {
class: {'is-selected': state.buttonAmountSelected$() && state.donation$().amount === amt.amount*100}
, on: {click: ev => {
state.evolveDonation$({amount: R.always(dollarsToCents(amt.amount))})
state.evolveDonation$({amount: () => dollarsToCents(amt.amount)})
state.buttonAmountSelected$(true)
state.currentStep$(1) // immediately advance steps when selecting an amount button
} }
Expand All @@ -172,10 +172,10 @@ function amountFields(state) {
, on: {
focus: ev => {
state.buttonAmountSelected$(false)
state.evolveDonation$({amount: R.always(dollarsToCents(ev.currentTarget.value))})
state.evolveDonation$({amount: () => dollarsToCents(ev.currentTarget.value)})
}
, input: ev => {
state.evolveDonation$({amount: R.always(dollarsToCentsSafe(ev.currentTarget.value))})
state.evolveDonation$({amount: () => dollarsToCentsSafe(ev.currentTarget.value)})
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// License: LGPL-3.0-or-later
import {map as Rmap} from 'ramda';
import { CustomFieldDescription } from '../../../types';
import customField from './customField';
const h = require('snabbdom/h');

export function customFields(fields?:CustomFieldDescription[]|null): ReturnType<typeof h> | '' {
if (!fields) return '';

return h('div', Rmap(customField, fields));
return h('div', fields.map(customField));
}
6 changes: 2 additions & 4 deletions client/js/nonprofits/donate/get-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ module.exports = params => {
multiple_designations: splitParam
, custom_amounts: parseCustomAmounts
, custom_fields: parseCustomFields
, tags: tags => R.map(tag => {
return tag.trim()
}, R.split(',', tags))
, tags: tags => tags.split(',').map(tag => tag.trim())
})

const outputParams = R.compose(evolve, merge)(params)
const outputParams = evolve(merge(params))
if (window.app && window.app.widget && window.app.widget.custom_amounts) {
outputParams.custom_amounts = window.app.widget.custom_amounts
}
Expand Down
12 changes: 6 additions & 6 deletions client/js/nonprofits/donate/info-step.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// License: LGPL-3.0-or-later
const h = require('snabbdom/h')
const R = require('ramda')
const pick = require('lodash/pick');
const flyd = require('flyd')
const uuid = require('uuid')
const supporterFields = require('../../components/supporter-fields')
Expand Down Expand Up @@ -30,10 +30,10 @@ function init(donation$, parentState) {
// Save supporter for dedication logic
state.dedicationData$ = flyd.map(form => serialize(form, {hash: true}), state.submitDedication$)
const dedicationSuppData$ = flyd.map(
data => R.merge(
R.pick(['phone', 'email', 'address'], data)
, {name: `${data.first_name||''} ${data.last_name||''}`}
)
data => ({
...pick(data, ['phone', 'email', 'address'])
, name: `${data.first_name||''} ${data.last_name||''}`
})
, state.dedicationData$
)
state.showDedicationForm$ = flyd.map(()=> false, state.submitDedication$)
Expand Down Expand Up @@ -64,7 +64,7 @@ const postSupporter = supporter =>
, request({
method: 'post'
, path: `/nonprofits/${app.nonprofit_id}/supporters`
, send: {supporter: R.merge(supporter, {locale: I18n.locale})}
, send: {supporter: {...supporter, locale: I18n.locale } }
}).load
)

Expand Down
8 changes: 4 additions & 4 deletions client/js/nonprofits/donate/payment-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function init(state) {
const donationWithCardToken$ = flyd.lift(R.assoc('token'), cardToken$, donationWithAmount$)

// Set the sepa transfer details ID into the donation object when it is saved
const sepaId$ = flyd.map(R.prop('id'), state.sepaForm.saved$)
const sepaId$ = flyd.map(s => s.id, state.sepaForm.saved$)
const donationWithSepaId$ = flyd.lift(R.assoc('direct_debit_detail_id'), sepaId$, state.donation$)

state.donationParams$ = flyd.immediate(
Expand Down Expand Up @@ -193,7 +193,7 @@ function init(state) {
}

const postGiftOption = (campaign_gift_option_id, result) => {
return flyd.map(R.prop('body'), request({
return flyd.map(r => r.body, request({
path: '/campaign_gifts'
, method: 'post'
, send: {
Expand All @@ -211,7 +211,7 @@ const postTracking = (utmParams, donationResponse) => {
const params = R.merge(utmParams, { donation_id: donationResponse().donation.id })

if (utmParams.utm_source || utmParams.utm_medium || utmParams.utm_content || utmParams.utm_campaign) {
return flyd.map(R.prop('body'), request({
return flyd.map(r => r.body, request({
path: `/nonprofits/${app.nonprofit_id}/tracking`
, method: 'post'
, send: params
Expand Down Expand Up @@ -246,7 +246,7 @@ const postDonation = (donation) => {
delete donation.weekly; // needs to be removed to be processed

if (donation.recurring) donation = { recurring_donation: donation }
return flyd.map(R.prop('body'), request({
return flyd.map(r => r.body, request({
path: prefix + postfix
, method: 'post'
, send: donation
Expand Down
25 changes: 13 additions & 12 deletions client/js/nonprofits/payments_chart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// License: LGPL-3.0-or-later
const request = require('../common/client')
const R = require('ramda')
const Chart = require('chart.js')
const Pikaday = require('pikaday')
const moment = require('moment')
Expand Down Expand Up @@ -28,18 +27,20 @@ appl.def('updateChartParams', function(formObj) {
})

// start date Pickaday
new Pikaday(R.merge({
new Pikaday({
field: document.getElementById('js-paymentsChart-startDate')
, maxDate: moment().subtract(1, 'week').toDate()
, defaultDate: moment().subtract(1, 'years').toDate()
}, pickadayDefaults))
, ...pickadayDefaults
})

// end date Pickaday
new Pikaday(R.merge({
new Pikaday({
field: document.getElementById('js-paymentsChart-endDate')
, maxDate: moment().toDate()
, defaultDate: moment().toDate()
}, pickadayDefaults))
, ...pickadayDefaults
})

var ctx = document.getElementById('js-paymentsChart').getContext('2d')

Expand All @@ -56,7 +57,7 @@ function updateChart(params) {
request.get(url)
.query(params)
.end(function(err, resp) {
chart.data.labels = formatLabels(R.pluck('time_span', resp.body), params.timeSpan)
chart.data.labels = formatLabels(resp.body.map(i => i['time_span']), params.timeSpan)
chart.data.datasets = formatDatasets(resp.body)
chart.update()
appl.def('loading_chart', false)
Expand All @@ -66,15 +67,15 @@ function updateChart(params) {
function formatLabels(dates, type) {
switch (type) {
case "year":
return R.map(st => moment(st).format('YYYY'), dates)
return dates.map(st => moment(st).format('YYYY'))
case "month":
return R.map(st => moment(st).format('MMM YYYY'), dates)
return dates.map(st => moment(st).format('MMM YYYY'))
case "week":
return R.map(st =>
return dates.map(st =>
`${moment(st).format('M/D/YY')} - ${moment(st).add(7, 'days').format('M/D/YY')}`
, dates)
)
default:
return R.map(st => moment(st).format(frontendFormat), dates)
return dates.map(st => moment(st).format(frontendFormat))
}
}

Expand All @@ -100,7 +101,7 @@ const formatDatasets = (data) => [
function dataset(label, key, rgb, data) {
return {
label: label
, data: R.pluck(key, data)
, data: data.map(i => i[key])
, borderWidth: 1
, borderColor: `rgb(${rgb})`
, backgroundColor: `rgba(${rgb},0.3)`
Expand Down
3 changes: 1 addition & 2 deletions client/js/nonprofits/recurring_donations/index/index.es6
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
const snabbdom = require('snabbdom')
const flyd = require('flyd')
const h = require('snabbdom/h')
const R = require('ramda')
const modal = require('ff-core/modal')
const render = require('ff-core/render')
const request = require('../../../common/request')

function init() {
var state = {}
state.modalID$ = flyd.stream()
state.data$ = flyd.map(R.prop('body'), request({
state.data$ = flyd.map(r => r.body, request({
path: `/nonprofits/${app.nonprofit_id}/recurring_donation_stats`
, method: 'get'
}).load)
Expand Down
1 change: 0 additions & 1 deletion client/js/nonprofits/reports/modal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// License: LGPL-3.0-or-later
const flyd = require('flyd')
const flyd_filter = require('flyd/module/filter')
const R = require('ramda')
const h = require('snabbdom/h')
const moment = require('moment')

Expand Down
2 changes: 1 addition & 1 deletion client/js/nonprofits/supporter_form/index.es6
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const postRequest = ev => {
}).load
}

const getReqBody = flyd.map(R.prop('body'))
const getReqBody = flyd.map(r => r.body)

const response$ = getReqBody(flatMap(postRequest, submit$))

Expand Down
2 changes: 1 addition & 1 deletion client/js/nonprofits/supporters/import/index.es6
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function init() {

// post to /imports after the file is uploaded to S3
const postImport = R.curry((headers, file) => {
return flyd.map(R.prop('body'), request({
return flyd.map(r => r.body, request({
method: 'post'
, path: `/nonprofits/${app.nonprofit_id}/imports`
, send: {file_uri: file.uri, header_matches: headers}
Expand Down
3 changes: 1 addition & 2 deletions client/js/nonprofits/supporters/index/merge_supporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var action_recipient = require("./action_recipient")
var request = require('../../../common/client')
require('../../../components/wizard')
var formatErr = require('../../../common/format_response_error')
const R = require('ramda')

appl.def('merge.has_any', function(arr) {
var supporters = appl.merge.data.supporters
Expand Down Expand Up @@ -42,7 +41,7 @@ appl.def('merge.init', function(){

appl.def('merge.set', function(form_obj, node) {
var supp = appl.merge.data.new_supporter
appl.def('merge.data.new_supporter', R.merge(supp, form_obj))
appl.def('merge.data.new_supporter', {...supp, ...form_obj})
})

appl.def('merge.select_address', function(supp, node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// License: LGPL-3.0-or-later
const h = require('snabbdom/h')
const R = require('ramda')
const marked = require('marked')

const format = require('../../../../common/format')
Expand Down Expand Up @@ -164,7 +163,7 @@ exports.SupporterEmail = (data, state) => {
title: `Email thread started by ${jd.from}`
, icon: 'fa-envelope'
, body: body
// , body: canView ? R.concat(body, thread) : R.concat(body, signIn)
// , body: canView ? [...body, ...thread] : [...body, ...signIn]
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/js/nonprofits/supporters/index/sidepanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const init = _ => {
const deleteNoteId$ = flyd.map(d => d.attachment_id, state.deleteNote$)

state.noteAjaxMethod$ = mergeAll([
flyd.map(R.always('post'), state.newNote$)
, flyd.map(R.always('put'), state.editNote$)
flyd.map(() => 'post', state.newNote$)
, flyd.map(() => 'put', state.editNote$)
])

state.supporterNoteForm = supporterNoteForm.init(state)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const h = require('snabbdom/h')
const flyd = require('flyd')
const modal = require('ff-core/modal')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const flatMap = require('flyd/module/flatmap')
const flyd = require('flyd')
const h = require('snabbdom/h')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const h = require('snabbdom/h')
const flyd = require('flyd')
const moment = require('moment')
Expand All @@ -11,7 +10,7 @@ const generateContent = require('./generate-content')

function init(parentState) {
const activitiesWithJson$ = flyd.map(
R.map(parseActivityJson)
i => i.map(parseActivityJson)
, parentState.activities$
)
const response$ = flyd.merge(
Expand Down Expand Up @@ -49,7 +48,7 @@ function jsonOrNull(testObj) {
const parseActivityJson = data => {
let json_data = jsonOrNull(data.json_data) || {};
json_data.dedication = tryJSON(json_data.dedication)
return R.merge(data, {json_data})
return {...data, json_data}
}

const view = parentState => {
Expand All @@ -64,7 +63,7 @@ const view = parentState => {
h('p.u-color--grey', 'No activity yet...')
])
}
return h('ul.timeline-activities', R.map(activityContent(parentState), state.response$()))
return h('ul.timeline-activities', state.response$().map(activityContent(parentState)));
}

// used to construct each activitiy list element
Expand Down

0 comments on commit 749a267

Please sign in to comment.