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 a banner based on some url param #5620

Merged

Conversation

erikdstock
Copy link
Contributor

@erikdstock erikdstock commented May 20, 2020

Related 🔒 Jira Ticket
Similar Eigen PR: artsy/eigen#3325

Initial working solution to a problem: I want to show a banner when the user passes email confirmation. This does it by catching the param very early in express, adding it to sd and then passing it into our NavBar component. It's a little bit over-engineered for what it is doing right now, a result of my trying to understand existing practices and where things were coming from.

Questions here:

  • Any reason to NOT show it on potentially every page?
  • The banner lays on top of other content, outside the document flow.
  • Related eigen pr: [AUCT-1011] - Add confirmation alert for email verification in homeVC eigen#3325. We will want to at least make sure we are using the same query parameter. Currently we are not.
  • I'm not sure if I added bannerCode, my new banner-related NavBar prop to too many places (eg a NavBar in a jade template).

image

@@ -7,11 +7,11 @@ block body
block banner
mixin login-signup("header")
header
!= stitch && stitch.components.NavBar({ user: sd.CURRENT_USER, notificationCount: sd.NOTIFICATION_COUNT })
!= stitch && stitch.components.NavBar({ user: sd.CURRENT_USER, flashMessage: sd.flashMessage, notificationCount: sd.NOTIFICATION_COUNT })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wondering what the difference is between this and index.jade, and why we have 2 navbars in this file...

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe I am responsible for the double-header. 😅 (#5261)

I think what you have is fine, but note that the sticky-header behavior on mobile web for non-reaction pages is a little weird. I would verify that this looks fine on the home page (logged in and logged out) and on the artist page (logged in/out) to be sure that nothing's messed up!

src/lib/setup.js Outdated Show resolved Hide resolved
@dleve123 dleve123 force-pushed the auct1001-show-email-confirmation-banner branch from 403f450 to 1c121d9 Compare May 22, 2020 20:23
@dleve123 dleve123 marked this pull request as ready for review May 22, 2020 20:23
@dleve123 dleve123 changed the title WIP: Show a banner based on some url param Show a banner based on some url param May 22, 2020
@damassi
Copy link
Member

damassi commented May 22, 2020

@erikdstock - if y'all can hold off on merging this. Very close with the other PR and then y'all can rebase.

We're going to do a release of some analytics updates but it would be best if this wasn't in that batch.

@dleve123
Copy link
Contributor

Re #5620 (comment)

That's fine! We're working on adding some tests for this behavior now. Can you ping us when the other PR is off and away?

@ArtsyOpenSource
Copy link

ArtsyOpenSource commented May 22, 2020

Fails
🚫

Danger failed to run dangerfile.ts.

Error RangeError

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at RegExp.[Symbol.replace] (<anonymous>)
    at String.replace (<anonymous>)
    at standardizeName (/home/circleci/project/node_modules/@babel/core/lib/config/files/plugins.js:94:15)
    at resolveStandardizedName (/home/circleci/project/node_modules/@babel/core/lib/config/files/plugins.js:98:28)
    at resolvePlugin (/home/circleci/project/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (/home/circleci/project/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (/home/circleci/project/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at /home/circleci/project/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/home/circleci/project/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)

Dangerfile

-----------------^

Generated by 🚫 dangerJS against 89be270

@codecov
Copy link

codecov bot commented May 22, 2020

Codecov Report

Merging #5620 into master will decrease coverage by 0.0%.
The diff coverage is 0.0%.

@@           Coverage Diff            @@
##           master   #5620     +/-   ##
========================================
- Coverage    79.3%   79.3%   -0.1%     
========================================
  Files        1250    1250             
  Lines       34034   34035      +1     
  Branches     2072    2073      +1     
========================================
  Hits        27021   27021             
- Misses       5999    6000      +1     
  Partials     1014    1014             

@damassi
Copy link
Member

damassi commented May 22, 2020

@erikdstock - Regarding approach, one thought is: rather than passing this data all through the system in order to SSR render, we simply look at the url in a useEffect and if the flag is there, show the bar. Even better, this can be moved into a hook and invoked in the NavBar component:

const flashMessage = useFlashMessage()
...
<Box>
  {flashMessage?.message && <FlashMessage message={flashMessage.message} />}
</Box>

This can happen all on the client. As that url bar query param state will never be persisted across urls we don't need to worry about it flashing in when a user clicks something and a new page re-renders.

Thoughts?

@erikdstock
Copy link
Contributor Author

@damassi Re: #5620 (comment)

Talking with @dleve123 much prefer this idea and spiked on it for a bit but weren't able to get it completely working. We'd like to merge this if tests pass and then iterate on it next week when we return for the more complicated next steps on the FlashBanner component, at which point (once working) we will undo all changes related to sd.FLASH_BANNER.

@damassi
Copy link
Member

damassi commented May 22, 2020

It might be worth reaching out to #dev-help if y'all are running into trouble with the client-side approach (versus rewinding everything)? A quick glance at https://github.com/artsy/force/pull/5620/files#diff-3df7ffd25fef9729a61746506a33251bR34 and i think this could be done with just a couple lines of code.

@erikdstock erikdstock force-pushed the auct1001-show-email-confirmation-banner branch from 83b7e7a to 9d421c4 Compare May 26, 2020 16:00
@erikdstock
Copy link
Contributor Author

@damassi re #5620 (comment)

@dleve123 and I were able to get it working this morning, much better- thanks for the tip!

}
}, [])

if (!messageCode) return null
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move this above the effect to show that we're exiting early and to avoid registering the effect inside of react's execution loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow you here.

Copy link
Member

Choose a reason for hiding this comment

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

Meaning, if (!messageCode) return null can move up above the React.useEffect call. Since messageCode is null, and we know that via props, we can immediately check for it right at the top of the component and exit early.

@erikdstock erikdstock force-pushed the auct1001-show-email-confirmation-banner branch from 96ca972 to b4b15bc Compare May 26, 2020 20:25
@erikdstock erikdstock merged commit 5e4e705 into artsy:master May 27, 2020
@artsy-peril artsy-peril bot mentioned this pull request May 27, 2020
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.

7 participants