App icon indicating copy to clipboard operation
App copied to clipboard

Update the free trial badge to display Start a free trial badge when we create a workspace for a user

Open abzokhattab opened this issue 1 year ago • 3 comments

Details

Fixed Issues

$ https://github.com/Expensify/App/issues/48217 PROPOSAL: https://github.com/Expensify/App/issues/48217#issuecomment-2316265641

Tests

  1. Log in with a new account.
  2. Complete the onboarding process.
  3. In the onboarded report (Expensify or Coinceirge), validate that the LHN and the header do not display the free trial badge.
  4. Create a workspace.
  5. Check the LHN, the report header, and the subscription tab inside the account settings to ensure that all three display the Start your free trial badge.
  6. Submit an expense to the workspace.
  7. Again, check the LHN, the report header, and the subscription tab inside the account settings to ensure that all three display the Free trial: 7 days left badge.

Offline tests

same as tests

QA Steps

same as tests

PR Author Checklist

  • [X] I linked the correct issue in the ### Fixed Issues section above
  • [X] I wrote clear testing steps that cover the changes made in this PR
    • [X] I added steps for local testing in the Tests section
    • [X] I added steps for the expected offline behavior in the Offline steps section
    • [X] I added steps for Staging and/or Production testing in the QA steps section
    • [X] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [X] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • [X] I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • [X] I included screenshots or videos for tests on all platforms
  • [X] I ran the tests on all platforms & verified they passed on:
    • [X] Android: Native
    • [X] Android: mWeb Chrome
    • [X] iOS: Native
    • [X] iOS: mWeb Safari
    • [X] MacOS: Chrome / Safari
    • [X] MacOS: Desktop
  • [X] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • [X] I followed proper code patterns (see Reviewing the code)
    • [X] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • [X] I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • [X] I verified that comments were added to code that is not self explanatory
    • [X] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • [X] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • [X] If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • [X] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [X] I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • [X] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • [X] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [X] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [X] I followed the guidelines as stated in the Review Guidelines
  • [X] I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • [X] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [X] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • [X] I verified that if a function's arguments changed that all usages have also been updated correctly
  • [X] If any new file was added I verified that:
    • [X] The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • [X] If a new CSS style is added I verified that:
    • [X] A similar style doesn't already exist
    • [X] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • [X] If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • [X] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • [X] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • [X] If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • [X] If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • [X] I verified that all the inputs inside a form are aligned with each other.
    • [X] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [X] If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • [X] If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

https://github.com/user-attachments/assets/b3f841d2-cca3-43e3-b111-72b35cae489e

Android: mWeb Chrome

https://github.com/user-attachments/assets/90cc81ec-41d9-4d83-a473-6fdbdd7fe95e

iOS: Native

https://github.com/user-attachments/assets/6286c0d8-6d98-48cb-8bb1-877e2bd6a7a0

iOS: mWeb Safari

https://github.com/user-attachments/assets/66d55ccc-936c-4416-abbb-5f18e5a212d0

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/8fa90886-d0e8-4993-91e0-e864b26c7c8d

MacOS: Desktop

https://github.com/user-attachments/assets/191df369-9dbc-4a3c-978c-4a563ab65f74

abzokhattab avatar Sep 03 '24 21:09 abzokhattab

@rojiphil Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

melvin-bot[bot] avatar Sep 03 '24 21:09 melvin-bot[bot]

@abzokhattab The free trial text is not updated properly as demonstrated in the video below. This is for a case when the trial has expired. Also, the LHN shows Start free trial briefly before transitioning to Your free trial has ended. Can you please check these? Also, jest unit tests are failing.

https://github.com/user-attachments/assets/ffe08a6f-79ce-43b4-84e0-febfec72f07d

rojiphil avatar Sep 04 '24 08:09 rojiphil

What is the ETA here? When do we think we will be able to fix the review comments and merge?

anmurali avatar Sep 07 '24 13:09 anmurali

@abzokhattab Please update on the latest status on the comment here. We need to take this to the finish line sooner as it is already marked as critical.

rojiphil avatar Sep 08 '24 09:09 rojiphil

Thanks for your patience, @rojiphil. It took me a bit to find the right solution for the title inconsistency.

I ended up creating a component for the free trial badge and updated getFreeTrialText and related functions to take Onyx data as inputs. The issue was that the free trial text wasn’t updating when the Onyx data changed. By passing the Onyx data directly into the function, it now reacts properly to those changes.

abzokhattab avatar Sep 08 '24 21:09 abzokhattab

The review is in progress. I will update today on this.

rojiphil avatar Sep 09 '24 14:09 rojiphil

Also, Start a free trial message get’s displayed on Concierge chat when it should have been displayed on Expensify system chat on signin. It looks like the delay for openApp to update the onboarding chat id is causing this problem. Here is a test video demonstrating this:

https://github.com/user-attachments/assets/12841d89-671d-422d-891d-6db84bd9d898

rojiphil avatar Sep 09 '24 18:09 rojiphil

It seems like there is a delay for openApp to update the lastDayFreeTrial and firstDayFreeTrial in Onyx which causes a temporary display of Start a free trial.

do you have a way in mind to address this issue? .. i have tried some approaches but didn't work.

abzokhattab avatar Sep 09 '24 18:09 abzokhattab

It seems like there is a delay for openApp to update the lastDayFreeTrial and firstDayFreeTrial in Onyx which causes a temporary display of Start a free trial.

do you have a way in mind to address this issue? .. i have tried some approaches but didn't work.

Hmm.. Interesting scenario here. Maybe BE needs to inform FE via a state like trialState which specifies whether it is preTrial,inTrial, trialEnded or Active. An undefined value can mean noState during which we decide to not show any message. @chiragsalian What are your thoughts on addressing this issue?

The context here is the problem of LHN showing Start a free trial briefly before transitioning to Your free trial has ended. This is mentioned here and here

rojiphil avatar Sep 09 '24 19:09 rojiphil

Maybe BE needs to inform FE via a state like trialState which specifies whether it is preTrial,inTrial, trialEnded or Active

Its a good idea but generally we should avoid duplicating source of truth unless really necessary. in this scenario its duplicate information because generally freeTrial start and end gives us everything we need. It seems like the catch here is that while the front end is fetching data because the nvp is not set it shows "start a free trial", but once it fetches the nvp it changes the text to "Your free trial has ended", correct?

If that's the case then can we use a flag like isLoading (or nvpsLoading if there isn't an existing one) so that we don't show anything until the NVPs are fetched?

chiragsalian avatar Sep 10 '24 02:09 chiragsalian

while the front end is fetching data because the nvp is not set it shows "start a free trial", but once it fetches the nvp it changes the text to "Your free trial has ended", correct?

That's correct

If that's the case then can we use a flag like isLoading (or nvpsLoading if there isn't an existing one) so that we don't show anything until the NVPs are fetched?

Thanks. That makes sense. @abzokhattab Can you please try this? This would also help us fix this comment

rojiphil avatar Sep 10 '24 07:09 rojiphil

If that's the case then can we use a flag like isLoading (or nvpsLoading if there isn't an existing one) so that we don't show anything until the NVPs are fetched?

then how would we know that the data has been fetched?

abzokhattab avatar Sep 10 '24 07:09 abzokhattab

If that's the case then can we use a flag like isLoading (or nvpsLoading if there isn't an existing one) so that we don't show anything until the NVPs are fetched?

then how would we know that the data has been fetched?

yeah. That's a genuine concern too. I will also see what can be done here. This happens only at the time of signin and is only until the Onyx data has stabilized.

rojiphil avatar Sep 10 '24 09:09 rojiphil

If that's the case then can we use a flag like isLoading (or nvpsLoading if there isn't an existing one) so that we don't show anything until the NVPs are fetched?

then how would we know that the data has been fetched?

yeah. That's a genuine concern too. I will also see what can be done here. This happens only at the time of signin and is only until the Onyx data has stabilized.

@abzokhattab Were you able to find some solution? One option though is to use debounce and wait for the Onyx data to stabilize and, then, use the debouncedFreeTrialText in the component instead of freeTrialText. Can you please check if this works? Something like this:

    const [freeTrialText, debouncedFreeTrialText, setFreeTrialText] = useDebouncedState('');
    useEffect(() => {
        setFreeTrialText(SubscriptionUtils.getFreeTrialText(policies) ?? '');
    }, [policies, firstDayFreeTrial, lastDayFreeTrial]);  

rojiphil avatar Sep 10 '24 12:09 rojiphil

Oh! And there are conflicts now. Please resolve

rojiphil avatar Sep 10 '24 12:09 rojiphil

I have tried the debounced state and I am not able to reproduce the quick transition change on my case ... can you validate that on your account as well? @rojiphil

abzokhattab avatar Sep 10 '24 22:09 abzokhattab

I have tried the debounced state and I am not able to reproduce the quick transition change on my case ... can you validate that on your account as well? @rojiphil

@abzokhattab I think using debouncedState is not a good idea as it will unnecessarily delay showing the freeTrialText even when the LHN gets re-rendered. I think it is an overkill to address this issue which occurs only during the signin. An alternate approach which waits until nvp_private_subscription is set for the freeTrialText to be populated seems to be better. Unless you have found something better, can you please check this?

    const [freeTrialText, setFreeTrialText] = useState<string>();
    const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION);    
    useEffect(() => {
        !!privateSubscription && setFreeTrialText(SubscriptionUtils.getFreeTrialText(policies));
    }, [privateSubscription, policies, firstDayFreeTrial, lastDayFreeTrial]); 

rojiphil avatar Sep 11 '24 12:09 rojiphil

@abzokhattab I think using debouncedState is not a good idea as it will unnecessarily delay showing the freeTrialText even when the LHN gets re-rendered. I think it is an overkill to address this issue which occurs only during the signin. An alternate approach which waits until nvp_private_subscription is set for the freeTrialText to be populated seems to be better. Unless you have found something better, can you please check this?

agree ... i have tried with two accounts for this approach and the issue is not reproducible ... please let me know if its the same for you as well

abzokhattab avatar Sep 11 '24 17:09 abzokhattab

also, i removed Your trial has ended case from the badge titles in this commit as mentioned here

Pease let me know if you have any other comments

abzokhattab avatar Sep 12 '24 06:09 abzokhattab

also, i removed Your trial has ended case from the badge titles in this commit as mentioned here

Pease let me know if you have any other comments

Thanks. That looks good. I will complete the checklist today.

rojiphil avatar Sep 12 '24 06:09 rojiphil

@abzokhattab Ah! We have an issue if we create a workspace offline. In such a case, the Concierge chat will not display the free trial text whereas Subscription does. The test video below demonstrates this. Since we need to check for privateSubscription only when it is online, let us use the offline status to fix this. Something like shown below:

Also, once this is addressed, can you please update the test videos in the PR description as quite a lot of change has gone through since the initial version?

    const {isOffline} = useNetwork();
    useEffect(() => {
        if (!privateSubscription && !isOffline) {
            return;
        }
        setFreeTrialText(SubscriptionUtils.getFreeTrialText(policies));
    }, [isOffline, privateSubscription, policies, firstDayFreeTrial, lastDayFreeTrial]);

https://github.com/user-attachments/assets/c44a783a-bf47-4f98-be25-d5cb59912c7c

rojiphil avatar Sep 12 '24 11:09 rojiphil

@abzokhattab Please let me know when it is ready for review again. Thanks.

rojiphil avatar Sep 13 '24 05:09 rojiphil

Sorry, I thought I had commented.

I have checked all devices again and all the tests pass.

The PR is ready from side.

abzokhattab avatar Sep 15 '24 19:09 abzokhattab

Reviewer Checklist

  • [x] I have verified the author checklist is complete (all boxes are checked off).
  • [x] I verified the correct issue is linked in the ### Fixed Issues section above
  • [x] I verified testing steps are clear and they cover the changes made in this PR
    • [x] I verified the steps for local testing are in the Tests section
    • [x] I verified the steps for Staging and/or Production testing are in the QA steps section
    • [x] I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [x] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • [x] I checked that screenshots or videos are included for tests on all platforms
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I verified tests pass on all platforms & I tested again on:
    • [x] Android: Native
    • [x] Android: mWeb Chrome
    • [x] iOS: Native
    • [x] iOS: mWeb Safari
    • [x] MacOS: Chrome / Safari
    • [x] MacOS: Desktop
  • [x] If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • [x] I verified proper code patterns were followed (see Reviewing the code)
    • [x] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • [x] I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • [x] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I verified that this PR follows the guidelines as stated in the Review Guidelines
  • [x] I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • [x] If a new component is created I verified that:
    • [x] A similar component doesn't exist in the codebase
    • [x] All props are defined accurately and each prop has a /** comment above it */
    • [x] The file is named correctly
    • [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • [x] The only data being stored in the state is data necessary for rendering and nothing else
    • [x] For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • [x] Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • [x] All JSX used for rendering exists in the render method
    • [x] The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • [x] If any new file was added I verified that:
    • [x] The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • [x] If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • [x] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • [x] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • [x] If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • [x] If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • [x] I verified that all the inputs inside a form are aligned with each other.
    • [x] I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • [x] If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • [x] If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

MacOS: Chrome / Safari

https://github.com/user-attachments/assets/660dd563-505b-41ce-80ee-8cf875366c05

MacOS: Desktop

https://github.com/user-attachments/assets/f6dbfc6c-2420-4a6a-a89c-57e5d5c9df2a

iOS: mWeb Safari

https://github.com/user-attachments/assets/3eb72779-26b3-41d0-9bcb-3ac13a36a9d2

Android: Native

https://github.com/user-attachments/assets/7c085525-ff2e-4744-8fc0-285bd7edf6f8

Android: mWeb Chrome

https://github.com/user-attachments/assets/107c98b0-ddb0-4780-903d-93ee5e49c539

iOS: Native

https://github.com/user-attachments/assets/c03ff901-89f3-4e10-946a-3e2f7b620752

rojiphil avatar Sep 16 '24 05:09 rojiphil

@abzokhattab Please update the test steps 1,2 as follows as Expensify onboarding chat will not be shown anymore:

okay done!

abzokhattab avatar Sep 16 '24 18:09 abzokhattab

Code, LGTM and it mostly works well but I do see a bug that we should address. Steps to reproduce:

  1. Log in with a new account.
  2. Select "manage my team" in onboarding. Enter a business name and personal name.
  3. Here the Start a free trial badge shows up which looks good.
  4. Start a DM with some random user and send a message. The idea here is for the newDot focus to be on a new report.
  5. Now signout and signin.
  6. 💥 Start a free trial badge doesn't show up for me image
  7. Once i mouse over or click on Concierge then the badge appears, (also clicking on search/settings and going back to chat view shows the badge for me) image

Can you guys test the same and confirm the issue.

chiragsalian avatar Sep 16 '24 18:09 chiragsalian

is it occurring on a specific platform?

abzokhattab avatar Sep 16 '24 18:09 abzokhattab

i only tested on MacOS: Chrome

chiragsalian avatar Sep 16 '24 18:09 chiragsalian

Any luck on addressing the bug? Were you guys able to reproduce the bug i mentioned @abzokhattab / @rojiphil?

chiragsalian avatar Sep 17 '24 17:09 chiragsalian

@chiragsalian I tried to reproduce just now but I noticed that the focus goes back to the Concierge Chat. Not sure what I am doing wrong. I tried some other things too but I could not get the focus to move away from Concierge chat. Strange but I will try again later. Anyway, here is a video that demonstrates this. Meanwhile, waiting for @abzokhattab feedback too on this.

https://github.com/user-attachments/assets/b06b8adc-a7ce-4f23-930a-03ae80cfbf48

rojiphil avatar Sep 17 '24 18:09 rojiphil