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

email confirmation message banner #3576

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Components/FlashBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from "react"
import { Banner, Sans } from "@artsy/palette"

interface Props {
messageCode: FlashMessageKey
}

export type FlashMessageKey =
/* email confirmed */
| "confirmed"
/* email already confirmed */
| "already_confirmed"
/* email confirmation token was invalid */
| "invalid_token"
/* email confirmation token was empty */
| "blank_token"
/* email confirmation token was expired */
| "expired_token"

type BannerMessage = string | React.FC
Copy link
Contributor

Choose a reason for hiding this comment

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

why the union type here? Seems like these are all strings?


const messages: Record<FlashMessageKey, BannerMessage> = {
confirmed: "Your email has been confirmed.",
already_confirmed: "You have already confirmed your email.",
invalid_token: "Your token is invalid. Please try again.",
blank_token: "No token found. Please try again.",
expired_token: "An error has occurred. Please try again.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be something about how their confirmation token expired, not the general message? Or are we planning to come back to this once we allow people to request the email?

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 copied these from the eigen pr- happy to change but also wonder if these are meant to be final - in most cases for example 'try again' is not going to be actionable unless there is a 'resend email' button.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed – would much rather tell people to "Contact support@artsymail.com"

}

export const FlashBanner: React.FunctionComponent<Props> = ({
messageCode,
}) => {
const Message = messages[messageCode]
if (!Message) return null
return (
Message && (
<Banner dismissable backgroundColor="black100">
<Sans color="white100" size="3" lineHeight={1} weight="medium">
{typeof Message === "string" ? Message : <Message />}
Copy link
Contributor

Choose a reason for hiding this comment

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

very well could be missing something, but these seem to always be strings...

</Sans>
</Banner>
)
)
}
7 changes: 6 additions & 1 deletion src/Components/MinimalCtaBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export class MinimalCtaBanner extends React.Component<
</Sans>
</a>
<IconContainer onClick={this.dismissCta.bind(this) as any}>
<Icon name="close" color={this.props.textColor} fontSize="16px" />
<Icon
name="close"
color={this.props.textColor}
fontSize="16px"
style={{ cursor: "pointer" }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and the other change to the CtaBanner story were minor bugfixes left over from early explorations. It's possible we don't even use this and/or should remove the changes from the PR but for now I'm thinking we want to prioritize upcoming reaction migration work so am not addressing unless you think it is neccessary @damassi

/>
</IconContainer>
</Banner>
</BannerContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/__stories__/CtaBanner.story.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { storiesOf } from "@storybook/react"
import React from "react"

import { storiesOf } from "storybook/storiesOf"
import { MinimalCtaBanner } from "../MinimalCtaBanner"

storiesOf("Components/MinimalCtaBanner", module).add(
Expand All @@ -12,6 +11,7 @@ storiesOf("Components/MinimalCtaBanner", module).add(
position="bottom"
textColor="white"
backgroundColor="black"
show
/>
)
)
10 changes: 10 additions & 0 deletions src/Components/__stories__/FlashBanner.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react"
import { storiesOf } from "storybook/storiesOf"
import { FlashBanner } from "Components/FlashBanner"

storiesOf("Components/FlashBanner", module).add(
"Successful Confirmation Message",
() => {
return <FlashBanner messageCode="confirmed" />
}
)
16 changes: 16 additions & 0 deletions src/Components/__tests__/FlashBanner.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { mount } from "enzyme"
import "jest-styled-components"
import React from "react"
import { FlashBanner } from "../FlashBanner"

describe("FlashBanner", () => {
it("renders a banner based on a message code", () => {
const wrapper = mount(<FlashBanner messageCode="confirmed" />)
expect(wrapper.text()).toContain("Your email has been confirmed.")
})

it("returns nothing without complaint if the message code is not supported", () => {
const wrapper = mount(<FlashBanner messageCode={"bad_message" as any} />)
expect(wrapper.html()).toBeNull()
})
})