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

85 create newsletter section #86

Merged
merged 8 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
"next-i18next": "^11.2.2",
"nextjs-toploader": "^1.4.2",
"react": "^18.2.0",
"react-confetti": "^6.1.0",
"react-dom": "^18.2.0",
"react-firebase-hooks": "^5.1.1",
"react-icons": "^4.11.0",
"react-mailchimp-subscribe": "^2.1.3",
"react-slick": "^0.29.0",
"react-test-renderer": "^18.2.0",
"react-toastify": "^9.1.3",
Expand Down
Binary file added public/images/newsletter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/newsletterBox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions src/components/Newsletter/NewsletterForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { useFormik } from "formik";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
import background from "public/images/newsletter.png";
import * as Yup from "yup";

import Input from "../Input";

function NewsletterForm({ onValidated }) {
const { t } = useTranslation();
const router = useRouter();
const formik = useFormik({
initialValues: {
email: "",
},
validationSchema: Yup.object({
email: Yup.string().email("invalid email").required("email is required"),
}),
onSubmit: async (values, { resetForm }) => {
try {
await onValidated({ EMAIL: values.email });
router.push({ pathname: "/success", query: values }, { scroll: false });
resetForm();
} catch (error) {
console.error("Error subscribing:", error);
}
},
});
return (
<div
className='bg-accent py-20 px-6 w-full'
style={{
backgroundImage: `url(${background.src})`,
backgroundSize: "cover",
}}
>
<h2 className='text-4xl tracking-tight font-extrabold text-white'>
Join our newsletter
</h2>
<p className='my-4 max-w-2xl font-light text-xl text-gray-200'>
Be the first to know about our latest blog posts, and insider updates.
Join us today.
</p>
<form
onSubmit={formik.handleSubmit}
className='flex flex-col md:flex-row gap-4'
>
<div>
<Input
name='email'
type='email'
placeholder='Enter your email'
handleChange={formik.handleChange}
value={formik.values.email}
handleBlur={(e) => formik.dirty && formik.handleBlur(e)}
error={formik.errors.email}
touched={formik.touched.email}
/>
{/* this is a spacer */}
<div className='label' />
</div>
<button
className='btn btn-neutral self-center rounded-3xl'
type='submit'
disabled={formik.isSubmitting}
>
{formik.isSubmitting ? "loading" : "Subscribe"}
</button>
</form>
</div>
);
}

export default NewsletterForm;
15 changes: 15 additions & 0 deletions src/components/Newsletter/__test__/Newsletter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import MailchimpSubscribe from "react-mailchimp-subscribe";
import renderer from "react-test-renderer";

import Newsletter from "..";

it("renders correctly", () => {
const tree = renderer
.create(
<Newsletter>
<MailchimpSubscribe url='' />
</Newsletter>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
8 changes: 8 additions & 0 deletions src/components/Newsletter/__test__/NewsletterForm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import renderer from "react-test-renderer";

import NewsletterForm from "../NewsletterForm";

it("renders correctly", () => {
const tree = renderer.create(<NewsletterForm />).toJSON();
expect(tree).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<div
className="bg-accent py-20 px-6 w-full"
style={
Object {
"backgroundImage": "url(/img.jpg)",
"backgroundSize": "cover",
}
}
>
<h2
className="text-4xl tracking-tight font-extrabold text-white"
>
Join our newsletter
</h2>
<p
className="my-4 max-w-2xl font-light text-xl text-gray-200"
>
Be the first to know about our latest blog posts, and insider updates. Join us today.
</p>
<form
className="flex flex-col md:flex-row gap-4"
onSubmit={[Function]}
>
<div>
<div>
<div
className="label ml-2"
>
<label
className="label-text"
htmlFor="email"
/>
<label
className="label-text-alt "
/>
</div>
<input
className="input bg-white input-primary w-full rounded-full border-opacity-25"
id="email"
name="email"
onBlur={[Function]}
onChange={[Function]}
placeholder="Enter your email"
type="email"
value=""
/>
</div>
<div
className="label"
/>
</div>
<button
className="btn btn-neutral self-center rounded-3xl"
disabled={false}
type="submit"
>
Subscribe
</button>
</form>
</div>
`;
Loading
Loading