simpliyfied dashboard & fixed error with leave group shown to group owner

- always show the manage button if you are the group owne
- only show the recurly subscription part if you are the subscription owner
- always try and loop through groups you can leave
This commit is contained in:
Henry Oswald 2016-06-15 18:34:56 +01:00
parent 5ce0100371
commit 101e98ed83
4 changed files with 24 additions and 18 deletions

View file

@ -43,7 +43,7 @@ module.exports =
callback err, hasValidSubscription, subscription callback err, hasValidSubscription, subscription
userIsMemberOfGroupSubscription: (user, callback = (error, isMember, subscriptions) ->) -> userIsMemberOfGroupSubscription: (user, callback = (error, isMember, subscriptions) ->) ->
logger.log user_id: user._ud, "checking is user is member of subscription groups" logger.log user_id: user._id, "checking is user is member of subscription groups"
SubscriptionLocator.getMemberSubscriptions user._id, (err, subscriptions = []) -> SubscriptionLocator.getMemberSubscriptions user._id, (err, subscriptions = []) ->
return callback(err) if err? return callback(err) if err?
callback err, subscriptions.length > 0, subscriptions callback err, subscriptions.length > 0, subscriptions

View file

@ -82,9 +82,9 @@ module.exports = SubscriptionController =
logger.log user: user, "redirecting to plans" logger.log user: user, "redirecting to plans"
res.redirect "/user/subscription/plans" res.redirect "/user/subscription/plans"
else else
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription, groups) -> SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription, groupSubscriptions) ->
return next(error) if error? return next(error) if error?
logger.log user: user, subscription:subscription, hasSubOrIsGroupMember:hasSubOrIsGroupMember, groups:groups, "showing subscription dashboard" logger.log user: user, subscription:subscription, hasSubOrIsGroupMember:hasSubOrIsGroupMember, groupSubscriptions:groupSubscriptions, "showing subscription dashboard"
plans = SubscriptionViewModelBuilder.buildViewModel() plans = SubscriptionViewModelBuilder.buildViewModel()
res.render "subscriptions/dashboard", res.render "subscriptions/dashboard",
title: "your_subscription" title: "your_subscription"
@ -92,8 +92,9 @@ module.exports = SubscriptionController =
taxRate:subscription?.taxRate taxRate:subscription?.taxRate
plans: plans plans: plans
subscription: subscription || {} subscription: subscription || {}
groups: groups groupSubscriptions: groupSubscriptions
subscriptionTabActive: true subscriptionTabActive: true
user:user
userCustomSubscriptionPage: (req, res, next)-> userCustomSubscriptionPage: (req, res, next)->

View file

@ -8,7 +8,7 @@ _ = require("underscore")
module.exports = module.exports =
buildUsersSubscriptionViewModel: (user, callback = (error, subscription, groups) ->) -> buildUsersSubscriptionViewModel: (user, callback = (error, subscription, memberSubscriptions) ->) ->
SubscriptionLocator.getUsersSubscription user, (err, subscription) -> SubscriptionLocator.getUsersSubscription user, (err, subscription) ->
return callback(err) if err? return callback(err) if err?
SubscriptionLocator.getMemberSubscriptions user, (err, memberSubscriptions = []) -> SubscriptionLocator.getMemberSubscriptions user, (err, memberSubscriptions = []) ->
@ -19,6 +19,7 @@ module.exports =
RecurlyWrapper.getSubscription subscription.recurlySubscription_id, (err, recurlySubscription)-> RecurlyWrapper.getSubscription subscription.recurlySubscription_id, (err, recurlySubscription)->
tax = recurlySubscription?.tax_in_cents || 0 tax = recurlySubscription?.tax_in_cents || 0
callback null, { callback null, {
admin_id:subscription.admin_id
name: plan.name name: plan.name
nextPaymentDueAt: SubscriptionFormatters.formatDate(recurlySubscription?.current_period_ends_at) nextPaymentDueAt: SubscriptionFormatters.formatDate(recurlySubscription?.current_period_ends_at)
state: recurlySubscription?.state state: recurlySubscription?.state

View file

@ -43,12 +43,8 @@ block content
.card(ng-if="view == 'overview'") .card(ng-if="view == 'overview'")
.page-header .page-header
h1 #{translate("your_subscription")} h1 #{translate("your_subscription")}
-if (groups.length != 0)
each groupSubscription in groups - if (subscription && user._id+'' == subscription.admin_id+'')
p !{translate("member_of_group_subscription", {admin_email: "<strong>" + groupSubscription.admin_id.email + "</strong>"})}
span
button.btn.btn-danger(ng-click="removeSelfFromGroup('#{groupSubscription.admin_id._id}')") #{translate("leave_group")}
- else if (subscription)
case subscription.state case subscription.state
when "free-trial" when "free-trial"
p !{translate("on_free_trial_expiring_at", {expiresAt:"<strong>" + subscription.expiresAt + "</strong>"})} p !{translate("on_free_trial_expiring_at", {expiresAt:"<strong>" + subscription.expiresAt + "</strong>"})}
@ -72,15 +68,9 @@ block content
p !{translate("your_subscription_has_expired")} p !{translate("your_subscription_has_expired")}
a(href="/user/subscription/plans") !{translate("create_new_subscription")} a(href="/user/subscription/plans") !{translate("create_new_subscription")}
default default
-if(groups.length == 0) -if(groupSubscriptions.length == 0)
p !{translate("problem_with_subscription_contact_us")} p !{translate("problem_with_subscription_contact_us")}
-if(subscription.groupPlan)
a(href="/subscription/group").btn.btn-primary !{translate("manage_group")}
div(ng-show="changePlan", ng-cloak)#changePlanSection div(ng-show="changePlan", ng-cloak)#changePlanSection
h2.col-md-7 !{translate("change_plan")} h2.col-md-7 !{translate("change_plan")}
span.dropdown.col-md-1.changePlanButton(ng-controller="CurrenyDropdownController", style="display:none", dropdown) span.dropdown.col-md-1.changePlanButton(ng-controller="CurrenyDropdownController", style="display:none", dropdown)
@ -105,6 +95,20 @@ block content
mixin printPlans(plans.individualMonthlyPlans) mixin printPlans(plans.individualMonthlyPlans)
mixin printPlans(plans.individualAnnualPlans) mixin printPlans(plans.individualAnnualPlans)
each groupSubscription in groupSubscriptions
- if (user._id+'' != groupSubscription.admin_id._id+'')
div
p !{translate("member_of_group_subscription", {admin_email: "<strong>" + groupSubscription.admin_id.email + "</strong>"})}
span
button.btn.btn-danger(ng-click="removeSelfFromGroup('#{groupSubscription.admin_id._id}')") #{translate("leave_group")}
-if(subscription.groupPlan && user._id+'' == subscription.admin_id+'')
div
a(href="/subscription/group").btn.btn-primary !{translate("manage_group")}
.card(ng-if="view == 'cancelation'") .card(ng-if="view == 'cancelation'")
.page-header .page-header
h1 #{translate("Cancel Subscription")} h1 #{translate("Cancel Subscription")}