-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break FlashBanner into multiple files
- Loading branch information
1 parent
113d876
commit 96ca972
Showing
5 changed files
with
51 additions
and
57 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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> | ||
) | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
src/v2/Components/FlashMessage.story.tsx → ...Banner/__stories__/FlashMessage.story.tsx
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
4 changes: 2 additions & 2 deletions
4
...Components/__tests__/FlashBanner.jest.tsx → ...lashBanner/__tests__/FlashBanner.jest.tsx
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,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} /> | ||
} |