diff --git a/server/boot/commit.js b/server/boot/commit.js index c04169f732..7e4b7c21c0 100644 --- a/server/boot/commit.js +++ b/server/boot/commit.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import { Observable } from 'rx'; import debugFactory from 'debug'; import dedent from 'dedent'; import nonprofits from '../utils/commit.json'; @@ -48,19 +49,46 @@ export default function commit(app) { app.use(router); - function commitToNonprofit(req, res) { + function commitToNonprofit(req, res, next) { + const { user } = req; let nonprofitName = unDasherize(req.query.nonprofit); - const nonprofit = findNonprofit(nonprofitName); debug('looking for nonprofit', nonprofitName); + const nonprofit = findNonprofit(nonprofitName); + + Observable.just(user) + .flatMap(user => { + if (user) { + debug('getting user pledge'); + return observeQuery(user, 'pledge'); + } + return Observable.just(); + }) + .subscribe( + pledge => { + if (pledge) { + debug('found previous pledge'); + req.flash('info', { + msg: dedent` + Looks like you already have a pledge to ${pledge.displayName}. + Hitting commit here will replace your old commitment. + ` + }); + } + res.render( + 'commit/', + Object.assign( + { + title: 'Commit to a nonprofit. Commit to your goal.', + pledge + }, + nonprofit + ) + ); + }, + next + ); - res.render( - 'commit/', - Object.assign( - { title: 'Commit to a nonprofit. Commit to your goal.' }, - nonprofit - ) - ); } function pledge(req, res, next) { @@ -114,6 +142,5 @@ export default function commit(app) { }, next ); - } } diff --git a/server/utils/commit.json b/server/utils/commit.json index 41d16d36c8..c0e09277c4 100644 --- a/server/utils/commit.json +++ b/server/utils/commit.json @@ -6,5 +6,13 @@ "description": "Girl Develop It provides in-person classes for women to learn to code.", "imgAlt": "Girl Develop It participants coding at tables.", "imgUrl": "http://i.imgur.com/U1CyEuA.jpg" + }, + { + "name": "black girls code", + "displayName": "Black Girls CODE", + "donateUrl": "http://www.blackgirlscode.com/", + "description": "Black Girls CODE is devoted to showing the world that black girls can code, and do so much more.", + "imgAlt": "Girls developing code with instructor", + "imgUrl": "http://i.imgur.com/HBVrdaj.jpg" } ] diff --git a/server/views/account/show.jade b/server/views/account/show.jade index ae7c9a3e0e..267d281b20 100644 --- a/server/views/account/show.jade +++ b/server/views/account/show.jade @@ -60,9 +60,10 @@ block content h1.flat-top.text-primary= "[ " + (progressTimestamps.length) + " ]" if pledge .spacer - h4 I am commited to giving $#{pledge.amount} to - a(href='#{pledge.donate}') #{pledge.displayName} - | each month until I have complete the #{pledge.goal} + h4 + | This camper has committed to giving $#{pledge.amount} to + a(href='#{pledge.donateUrl}?ref=freecodecamp.com' target='_blank') #{pledge.displayName} + | each month until they have completed the #{pledge.goal} .spacer if isFrontEndCert a.btn.btn-primary(href='/' + username + '/front-end-certification') View My Front End Development Certification @@ -174,6 +175,10 @@ block content a.btn.btn-lg.btn-block.btn-info.btn-link-social(href='/toggle-lockdown-mode') span.ion-unlocked | Let other people see all my solutions + .col-xs-12 + a.btn.btn-lg.btn-block.btn-success.btn-link-social(href='/commit') + span.ion-android-exit + | Edit my pledge .col-xs-12 a.btn.btn-lg.btn-block.btn-warning.btn-link-social(href='/logout') span.ion-android-exit