-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
show upgrade dialog to new users #2788
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,16 @@ export function mockUser(): User { | |
return { | ||
id: 'f7102dc9-4c0c-42b4-9a17-e2bd4af94d5a', | ||
stripeCustomerId: 'f7102dc9-4c0c-42b4-9a17-e2bd4af94d5a', | ||
resendContactId: 'f7102dc9-4c0c-42b4-9a17-e2bd4af94d5a', | ||
email: '[email protected]', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
picture: 'asdf', | ||
isNewUser: false, | ||
emailVerified: new Date(), | ||
password: 'password', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
} as User; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { createEffect, Actions, ofType } from '@ngrx/effects'; | |
import { Store } from '@ngrx/store'; | ||
import { RootState } from 'altair-graphql-core/build/types/state/state.interfaces'; | ||
import { environment } from 'environments/environment'; | ||
import { EMPTY, forkJoin, from, zip } from 'rxjs'; | ||
import { EMPTY, forkJoin, from, of, zip } from 'rxjs'; | ||
import { | ||
catchError, | ||
map, | ||
|
@@ -57,6 +57,7 @@ export class AccountEffects { | |
firstName: user?.firstName ?? user?.email ?? '', | ||
lastName: '', | ||
picture: user.picture ?? '', | ||
isNewUser: user.isNewUser, | ||
}) | ||
); | ||
|
||
|
@@ -98,10 +99,11 @@ export class AccountEffects { | |
); | ||
this.store.dispatch( | ||
new accountActions.AccountIsLoggedInAction({ | ||
email: user.email || '', | ||
firstName: user.firstName || user.email || '', | ||
email: user.email ?? '', | ||
firstName: user.firstName ?? user.email ?? '', | ||
lastName: '', | ||
picture: user.picture || '', | ||
picture: user.picture ?? '', | ||
isNewUser: user.isNewUser, | ||
}) | ||
); | ||
this.store.dispatch( | ||
|
@@ -224,24 +226,31 @@ export class AccountEffects { | |
() => { | ||
return this.actions$.pipe( | ||
ofType(accountActions.ACCOUNT_IS_LOGGED_IN), | ||
switchMap((action) => | ||
switchMap((action: accountActions.AccountIsLoggedInAction) => | ||
forkJoin([ | ||
fromPromise(this.accountService.getStats()), | ||
fromPromise(this.accountService.getPlan()), | ||
fromPromise(this.accountService.getPlanInfos()), | ||
fromPromise(this.accountService.getAvailableCredits()), | ||
of(action.payload), | ||
]) | ||
), | ||
map(([stats, plan, planInfos, availableCredits]) => { | ||
map(([stats, plan, planInfos, availableCredits, user]) => { | ||
// check query parameter and show the update plan dialog if necessary | ||
const selectedPlan = consumeQueryParam('plan_select'); | ||
if (plan.canUpgradePro && selectedPlan === 'pro') { | ||
this.store.dispatch( | ||
new windowsMetaActions.ShowUpgradeDialogAction({ value: true }) | ||
); | ||
this.accountService.getUpgradeProUrl().then(({ url }) => { | ||
externalLink(url); | ||
}); | ||
if (plan.canUpgradePro) { | ||
const selectedPlan = consumeQueryParam('plan_select'); | ||
if (selectedPlan === 'pro') { | ||
this.store.dispatch( | ||
new windowsMetaActions.ShowUpgradeDialogAction({ value: true }) | ||
); | ||
this.accountService.getUpgradeProUrl().then(({ url }) => { | ||
externalLink(url); | ||
}); | ||
} else if (user.isNewUser) { | ||
this.store.dispatch( | ||
new windowsMetaActions.ShowUpgradeDialogAction({ value: true }) | ||
); | ||
} | ||
Comment on lines
+240
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if (plan.canUpgradePro && selectedPlan === 'pro') {
this.store.dispatch(
new windowsMetaActions.ShowUpgradeDialogAction({ value: true })
);
this.accountService.getUpgradeProUrl().then(({ url }) => {
externalLink(url);
});
} else if (user.isNewUser) {
this.store.dispatch(
new windowsMetaActions.ShowUpgradeDialogAction({ value: true })
); |
||
} | ||
|
||
this.store.dispatch( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using guard clauses to flatten the nested if statements and improve readability by reducing complexity and improving code flow.
This maintains the original functionality while reducing nesting and clarifying your intent.