Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2048: Display premium icons & subscription info & GH-2036: Unlock Plus features on GBE/Midnight for all Premium & Plus users #546

Merged
merged 35 commits into from May 20, 2020
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
901c4fa
Show premium subscribers a premium badge in simple/detailed views, he…
benstrumeyer May 7, 2020
f944c6c
Use api version 2.1.0 to get multiple subscriptions
benstrumeyer May 7, 2020
e035e69
Add hover effect for premium icon in menu
benstrumeyer May 7, 2020
659749b
Use css as single source of truth for icon colors
benstrumeyer May 7, 2020
2a83d42
Handle case where a user has multiple subscriptions and display Premi…
benstrumeyer May 7, 2020
de02e6c
Display subscription name
benstrumeyer May 8, 2020
53378f0
Remove duplicate locale string
benstrumeyer May 8, 2020
a10bd6c
Handle case where user only has a premium subscription and clicks the…
benstrumeyer May 8, 2020
7e552d2
Refactor code
benstrumeyer May 8, 2020
eb43832
Merge branch 'develop' into GH-2048
benstrumeyer May 8, 2020
9eb39bd
Refactor subscriber badge css classes, image paths and comments
benstrumeyer May 11, 2020
2d2aa90
Fix account#getUserSubscriptionData behavior
benstrumeyer May 11, 2020
9383ab6
Add subscriptionsPremium property to user object to check if a user h…
benstrumeyer May 11, 2020
f7b36a9
Refactor Header component to use subscriptionsPremium property
benstrumeyer May 11, 2020
f545e7b
Add newline
benstrumeyer May 11, 2020
2fcc862
Refactor svg template literal
benstrumeyer May 11, 2020
ef91547
Refactor account#getUserSubscriptionData to return an array of subscr…
benstrumeyer May 12, 2020
4fc3f53
Pass object that allows destructuring of subscriptionData
benstrumeyer May 12, 2020
2a9ffcb
Add return statement after callbacks
benstrumeyer May 12, 2020
f120d4d
Add guard to account#_setSubscriptionData to prevent overriding premi…
benstrumeyer May 12, 2020
7fe5a24
Give user subscriptionsPlus bool if they have either plus or premium …
benstrumeyer May 12, 2020
33c506a
Rename subscriptionsPlus and subscriptionsPremium to plusAccess and p…
benstrumeyer May 12, 2020
0586ff5
Set subscription property on user object with highest tier subscripti…
benstrumeyer May 12, 2020
a77797c
Refactor menu upsell icon to use user.subscriber instead of plusAcces…
benstrumeyer May 12, 2020
1816764
test
benstrumeyer May 12, 2020
0847e49
Refactor Header logo and menu icon to use subscription instead of pre…
benstrumeyer May 13, 2020
d25d313
Rename subscriber variable to subscription
benstrumeyer May 13, 2020
c9ad1de
Refactor subscriber badge to use plusAccess and premiumAccess on clic…
benstrumeyer May 13, 2020
6398be1
Check if user object exists before accessing subscription property
benstrumeyer May 13, 2020
eb337bc
Display UI elements basedd off user scope
benstrumeyer May 13, 2020
3d51fd0
Remove unused subscription property on user
benstrumeyer May 13, 2020
23e5eb7
Base menu icon off of plusAccess and premiumAccess
benstrumeyer May 13, 2020
49eb749
Refactor isPlus to hasPlusAccess, destructure some things, and save s…
benstrumeyer May 13, 2020
47f1cd5
Use panel#hasPlusAccess() directly
benstrumeyer May 13, 2020
ead0930
Fix menu icon link
benstrumeyer May 14, 2020
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Refactor account#getUserSubscriptionData to return an array of subscr…

…iptions, and the background handler to return the highest tier subscription
  • Loading branch information
benstrumeyer committed May 12, 2020
commit ef91547d7bb8c1d362a365750488856f92d8c47a
@@ -243,7 +243,7 @@ class HeaderMenu extends React.Component {
</li>
<li className={optionClasses} onClick={this.clickSubscriber}>
<div>
{/* Upselling plus for all users who are not premium subscribers */}
{/* Show premium icon to premium users and plus icon to basic and plus users */}
{!subscriptionsPremium && (
<svg className={iconClasses} width="84" height="77" viewBox="0 0 84 77">
<g className="about-icon" fill="none">
@@ -823,20 +823,15 @@ function onMessageHandler(request, sender, callback) {
}
if (name === 'account.getUserSubscriptionData') {
account.getUserSubscriptionData()
.then((customer) => {
// TODO temporary fix to handle multiple subscriptions
let sub = customer.subscriptions;
if (!Array.isArray(sub)) {
sub = [sub];
}
.then((subscriptions) => {
// Return highest tier subscription from array
const premiumSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Premium'));
if (premiumSubscription) callback({ premiumSubscription });

let subscriptionData = sub.find(subscription => subscription.productName.includes('Ghostery Premium'));
if (subscriptionData) {
callback({ subscriptionData });
}
const plusSubscription = subscriptions.find(subscription => subscription.productName.includes('Ghostery Plus'));
if (plusSubscription) callback({ plusSubscription });

subscriptionData = sub.find(subscription => subscription.productName.includes('Ghostery Plus'));
callback({ subscriptionData });
callback({});
})
.catch((err) => {
log('Error getting user subscription data:', err);
@@ -158,6 +158,9 @@ class Account {
})
)

/**
* @return {array} All subscriptions the user has, empty if none
*/
This conversation was marked as resolved by wlycdgr
Comment on lines +161 to +163

This comment has been minimized.

@wlycdgr

wlycdgr May 12, 2020
Member

Good idea to add this!

getUserSubscriptionData = () => (
this._getUserID()
.then(userID => api.get('stripe/customers', userID, 'cards,subscriptions'))
@@ -170,17 +173,20 @@ class Account {
sub = [sub];
}

// Display premium info if user has both premium and plus subscriptions
const subscriptions = [];

const premiumSubscription = sub.find(subscription => subscription.productName.includes('Ghostery Premium'));
if (premiumSubscription) {
this._setSubscriptionData(premiumSubscription);
subscriptions.push(premiumSubscription);
}

const plusSubscription = sub.find(subscription => subscription.productName.includes('Ghostery Plus'));
if (plusSubscription) {
subscriptions.push(plusSubscription);
this._setSubscriptionData(plusSubscription);
}
return customer;
return subscriptions;
This conversation was marked as resolved by wlycdgr
Comment on lines +176 to +189

This comment has been minimized.

@wlycdgr

wlycdgr May 12, 2020
Member

Looking much better, just a couple more things:

  • We can simplify/dedupe this by usng forEach to iterate once over the sub array, checking whether the productName of each element is in a productNames array we define, and pushing the element to the subscriptions array if so.
  • We need to make sure we don't clobber Premium subsciption data with Plus subscription data in _setSubscriptionData in case the user has both and the Plus sub is found after the Premium one.

This comment has been minimized.

@wlycdgr

wlycdgr May 12, 2020
Member

Let's not worry about the forEach change for now

})
)

ProTip! Use n and p to navigate between commits in a pull request.