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

RENO-3681: NewsletterSignup Component #1422

Merged
merged 43 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cde951b
NewsletterSignup as Refactored FeedbackBox
aarnold101 Sep 8, 2023
6e6b373
NewsletterSignup as exposed Form
aarnold101 Sep 8, 2023
d7427a7
React EmailSubscription as DS Component
aarnold101 Sep 8, 2023
8710deb
NewsLetterSignup add getSectionColors function, and other advances
aarnold101 Sep 14, 2023
0b2b4a9
Merge branch 'development' into RENO-3681/newslettersignup-component
aarnold101 Sep 14, 2023
735e4c7
NewsletterSignup Functional Layout
aarnold101 Sep 20, 2023
00f217b
NewsletterSignup w/o onSubmit funtionality
aarnold101 Sep 22, 2023
706bf00
NewsletterSignup Near Complete Functionality
aarnold101 Sep 22, 2023
e7952c1
NewsletterSignup Updates & Fixes
aarnold101 Sep 25, 2023
5983419
NewsletterSignup Tests Round 1
aarnold101 Sep 26, 2023
3bd8d9d
NewsletterSignup w/o 3-second Timer
aarnold101 Sep 26, 2023
ac17c39
code cleanup
nypl-wluisi Sep 26, 2023
747b451
more code cleanup
nypl-wluisi Sep 27, 2023
4b33145
NewsletterSignup Update w/ Testing
aarnold101 Sep 28, 2023
8d53b28
Merge branch 'development' into RENO-3681/newslettersignup-component
aarnold101 Sep 28, 2023
f9dc57d
NewsletterSignup Snapshot Update
aarnold101 Sep 28, 2023
bcbb3b4
NewsletterSignup Minor Updates
aarnold101 Sep 28, 2023
117de84
NewsletterSignup Snapshot Update
aarnold101 Sep 28, 2023
8c603a9
code/storybook clean up
isastettler Oct 4, 2023
39670cc
fix darkmode, update storybook
isastettler Oct 4, 2023
e10e3de
add onChange and onSubmit test
isastettler Oct 5, 2023
26be513
fix onSubmit test, fix dark mode border bug
isastettler Oct 5, 2023
f7532ca
update confirmation props, update storybook, tests and Snapshots acco…
isastettler Oct 5, 2023
fa0c034
update storybook, add privacyPolicyLink prop
isastettler Oct 6, 2023
11aafed
fix title storybook bug, updated styles
isastettler Oct 6, 2023
87cc43d
fix descriptionText bug
isastettler Oct 10, 2023
7d141cc
fix "blogs" border color, add test for html props passed
isastettler Oct 10, 2023
f6bdbe9
add NewsletterSignup to component export file
isastettler Oct 10, 2023
abbe6eb
Add working onSubmit function and update .mdx
aarnold101 Oct 10, 2023
a4460e1
Merge branch 'development' into RENO-3681/newslettersignup-component
aarnold101 Oct 10, 2023
2b15b97
add props for error message, update styling and tests, add Newsletter…
isastettler Oct 11, 2023
9b31ea7
update storybook stories, fix typo
isastettler Oct 11, 2023
650e487
add interavtive example to storybook
isastettler Oct 11, 2023
cfcab79
add actions for onChange and onSubmit
isastettler Oct 11, 2023
8e5430f
remove styling, fix typos
isastettler Oct 12, 2023
d34bcc7
update as per PR comments
isastettler Oct 12, 2023
d926063
update snapshots
isastettler Oct 12, 2023
d99e940
Merge branch 'development' into RENO-3681/newslettersignup-component
isastettler Oct 12, 2023
1e634b1
update props, comments as discussed, update test and doc accordingly
isastettler Oct 12, 2023
3a56d1f
update breakpoints, remove reduntant content
isastettler Oct 12, 2023
917feb0
update breakpoint - the one that got away
isastettler Oct 12, 2023
3f42b6a
change html tags to ds components
isastettler Oct 12, 2023
77c31d7
update Text styles, fix typo for privacyPolicyLink, update tests
isastettler Oct 12, 2023
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
36 changes: 35 additions & 1 deletion src/components/NewsletterSignup/NewsletterSignup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ const meta: Meta<typeof NewsletterSignup> = {
},
},
},
errorHeading: {
control: "text",
table: {
defaultValue: {
summary: "Oops! Something went wrong.",
},
},
},
errorText: {
control: "text",
},
formHelperText: {
control: "text",
},
Expand Down Expand Up @@ -203,7 +214,20 @@ export const ComponentStates: Story = {
</Box>
<Box>
<Heading level="h3" size="heading6">
Error View
Deafult Error View
</Heading>
<NewsletterSignup
id="error-view"
view="error"
onChange={() => {}}
onSubmit={() => {}}
confirmationHeading="Thank you for signing up!"
confirmationText="You can update your email subscription preferences at any time using the links at the bottom of the email."
/>
</Box>
<Box>
<Heading level="h3" size="heading6">
Error View with Custom Error Message
</Heading>
<NewsletterSignup
id="error-view"
Expand All @@ -212,6 +236,16 @@ export const ComponentStates: Story = {
onSubmit={() => {}}
confirmationHeading="Thank you for signing up!"
confirmationText="You can update your email subscription preferences at any time using the links at the bottom of the email."
errorHeading="An error has occurred."
errorText={
<div>
Please refresh this page and try again. If this error persists,
<a href="mailto:[email protected]?subject=Please re-activate my e-mail address">
contact our e-mail team
</a>
.
</div>
isastettler marked this conversation as resolved.
Show resolved Hide resolved
}
/>
</Box>
</VStack>
Expand Down
30 changes: 28 additions & 2 deletions src/components/NewsletterSignup/NewsletterSignup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ describe("NewsletterSignup Unit Tests", () => {
it("Renders the Optional descriptionText and formHelperText HTML Values for the Form", () => {
const testNewsletterSignup = (
<NewsletterSignup
// This link is safe and fun - If you have a moment check it out ;)
descriptionText={
<div>
Do not send <a href="https://chias.website/">cash</a>.
isastettler marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -364,7 +365,7 @@ describe("NewsletterSignup Snapshots", () => {
expect(view).toMatchSnapshot();
});

it("Renders the error state snapshot correctly", () => {
it("Renders the default error state snapshot correctly", () => {
const view = renderer
.create(
<NewsletterSignup
Expand All @@ -380,6 +381,31 @@ describe("NewsletterSignup Snapshots", () => {
expect(view).toMatchSnapshot();
});

it("Renders the custom error state snapshot correctly", () => {
const view = renderer
.create(
<NewsletterSignup
onSubmit={onSubmit}
onChange={onChange}
valueEmail={valueEmail}
view="error"
confirmationHeading="Thank you for signing up!"
confirmationText="You can update your email subscription preferences at any time using the links at the bottom of the email."
errorHeading="Oh no! Something went wrong."
errorText={
<div>
If the error persists,
<a href="mailto:[email protected]?subject=Please re-activate my e-mail address">
contact our e-mail team
</a>
</div>
}
/>
)
.toJSON();
expect(view).toMatchSnapshot();
});

it("Renders the default confirmation state snapshot correctly", () => {
const view = renderer
.create(
Expand Down Expand Up @@ -411,7 +437,7 @@ describe("NewsletterSignup Snapshots", () => {
.toJSON();
expect(view).toMatchSnapshot();
});

// @TODO I don't think these test are working as intended as the colors are now set in the theme file.
describe("Renders each color for each newsletterSignupType correctly", () => {
// The newsletterSignupType values are determined by the types contained in the sectionDataMap.
// So it is safe to use the map directly.
Expand Down
80 changes: 54 additions & 26 deletions src/components/NewsletterSignup/NewsletterSignup.tsx
aarnold101 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
chakra,
Stack,
useColorModeValue,
useStyleConfig,
useMultiStyleConfig,
VStack,
} from "@chakra-ui/react";
import React, { forwardRef } from "react";
Expand All @@ -27,6 +27,10 @@ interface NewsletterSignupProps {
confirmationText: string;
/** Appears below the title to provide details about the newsletter. Accepts a string or an element. */
descriptionText?: string | JSX.Element;
/** Text displayed next to the error icon in case of an error in the email submission process*/
errorHeading?: string;
/** Appears below the title to provide details about next steps in case of an error. Accepts a string or an element. */
errorText?: string | JSX.Element;
/** Appears below the input field's example text to provide any additional instructions. Accepts a string or
* an element. */
formHelperText?: string | JSX.Element;
Expand All @@ -47,9 +51,15 @@ interface NewsletterSignupProps {
/** The value of the email text input field. */
valueEmail?: string;
/** Used to specify what is displayed in the component form/feedback area. */
view?: "form" | "submitting" | "confirmation" | "error";
view?: NewsletterSignupViewType;
}

export type NewsletterSignupViewType =
| "form"
| "submitting"
| "confirmation"
| "error";

const defaultDescriptionText =
"Stay connected with the latest research news from NYPL, including information about our events, programs, " +
"exhibitions, and collections.";
Expand All @@ -66,6 +76,8 @@ export const NewsletterSignup = chakra(
confirmationHeading,
confirmationText,
descriptionText = defaultDescriptionText,
errorHeading = "Oops! Something went wrong.",
errorText,
formHelperText,
id,
isInvalidEmail = false,
Expand All @@ -81,7 +93,7 @@ export const NewsletterSignup = chakra(
ref?
) => {
const { isLargerThanMobile } = useNYPLBreakpoints();
const styles = useStyleConfig("NewsletterSignup", {
const styles = useMultiStyleConfig("NewsletterSignup", {
newsletterSignupType,
});
const iconColor = useColorModeValue(null, "dark.ui.typography.body");
Expand All @@ -94,29 +106,33 @@ export const NewsletterSignup = chakra(
React.useEffect(() => {
focusRef.current?.focus();
}, [view]);

return (
<Stack
direction={isLargerThanMobile ? "row" : "column"}
ref={ref}
__css={styles}
{...rest}
>
<VStack id="pitch">
{title && <Heading level="h3" text={title} />}
<VStack __css={styles.pitch} alignItems="flex-start">
{title && <Heading level="h3" text={title} margin="unset" />}
bigfishdesign13 marked this conversation as resolved.
Show resolved Hide resolved
{descriptionText ? (
typeof descriptionText === "string" ? (
<Text>{descriptionText}</Text>
<Text margin="unset">{descriptionText}</Text>
isastettler marked this conversation as resolved.
Show resolved Hide resolved
) : (
descriptionText
)
) : null}

<Link href={privacyPolicyLink} type="external" id="privacy">
<Link
href={privacyPolicyLink}
type="external"
margin="unset"
__css={styles.privacy}
>
bigfishdesign13 marked this conversation as resolved.
Show resolved Hide resolved
Privacy Policy
</Link>
</VStack>
<VStack id="action">
<VStack __css={styles.action}>
{isFormView && (
<Form id="newsletter-form" onSubmit={onSubmit}>
<FormField key="formfield-input">
Expand Down Expand Up @@ -177,27 +193,39 @@ export const NewsletterSignup = chakra(
)}
{view === "error" && (
<Box
display="flex"
color="ui.error.primary"
className="feedback-body response"
margin="auto"
ref={focusRef}
tabIndex={0}
alignItems={{ md: "center" }}
width="full"
>
<Icon
color="ui.error.primary"
name="errorFilled"
size="large"
/>
{/* This text is boilerplate and not meant to be customized. */}
<Text
fontSize="xl"
marginStart="xs"
marginBottom="unset"
fontWeight="medium"
<Box
display="flex"
marginBottom="xs"
alignItems={{ md: "center" }}
>
Oops! Something went wrong.
</Text>
<Icon
color="ui.error.primary"
name="errorFilled"
size="large"
/>
{/* This text is boilerplate and not meant to be customized. */}
<Text
color="ui.error.primary"
fontSize="xl"
marginStart="xs"
marginBottom="unset"
fontWeight="medium"
>
{errorHeading}
</Text>
bigfishdesign13 marked this conversation as resolved.
Show resolved Hide resolved
</Box>
{errorText ? (
typeof errorText === "string" ? (
<Text margin="unset">{errorText}</Text>
isastettler marked this conversation as resolved.
Show resolved Hide resolved
) : (
errorText
)
) : null}
</Box>
)}
</VStack>
Expand Down
Loading
Loading