-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
email confirmation message banner (#3576)
* email confirmation message banner * rename EmailConfirmationBanner to FlashBanner * refactor message formatting and add a test
- Loading branch information
1 parent
6c94da3
commit 7f6e018
Showing
5 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |