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

show upgrade dialog to new users #2788

Merged
merged 5 commits into from
Mar 7, 2025
Merged

Conversation

imolorhe
Copy link
Collaborator

@imolorhe imolorhe commented Mar 5, 2025

Fixes

Checks

  • Ran yarn test-build
  • Updated relevant documentations
  • Updated matching config options in altair-static

Changes proposed in this pull request:

Summary by Sourcery

New Features:

  • Display the upgrade dialog to new users upon login.

Copy link

sourcery-ai bot commented Mar 5, 2025

Reviewer's Guide by Sourcery

This pull request introduces a feature to display an upgrade dialog to new users upon login. It also ensures that users who select a 'pro' plan via a query parameter are shown the upgrade dialog. The implementation involves adding an isNewUser flag to the user profile and modifying the account effects to trigger the upgrade dialog based on this flag and the presence of the plan_select query parameter.

Sequence diagram for showing upgrade dialog to new users

sequenceDiagram
  participant User
  participant AccountEffects
  participant AccountService
  participant Store
  participant WindowsMetaActions

  User->>AccountEffects: Logs in
  AccountEffects->>AccountService: getStats()
  AccountEffects->>AccountService: getPlan()
  AccountEffects->>AccountService: getPlanInfos()
  AccountEffects->>AccountService: getAvailableCredits()
  AccountService-->>AccountEffects: Returns data
  AccountEffects->>AccountEffects: Checks if user is new or selected 'pro' plan
  alt isNewUser or selected 'pro' plan
    AccountEffects->>Store: Dispatch ShowUpgradeDialogAction
    Store-->>AccountEffects: Acknowledged
    AccountEffects->>AccountService: getUpgradeProUrl()
    AccountService-->>AccountEffects: Returns URL
    AccountEffects->>AccountEffects: Open external link
  end
  AccountEffects->>Store: Dispatch other actions
  Store-->>AccountEffects: Acknowledged
Loading

Updated class diagram for IUserProfile

classDiagram
  class IUserProfile {
    firstName: string
    lastName?: string
    picture?: string
    isNewUser?: boolean
    tokens: IToken
  }

  class IToken {
    // Assuming IToken is defined elsewhere
  }

  IUserProfile -- IToken : has
Loading

File-Level Changes

Change Details Files
Added isNewUser property to the user profile and account actions to track new users.
  • Added isNewUser property to the IUserProfile interface.
  • Included isNewUser in the AccountIsLoggedInAction payload.
  • Populated the isNewUser field during user creation/authentication based on the user's creation time.
  • Included the isNewUser property when dispatching the AccountIsLoggedInAction.
packages/altair-app/src/app/modules/altair/effects/account.effect.ts
packages/altair-api/src/auth/strategies/google.strategy.ts
packages/altair-api-utils/src/user.ts
packages/altair-api/src/auth/auth.service.ts
packages/altair-app/src/app/modules/altair/store/account/account.action.ts
Modified the logic to display the upgrade dialog to new users and users who have selected a plan via a query parameter.
  • The upgrade dialog is now displayed to new users (based on the isNewUser flag).
  • The upgrade dialog is displayed if the plan_select query parameter is set to 'pro'.
  • The logic for showing the upgrade dialog was moved into the ACCOUNT_IS_LOGGED_IN effect.
packages/altair-app/src/app/modules/altair/effects/account.effect.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @imolorhe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces a feature that displays an upgrade dialog to new users. It achieves this by adding an isNewUser property to the user profile, which is determined by checking if the user's creation time is within the last 10 minutes. This property is then used in the account effects to conditionally show the upgrade dialog to new users upon login, in addition to the existing logic based on query parameters.

Highlights

  • New User Identification: The PR introduces a new isNewUser flag in the user profile to identify recently created users.
  • Conditional Upgrade Dialog: The upgrade dialog is now displayed to new users upon login, in addition to the existing logic based on the 'plan_select' query parameter.
  • Code Improvements: The PR also includes minor code improvements such as using the nullish coalescing operator (??) instead of the logical OR operator (||) for default value assignments.

Changelog

Click here to see the changelog
  • packages/altair-api-utils/src/user.ts
    • Added isNewUser property to the IUserProfile interface.
  • packages/altair-api/src/auth/auth.service.ts
    • Added logic to set the isNewUser property based on the user's creation time (within 10 minutes).
  • packages/altair-api/src/auth/strategies/google.strategy.ts
    • Replaced logical OR operator (||) with nullish coalescing operator (??) for default firstName assignment.
  • packages/altair-app/src/app/modules/altair/effects/account.effect.ts
    • Imported of from 'rxjs'.
    • Added isNewUser property to the user object when dispatching SetAccountAction.
    • Added isNewUser property to the user object when dispatching AccountIsLoggedInAction.
    • Modified the ACCOUNT_IS_LOGGED_IN effect to display the upgrade dialog to new users if they haven't already seen it via the query parameter logic.
  • packages/altair-app/src/app/modules/altair/store/account/account.action.ts
    • Added isNewUser property to the AccountIsLoggedInAction payload.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Did you know?

The name Altair comes from the brightest star in the constellation Aquila (the Eagle).

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a new feature to show an upgrade dialog to new users. The changes look good overall, but there are a few areas that could be improved for clarity and efficiency.

Summary of Findings

  • Magic number: The use of 1000 * 60 * 10 (10 minutes) as a magic number should be replaced with a named constant for better readability and maintainability.
  • Redundant check: The plan.canUpgradePro check in AccountEffects seems redundant as the subsequent logic depends on it. Consider simplifying the conditional logic.
  • Nullish coalescing operator: The usage of the nullish coalescing operator ?? is good, but ensure it's consistently used throughout the codebase for similar scenarios.

Merge Readiness

The pull request is almost ready for merging. Addressing the magic number and redundant check would improve the code quality. I am unable to approve the pull request, and other reviewers should review and approve this code before merging.

@@ -109,6 +109,7 @@ export class AuthService {
firstName: user.firstName,
lastName: user.lastName,
picture: user.picture,
isNewUser: Date.now() - user.createdAt.getTime() < 1000 * 60 * 10, // 10 minutes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This calculation determines if a user is new based on their creation time. Using a magic number like 1000 * 60 * 10 (10 minutes) makes the code less readable. Consider defining a constant for this duration to improve clarity and maintainability.

const TEN_MINUTES_IN_MS = 1000 * 60 * 10;
      isNewUser: Date.now() - user.createdAt.getTime() < TEN_MINUTES_IN_MS, // 10 minutes

Comment on lines +240 to +253
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 })
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The plan.canUpgradePro check is performed, and then the selectedPlan === 'pro' check is nested inside. If plan.canUpgradePro is false, the inner block will never execute. Consider simplifying this logic by removing the outer if statement, since the inner logic depends on it anyway. Also, it might be clearer to use an else if instead of two separate if statements.

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 })
              );

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @imolorhe - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining the magic number 1000 * 60 * 10 in packages/altair-api/src/auth/auth.service.ts.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -98,10 +99,11 @@ export class AccountEffects {
);
this.store.dispatch(
Copy link

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.

Consider flattening the nested ifs with guard clauses to improve readability. For example, extract the upgrade logic into its own helper or simply return early to avoid deep nesting. One option:

// Before:
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 }));
  }
}

// After:
if (!plan.canUpgradePro) {
  return;
}

const selectedPlan = consumeQueryParam('plan_select');

if (selectedPlan === 'pro') {
  this.store.dispatch(new windowsMetaActions.ShowUpgradeDialogAction({ value: true }));
  this.accountService.getUpgradeProUrl().then(({ url }) => {
    externalLink(url);
  });
  return;
}

if (user.isNewUser) {
  this.store.dispatch(new windowsMetaActions.ShowUpgradeDialogAction({ value: true }));
}

This maintains the original functionality while reducing nesting and clarifying your intent.

Copy link

github-actions bot commented Mar 5, 2025

Visit the preview URL for this PR (updated for commit 0443201):

https://altair-gql--pr2788-imolorhe-show-upgrad-ajkw6471.web.app

(expires Fri, 14 Mar 2025 15:34:48 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 02d6323d75a99e532a38922862e269d63351a6cf

@imolorhe imolorhe force-pushed the imolorhe/show-upgrade-to-new-users branch from 3036952 to b973ef3 Compare March 7, 2025 14:42
@imolorhe imolorhe added this pull request to the merge queue Mar 7, 2025
Merged via the queue into master with commit 1333f0f Mar 7, 2025
15 checks passed
@imolorhe imolorhe deleted the imolorhe/show-upgrade-to-new-users branch March 7, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant