-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onboarding): Simplify onboarding process (#409)
Closes #163. ## Changes - after signing up, new users are directly brought to their stream - a "add a track" button was added at the top of the stream - a "other recent tracks" link (to `/all`) was added at the top of the steam - `/button` and `/bookmarklet` lead to the same page (from the onboarding process) => previous versions were removed - featured users were added, for the welcome email - bonus: speed up restart with docker-compose ## Results <img width="1280" alt="Capture d’écran 2020-11-28 à 17 02 08" src="https://user-images.githubusercontent.com/531781/100520443-ff6ea580-319d-11eb-8049-5d48e6a54050.png"> <img width="1280" alt="Capture d’écran 2020-11-28 à 17 19 11" src="https://user-images.githubusercontent.com/531781/100520425-ebc33f00-319d-11eb-986c-04faa575ac0d.png"> ## ... instead of <img width="1280" alt="Capture d’écran 2020-11-28 à 15 44 14" src="https://user-images.githubusercontent.com/531781/100520454-0bf2fe00-319e-11eb-9b18-593f3749afce.png"> [legacy bookmarklet chrome.pdf](https://github.com/openwhyd/openwhyd/files/5610884/legacy.bookmarklet.chrome.pdf) [legacy bookmarklet firefox.pdf](https://github.com/openwhyd/openwhyd/files/5610885/legacy.bookmarklet.firefox.pdf)
- Loading branch information
1 parent
46a7fb1
commit ec40c7d
Showing
43 changed files
with
113 additions
and
1,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,25 @@ | ||
/** | ||
* onboarding controller | ||
* handles the onboarding process (for new users) | ||
* @author adrienjoly, whyd | ||
* explains how to install the bookmarklet or chrome extension | ||
*/ | ||
|
||
// testing phase 3: send welcome email | ||
// $ curl -v --data "ajax=follow" --cookie "whydSid=4j8OSWWYknxyPlmGmgqURg12AiBoKDQpqt4iU610PT9nKkIkRdlMgHWF9kFMsQEvU" http://openwhyd.org/onboarding | ||
|
||
var mongodb = require('../models/mongodb.js'); | ||
var userModel = require('../models/user.js'); | ||
var followModel = require('../models/follow.js'); | ||
var analytics = require('../models/analytics.js'); | ||
var notifModel = require('../models/notif.js'); | ||
var notifEmails = require('../models/notifEmails.js'); | ||
|
||
var TEMPLATE_FILE = 'app/templates/onboarding.html'; | ||
var mainTemplate = require('../templates/mainTemplate.js'); | ||
var templateLoader = require('../templates/templateLoader.js'); | ||
const { getSuggestedUsers } = require('../models/featuredUsers.js'); | ||
|
||
// var MAX_RECOM_USERS = 10; | ||
|
||
var templates = { | ||
'bookmarklet-legacy': 'app/templates/onboarding/bookmarklet.html', // old version (still bound to openwhyd.org/bookmarklet and openwhyd.org/button) | ||
}; | ||
|
||
function makeTemplateRenderer(cb) { | ||
return function (p) { | ||
templateLoader.loadTemplate(templates[p.step] || TEMPLATE_FILE, function ( | ||
template | ||
) { | ||
p.content = template.render(p); | ||
cb(p); | ||
}); | ||
}; | ||
} | ||
|
||
var processAjax = { | ||
people: function (_, cb) { | ||
getSuggestedUsers().then(cb); | ||
}, | ||
follow: function (p, cb) { | ||
userModel.fetchByUid(p.loggedUser.id, function (user) { | ||
console.log('onboarding, sending welcome email', user.email, user.iBy); | ||
var inviteSender = user.iBy ? mongodb.getUserFromId(user.iBy) : null; | ||
notifEmails.sendRegWelcomeAsync(user, inviteSender); | ||
}); | ||
|
||
console.log('onboarding, following uids:', p.uids); | ||
var uids = (p.uids || '').split(','); | ||
(function next() { | ||
var uid = uids.pop(); | ||
if (uid) | ||
followModel.add( | ||
{ | ||
uId: p.loggedUser.id, | ||
uNm: p.loggedUser.name, | ||
tId: uid, | ||
tNm: mongodb.getUserNameFromId(uid), | ||
ctx: 'onb', // onb = onboarding context | ||
}, | ||
function () { | ||
console.log('onboarding, followed uid', uid); | ||
notifModel.subscribedToUser(p.loggedUser.id, uid, next); | ||
} | ||
); | ||
})(); | ||
cb({ ok: true }); | ||
}, | ||
}; | ||
|
||
var processStep = { | ||
people: function (p, render) { | ||
(p.css = p.css || []).push('onboarding.css'); | ||
p.bodyClass = 'pgOnboarding stepPeople minimalHeader'; | ||
p.stepPeople = true; | ||
render(p); | ||
}, | ||
button: function (p, render) { | ||
(p.css = p.css || []).push('onboarding.css'); | ||
p.bodyClass = 'pgOnboarding stepButton minimalHeader'; | ||
p.stepButton = true; | ||
render(p); | ||
}, | ||
'bookmarklet-legacy': function (p, render) { | ||
render(p); | ||
}, | ||
}; | ||
|
||
function handleRequest(p, cb) { | ||
if (p.ajax && processAjax[p.ajax]) { | ||
processAjax[p.ajax](p, cb); | ||
} else { | ||
var lastUrlWord = p.pageUrl.split('?')[0].split('/')[1]; | ||
if (lastUrlWord == 'bookmarklet' || lastUrlWord == 'button') | ||
p.step = 'bookmarklet-legacy'; | ||
|
||
var processor = processStep[p.step]; | ||
if (!processor) cb({ error: 'unknown step' }); | ||
//cb({redirect:"/"}); | ||
else { | ||
processor(p, makeTemplateRenderer(cb)); | ||
analytics.addVisit(p.loggedUser, p.pageUrl); | ||
} | ||
} | ||
} | ||
|
||
exports.controller = function (request, getParams, response) { | ||
var p = | ||
(request.method.toLowerCase() === 'post' ? request.body : getParams) || {}; | ||
request.logToConsole('onboarding.controller ' + request.method, p); | ||
// make sure user is logged in | ||
if (!(p.loggedUser = request.checkLogin(response))) return; | ||
p.pageUrl = request.url; | ||
handleRequest(p, function (r) { | ||
if (!r || r.error) { | ||
r = r || {}; | ||
console.log(r.error); | ||
//response.temporaryRedirect("/welcome"); | ||
} else if (r.content) r.html = mainTemplate.renderWhydPage(r); | ||
|
||
if (r.redirect) response.temporaryRedirect(r.redirect); | ||
else if (r.html) response.renderHTML(r.html); | ||
else response.renderJSON(r); | ||
request.logToConsole('onboarding.controller', getParams); | ||
var loggedUser = request.getUser() || {}; | ||
templateLoader.loadTemplate(TEMPLATE_FILE, function (template) { | ||
const p = { | ||
pageUrl: request.url, | ||
loggedUser: loggedUser, | ||
css: ['onboarding.css'], | ||
bodyClass: 'pgOnboarding', | ||
content: template.render(), | ||
}; | ||
response.renderHTML(mainTemplate.renderWhydPage(p)); | ||
analytics.addVisit(loggedUser.id, request.url); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.