Onboarding guide and initial achievements refactoring (#11536)
* add achievements to user * add placeholder strings * add to achievements to common script * add onboarding achievements category * add notifications * more notifications * award achievements * wip notification panel * add achievements icons and copy * do not count onboarding tasks for the created task achievement * add notes * sprites, fixes and completion status and reward * add onboarding panel * add toggle * fix toggle size * fix tests * fix typo * add notification * start adding modal * fix remove button positionin, timeout, progress bar * modal + fixes * disable broken social links from level up modal * change toggle icon color on hover * add border bottom to onboarding guide panel * add collapse animation * expanded onboarding on first open * onboarding: flip toggle colors * onboarding: show progress bar all the time * onboarding: fix panel closing on click * onboarding modal: add close icon and fix padding * wip: add migration for existing users * fix titles in guide * fix achievements copy * do not award completed task achievement when direction is down * start implementing new achievements * start migrating client * remove social links from achievements modals * prevent skipping tutorial + fix achievement notification * sync fixes * start redesign achievement modal * misc fixes to achievements, polish generic achievement modal and hatched pet modal * add special badge for onboarding * fix badge condition * modals fixes * hatched pet modal: add close icon * fix badge typo * fix justin button * new scrolling behavior for dropdowns * fix strings capitalization * add common tests * add api unit tests * add date check * achievements modal polishing * typos * add toggle for achievements categories * typo * fix test * fix edit avatar modal cannot be closed * finish migration and correct launch date * fix migration * migration fixes * fix tests
This commit is contained in:
@@ -65,6 +65,8 @@ function _populateDefaultTasks (user, taskTypes) {
|
||||
// @TODO: default tasks are handled differently now, and not during registration.
|
||||
// We should move this code
|
||||
|
||||
// TODO why isn't this using createTasks from libs/tasksManager?
|
||||
|
||||
const tasksToCreate = [];
|
||||
if (user.registeredThrough === 'habitica-web') return Promise.all(tasksToCreate);
|
||||
|
||||
|
||||
@@ -231,6 +231,59 @@ schema.statics.pushNotification = async function pushNotification (
|
||||
).exec();
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds an achievement and a related notification to the user.
|
||||
*
|
||||
* @param achievement The key identifying the achievement to award.
|
||||
*/
|
||||
schema.methods.addAchievement = function addAchievement (achievement) {
|
||||
const achievementData = common.content.achievements[achievement];
|
||||
if (!achievementData) throw new Error(`Achievement ${achievement} does not exist.`);
|
||||
|
||||
this.achievements[achievement] = true;
|
||||
|
||||
this.notifications.push({
|
||||
type: 'ACHIEVEMENT',
|
||||
data: {
|
||||
achievement,
|
||||
},
|
||||
seen: false,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Adds an achievement and a related notification to the user, saving it directly to the database
|
||||
* To be used when the user object is not loaded or we don't want to use `user.save`
|
||||
*
|
||||
* @param query A Mongoose query defining the users to add the notification to.
|
||||
* @param achievement The key identifying the achievement to award.
|
||||
*/
|
||||
schema.statics.addAchievementUpdate = async function addAchievementUpdate (query, achievement) {
|
||||
const achievementData = common.content.achievements[achievement];
|
||||
if (!achievementData) throw new Error(`Achievement ${achievement} does not exist.`);
|
||||
|
||||
const newNotification = new UserNotification({
|
||||
type: 'ACHIEVEMENT',
|
||||
data: {
|
||||
achievement,
|
||||
},
|
||||
seen: false,
|
||||
});
|
||||
|
||||
const validationResult = newNotification.validateSync();
|
||||
if (validationResult) throw validationResult;
|
||||
|
||||
await this.update(
|
||||
query,
|
||||
{
|
||||
$push: { notifications: newNotification.toObject() },
|
||||
$set: { [`achievements.${achievement}`]: true },
|
||||
},
|
||||
{ multi: true },
|
||||
).exec();
|
||||
};
|
||||
|
||||
// Static method to add/remove properties to a JSON User object,
|
||||
// For example for when the user is returned using `.lean()` and thus doesn't
|
||||
// have access to any mongoose helper
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import mongoose from 'mongoose';
|
||||
import validator from 'validator';
|
||||
import shared from '../../../common';
|
||||
import { schema as TagSchema } from '../tag';
|
||||
import { schema as PushDeviceSchema } from '../pushDevice';
|
||||
import { schema as WebhookSchema } from '../webhook';
|
||||
import {
|
||||
schema as UserNotificationSchema,
|
||||
} from '../userNotification';
|
||||
import {
|
||||
schema as SubscriptionPlanSchema,
|
||||
} from '../subscriptionPlan';
|
||||
import { // eslint-disable-line import/no-cycle
|
||||
getDefaultOwnedGear,
|
||||
} from '../../libs/items/utils';
|
||||
import { schema as PushDeviceSchema } from '../pushDevice';
|
||||
import { schema as SubscriptionPlanSchema } from '../subscriptionPlan';
|
||||
import { schema as TagSchema } from '../tag';
|
||||
import { schema as UserNotificationSchema } from '../userNotification';
|
||||
import { schema as WebhookSchema } from '../webhook';
|
||||
|
||||
const { Schema } = mongoose;
|
||||
|
||||
@@ -134,6 +130,12 @@ export default new Schema({
|
||||
undeadUndertaker: Boolean,
|
||||
primedForPainting: Boolean,
|
||||
pearlyPro: Boolean,
|
||||
// Onboarding Guide
|
||||
createdTask: Boolean,
|
||||
completedTask: Boolean,
|
||||
hatchedPet: Boolean,
|
||||
fedPet: Boolean,
|
||||
purchasedEquipment: Boolean,
|
||||
},
|
||||
|
||||
backer: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import mongoose from 'mongoose';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import validator from 'validator';
|
||||
import _ from 'lodash';
|
||||
import baseModel from '../libs/baseModel';
|
||||
|
||||
const NOTIFICATION_TYPES = [
|
||||
@@ -33,6 +33,7 @@ const NOTIFICATION_TYPES = [
|
||||
'NEW_STUFF',
|
||||
'NEW_CHAT_MESSAGE',
|
||||
'LEVELED_UP',
|
||||
'ONBOARDING_COMPLETE',
|
||||
'ACHIEVEMENT_ALL_YOUR_BASE',
|
||||
'ACHIEVEMENT_BACK_TO_BASICS',
|
||||
'ACHIEVEMENT_JUST_ADD_WATER',
|
||||
@@ -49,6 +50,7 @@ const NOTIFICATION_TYPES = [
|
||||
'ACHIEVEMENT_UNDEAD_UNDERTAKER',
|
||||
'ACHIEVEMENT_PRIMED_FOR_PAINTING',
|
||||
'ACHIEVEMENT_PEARLY_PRO',
|
||||
'ACHIEVEMENT', // generic achievement notification, details inside `notification.data`
|
||||
];
|
||||
|
||||
const { Schema } = mongoose;
|
||||
|
||||
Reference in New Issue
Block a user