Skip to content

Commit

Permalink
Add redirect to user page on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Oct 7, 2015
1 parent d1c0276 commit bc6a9c6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
15 changes: 11 additions & 4 deletions client/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
var mapShareKey = 'map-shares';
var main = window.main || {};

main.mapShareKey = 'map-shares';

var lastCompleted = typeof lastCompleted !== 'undefined' ?
lastCompleted :
'';

function getMapShares() {
var alreadyShared = JSON.parse(localStorage.getItem(mapShareKey) || '[]');
var alreadyShared = JSON.parse(
localStorage.getItem(main.mapShareKey) ||
'[]'
);

if (!alreadyShared || !Array.isArray(alreadyShared)) {
localStorage.setItem(mapShareKey, JSON.stringify([]));
localStorage.setItem(main.mapShareKey, JSON.stringify([]));
alreadyShared = [];
}
return alreadyShared;
Expand All @@ -23,7 +30,7 @@ function setMapShare(id) {
if (!found) {
alreadyShared.push(id);
}
localStorage.setItem(mapShareKey, JSON.stringify(alreadyShared));
localStorage.setItem(main.mapShareKey, JSON.stringify(alreadyShared));
return alreadyShared;
}

Expand Down
31 changes: 31 additions & 0 deletions server/boot/commit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import dedent from 'dedent';
import {
ifNoUserRedirectTo
} from '../utils/middleware';

const sendNonUserToFront = ifNoUserRedirectTo('/');

export default function commit(app) {
const router = app.loopback.Router();
router.get(
'/commit',
commitToNonprofit
);
router.get(
'/commit/pledge',
sendNonUserToFront,
pledge
);

app.use(router);

Expand All @@ -12,4 +24,23 @@ export default function commit(app) {
title: 'Commit to a nonprofit. Commit to your goal.'
});
}

function pledge(req, res) {
const { user } = req;
const {
nonprofit = 'girl develop it',
amount = '5',
goal = 'front end certification'
} = req.query;

req.flash('success', {
msg: dedent`
Congratulations, you have commit to giving ${nonprofit} ${amount}
dollars a month until you have reached your goal
of completing your ${goal}
`
});

res.redirect('/' + user.username);
}
}
8 changes: 7 additions & 1 deletion server/utils/middleware.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export function ifNoUserRedirectTo(url) {
export function ifNoUserRedirectTo(url, message) {
return function(req, res, next) {
const { path } = req;
if (req.user) {
return next();
}

req.flash('errors', {
msg: message || `You must be signed to go to ${path}`
});

return res.redirect(url);
};
}
Expand Down
22 changes: 15 additions & 7 deletions server/views/commit/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,44 @@ block content
img.img-responsive(src='http://i.imgur.com/U1CyEuA.jpg' alt="Girl Develop It participants coding at tables.")
p Girl Develop It is a nonprofit that provides in-person classes for women to learn to code.
.spacer
form.form
form.form(name='commit')
.hidden
input(type='text' value='girl develop it' name='nonprofit')
.row
.col-xs-12.col-sm-6.col-sm-offset-3
h4 Step 1: Choose your goal
.btn-group.btn-group-justified(data-toggle='buttons' role='group')
label.btn.btn-info.active
input(type='radio' id='front-end-development-certificate' name='goal')
input(type='radio' id='front-end-development-certificate' value='front end certification' name='goal' checked="checked")
| Front End Development Certificate (takes about 400 hours)
label.btn.btn-info
input(type='radio' id='full-stack-development-certificate' name='goal')
input(type='radio' id='full-stack-development-certificate' value='full stack certification' name='goal')
| Full Stack Development Certificate (takes about 800 hours)
.spacer
.row
.col-xs-12.col-sm-6.col-sm-offset-3
h4 Step 2: Choose how much you want to donate each month
.btn-group.btn-group-justified(data-toggle='buttons' role='group')
label.btn.btn-primary
input(type='radio' id='5-dollar-pledge' name='pledge-amount')
input(type='radio' id='5-dollar-pledge' value='5' name='amount')
| $5 per month
label.btn.btn-primary.active
input(type='radio' id='10-dollar-pledge' name='pledge-amount')
input(type='radio' id='10-dollar-pledge' value='10' name='amount' checked="checked")
| $10 per month
label.btn.btn-primary
input(type='radio' id='50-dollar-pledge' name='pledge-amount')
input(type='radio' id='50-dollar-pledge' value='50' name='amount')
| $50 per month
.spacer
.row
.col-xs-12.col-sm-6.col-sm-offset-3
h4 Step 3: Commit
a.btn.btn-block.btn-primary(href='https://www.girldevelopit.com/donate') Commit
a#commit-btn-submit.btn.btn-block.btn-primary(href='https://www.girldevelopit.com/donate' target='_blank') Commit
.button-spacer
a.btn.btn-block.btn-warning(href='/') Maybe later
.spacer
script.
$(function() {
$('#commit-btn-submit').click(function() {
window.location.href = '/commit/pledge?' + $('form').serialize();
});
});
15 changes: 15 additions & 0 deletions server/views/commit/pledge.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends ../layout
block content
.panel.panel-info
.panel-body
h3.text-center You've commited!
.row
.col-xs-12.col-sm-6.col-sm-offset-3
p Congratulations, you have commit to giving
span(style='text-transform: capitalize') #{nonprofit}
| #{amount} dollars a month until you have reached your goal
| of completing your #{goal}
.row
.col-xs-12.col-sm-6.col-sm-offset-3
img.img-responsive(src='http://i.imgur.com/U1CyEuA.jpg' alt="Girl Develop It participants coding at tables.")
p Girl Develop It is a nonprofit that provides in-person classes for women to learn to code.

0 comments on commit bc6a9c6

Please sign in to comment.