Skip to content

Commit

Permalink
break FlashBanner into multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdstock committed May 26, 2020
1 parent 113d876 commit 96ca972
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 57 deletions.
54 changes: 0 additions & 54 deletions src/v2/Components/FlashBanner.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions src/v2/Components/FlashBanner/FlashMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react"
import { Banner, Sans } from "@artsy/palette"

/** Flash messages triggered by a url `flash_message` query param
* A message can be a string or a React Component that takes no props
* (that is, use relay or context if necessary)
*/
const messagebyQueryParam: { [k: string]: string | React.FC } = {
confirmed: "Your email has been confirmed.",
already_confirmed: "You have already confirmed your email.",
invalid_token: "An error has occurred. Please contact support@artsy.net.",
blank_token: "An error has occurred. Please contact support@artsy.net.",
expired_token: "Link expired. Resend verification email.",
}

export const FlashMessage: React.FC<{ messageCode: string }> = ({
messageCode,
}) => {
const Message = messagebyQueryParam[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>
)
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"
import { storiesOf } from "storybook/storiesOf"
import { FlashMessage } from "v2/Components/FlashBanner"
import { FlashMessage } from "v2/Components/FlashBanner/FlashMessage"

storiesOf("Components/FlashBanner", module).add(
"Successful Confirmation Message",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mount } from "enzyme"
import "jest-styled-components"
import React from "react"
import { FlashMessage } from "../FlashBanner"
import { FlashMessage } from "../FlashMessage"

describe("FlashBanner", () => {
describe("FlashMessage", () => {
it("renders a banner based on a message code", () => {
const wrapper = mount(<FlashMessage messageCode="confirmed" />)
expect(wrapper.text()).toContain("Your email has been confirmed.")
Expand Down
18 changes: 18 additions & 0 deletions src/v2/Components/FlashBanner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react"
import qs from "qs"
import { FlashMessage } from "./FlashMessage"

/**
* The component responsible for selecting a flash message key from the `flash_message` url query param
*/
export const FlashBanner: React.FunctionComponent = () => {
const [messageCode, setMessageCode] = React.useState(null)

React.useEffect(() => {
const query = qs.parse(window.location.search.slice(1))
if (query["flash_message"]) setMessageCode(query["flash_message"])
}, [])

if (!messageCode) return null
return <FlashMessage messageCode={messageCode} />
}

0 comments on commit 96ca972

Please sign in to comment.