Add stop commit functionality
This commit is contained in:
@ -18,6 +18,10 @@ import {
|
||||
} from '../utils/middleware';
|
||||
|
||||
const sendNonUserToFront = ifNoUserRedirectTo('/');
|
||||
const sendNonUserToCommit = ifNoUserRedirectTo(
|
||||
'/commit',
|
||||
'Must be signed in to update commit'
|
||||
);
|
||||
const debug = debugFactory('freecc:commit');
|
||||
|
||||
function findNonprofit(name) {
|
||||
@ -47,6 +51,12 @@ export default function commit(app) {
|
||||
pledge
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/commit/stop-commitment',
|
||||
sendNonUserToCommit,
|
||||
stopCommit
|
||||
);
|
||||
|
||||
app.use(router);
|
||||
|
||||
function commitToNonprofit(req, res, next) {
|
||||
@ -143,4 +153,32 @@ export default function commit(app) {
|
||||
next
|
||||
);
|
||||
}
|
||||
|
||||
function stopCommit(req, res, next) {
|
||||
const { user } = req;
|
||||
|
||||
observeQuery(user, 'pledge')
|
||||
.flatMap(pledge => {
|
||||
if (!pledge) {
|
||||
return Observable.just();
|
||||
}
|
||||
|
||||
pledge.formerUserId = pledge.userId;
|
||||
pledge.userId = null;
|
||||
pledge.isOrphaned = true;
|
||||
pledge.dateEnded = new Date();
|
||||
return saveInstance(pledge);
|
||||
})
|
||||
.subscribe(
|
||||
pledge => {
|
||||
let msg = `You have successfully stopped your pledge.`;
|
||||
if (!pledge) {
|
||||
msg = `No pledge found for user ${user.username}.`;
|
||||
}
|
||||
req.flash('errors', { msg });
|
||||
return res.redirect('/commit');
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ block content
|
||||
h3.text-center Commit to yourself. Commit to a nonprofit.
|
||||
.row
|
||||
.col-xs-12.col-sm-6.col-sm-offset-3
|
||||
p Give yourself ongoing motivation and help nonprofits right away. Pledge a monthly donation to a nonprofit until you’ve earned either your Front End or Full Stack Development Certification.
|
||||
p Give yourself external motivation and help nonprofits right away. Pledge a monthly donation to a nonprofit until you’ve earned either your Front End or Full Stack Development Certification.
|
||||
.row
|
||||
.col-xs-12.col-sm-6.col-sm-offset-3.text-center
|
||||
h4 Pledge to #{displayName}
|
||||
@ -47,8 +47,17 @@ block content
|
||||
.col-xs-12.col-sm-6.col-sm-offset-3.text-center
|
||||
a#commit-btn-submit.btn.btn-block.btn-lg.signup-btn(href='https://www.girldevelopit.com/donate' target='_blank') Commit (and open donate page)
|
||||
.button-spacer
|
||||
.spacer
|
||||
if pledge
|
||||
form.row(name='stop-pledge' action='/commit/stop-commitment' method='post')
|
||||
.col-xs-12.col-sm-6.col-sm-offset-3.text-center
|
||||
button.btn.btn-sm.btn-danger(name='submit' type='submit') Stop my pledge
|
||||
.spacer
|
||||
else
|
||||
.row
|
||||
.col-xs-12.col-sm-6.col-sm-offset-3.text-center
|
||||
a(href='/') Maybe later
|
||||
.spacer
|
||||
.spacer
|
||||
script.
|
||||
$(function() {
|
||||
$('#commit-btn-submit').click(function() {
|
||||
|
Reference in New Issue
Block a user