Add redirect to user page on submit

This commit is contained in:
Berkeley Martinez
2015-10-06 00:13:51 -07:00
parent d1c0276f4e
commit bc6a9c6db2
5 changed files with 79 additions and 12 deletions

View File

@ -1,12 +1,19 @@
var mapShareKey = 'map-shares'; var main = window.main || {};
main.mapShareKey = 'map-shares';
var lastCompleted = typeof lastCompleted !== 'undefined' ? var lastCompleted = typeof lastCompleted !== 'undefined' ?
lastCompleted : lastCompleted :
''; '';
function getMapShares() { function getMapShares() {
var alreadyShared = JSON.parse(localStorage.getItem(mapShareKey) || '[]'); var alreadyShared = JSON.parse(
localStorage.getItem(main.mapShareKey) ||
'[]'
);
if (!alreadyShared || !Array.isArray(alreadyShared)) { if (!alreadyShared || !Array.isArray(alreadyShared)) {
localStorage.setItem(mapShareKey, JSON.stringify([])); localStorage.setItem(main.mapShareKey, JSON.stringify([]));
alreadyShared = []; alreadyShared = [];
} }
return alreadyShared; return alreadyShared;
@ -23,7 +30,7 @@ function setMapShare(id) {
if (!found) { if (!found) {
alreadyShared.push(id); alreadyShared.push(id);
} }
localStorage.setItem(mapShareKey, JSON.stringify(alreadyShared)); localStorage.setItem(main.mapShareKey, JSON.stringify(alreadyShared));
return alreadyShared; return alreadyShared;
} }

View File

@ -1,9 +1,21 @@
import dedent from 'dedent';
import {
ifNoUserRedirectTo
} from '../utils/middleware';
const sendNonUserToFront = ifNoUserRedirectTo('/');
export default function commit(app) { export default function commit(app) {
const router = app.loopback.Router(); const router = app.loopback.Router();
router.get( router.get(
'/commit', '/commit',
commitToNonprofit commitToNonprofit
); );
router.get(
'/commit/pledge',
sendNonUserToFront,
pledge
);
app.use(router); app.use(router);
@ -12,4 +24,23 @@ export default function commit(app) {
title: 'Commit to a nonprofit. Commit to your goal.' 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);
}
} }

View File

@ -1,8 +1,14 @@
export function ifNoUserRedirectTo(url) { export function ifNoUserRedirectTo(url, message) {
return function(req, res, next) { return function(req, res, next) {
const { path } = req;
if (req.user) { if (req.user) {
return next(); return next();
} }
req.flash('errors', {
msg: message || `You must be signed to go to ${path}`
});
return res.redirect(url); return res.redirect(url);
}; };
} }

View File

@ -13,16 +13,18 @@ block content
img.img-responsive(src='http://i.imgur.com/U1CyEuA.jpg' alt="Girl Develop It participants coding at tables.") 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. p Girl Develop It is a nonprofit that provides in-person classes for women to learn to code.
.spacer .spacer
form.form form.form(name='commit')
.hidden
input(type='text' value='girl develop it' name='nonprofit')
.row .row
.col-xs-12.col-sm-6.col-sm-offset-3 .col-xs-12.col-sm-6.col-sm-offset-3
h4 Step 1: Choose your goal h4 Step 1: Choose your goal
.btn-group.btn-group-justified(data-toggle='buttons' role='group') .btn-group.btn-group-justified(data-toggle='buttons' role='group')
label.btn.btn-info.active 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) | Front End Development Certificate (takes about 400 hours)
label.btn.btn-info 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) | Full Stack Development Certificate (takes about 800 hours)
.spacer .spacer
.row .row
@ -30,19 +32,25 @@ block content
h4 Step 2: Choose how much you want to donate each month h4 Step 2: Choose how much you want to donate each month
.btn-group.btn-group-justified(data-toggle='buttons' role='group') .btn-group.btn-group-justified(data-toggle='buttons' role='group')
label.btn.btn-primary 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 | $5 per month
label.btn.btn-primary.active 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 | $10 per month
label.btn.btn-primary 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 | $50 per month
.spacer .spacer
.row .row
.col-xs-12.col-sm-6.col-sm-offset-3 .col-xs-12.col-sm-6.col-sm-offset-3
h4 Step 3: Commit 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 .button-spacer
a.btn.btn-block.btn-warning(href='/') Maybe later a.btn.btn-block.btn-warning(href='/') Maybe later
.spacer .spacer
script.
$(function() {
$('#commit-btn-submit').click(function() {
window.location.href = '/commit/pledge?' + $('form').serialize();
});
});

View File

@ -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.