Skip to content

Commit

Permalink
email confirmation message banner (#3576)
Browse files Browse the repository at this point in the history
* email confirmation message banner

* rename EmailConfirmationBanner to FlashBanner

* refactor message formatting and add a test
  • Loading branch information
erikdstock authored May 21, 2020
1 parent 6c94da3 commit 7f6e018
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
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

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.",
}

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 />}
</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" }}
/>
</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()
})
})

0 comments on commit 7f6e018

Please sign in to comment.