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

Email Signup Submission Fixed #1119

Merged
merged 7 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
143 changes: 68 additions & 75 deletions frontend/src/components/Footer/Footer.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from "react";
import { Link } from "react-router-dom";
import style from "./footer.module.scss";
import { postSubscriber } from '../../service/Subscriber'
import { SimpleToast } from "../util/Toast";

//react-icon
import { FiCheckSquare } from "react-icons/fi";
Expand All @@ -12,6 +14,11 @@ export const Footer = (props) => {
const [email, setEmail] = useState("");
//setting email error
const [emailErr, setEmailErr] = useState({});
const [toast, setToast] = useState({
toastStatus: false,
toastType: "",
toastMessage: "",
});

const emailValidation = (email) => {
let isValid = true;
Expand Down Expand Up @@ -47,14 +54,15 @@ export const Footer = (props) => {
};

//handling submit
const handleSubmit = (e) => {
const handleSubmit = async(e) => {
e.preventDefault();
//if isValid = true, form submission trigger
const isValid = validation();
if (isValid) {
setSubmited(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every new user, there should be a welcome email sent to the subscribers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a frontend part... the email sent part should be done in backend.
Merge the request and i will add the email functionality in new issue.

const res=await postSubscriber({email},setToast)
//resetting email value in state after submission of form
setEmail("");
if(res)
setEmail("");
}
};
var date = new Date();
Expand Down Expand Up @@ -87,93 +95,70 @@ export const Footer = (props) => {
>
<p>Email: [email protected]</p>
</a>
{submited ? (
<React.Fragment>
<div
<React.Fragment>
<div className={style["newsletter"]}>
<h2
className={
dark
? `${style["subscribe-card"]} ${style["subscribe-card-dark"]}`
: `${style["subscribe-card"]} `
dark ? style["nav-title-dark"] : style["nav-title"]
}
>
<h1
Sign Up for our Newsletter
</h2>
<p>
Receive updates and news about various Job Opportunities,
Internships, Webinars and Open Source Events.
</p>
<form
className="d-flex flex-column flex-md-row align-items-center mt-4"
onSubmit={handleSubmit}
>
<input
autoComplete="off"
type="text"
name="email"
className={
dark
? `${style["card-heading"]} ${style["card-heading-dark"]}`
: `${style["card-heading"]} `
}
>
successfully subscribed to our newsletter
<FiCheckSquare className={style["newsletter-icon"]} />
</h1>
</div>
</React.Fragment>
) : (
<React.Fragment>
<div className={style["newsletter"]}>
<h2
className={
dark ? style["nav-title-dark"] : style["nav-title"]
? `${style["input-field-footer"]} ${style["input-field-footer-dark"]}`
: `${style["input-field-footer"]}`
}
>
Sign Up for our Newsletter
</h2>
<p>
Receive updates and news about various Job Opportunities,
Internships, Webinars and Open Source Events.
</p>
<form
className="d-flex flex-column flex-md-row align-items-center mt-4"
onSubmit={handleSubmit}
>
<input
autoComplete="off"
type="text"
name="email"
className={
dark
? `${style["input-field-footer"]} ${style["input-field-footer-dark"]}`
: `${style["input-field-footer"]}`
}
placeholder="Email Id"
onChange={handleEmailChange}
value={email}
/>
<br />
{Object.keys(emailErr).map((key) => {
return (
<div
className={`${style["validation"]} d-sm-block d-md-none`}
key={key}
>
{emailErr[key]}
</div>
);
})}
<button
type="submit"
className={
dark
? `mt-3 mt-md-0 ${style["submit-btn-footer"]} py-2 px-3 mt-3 mt-md-0 ${style["submit-btn-footer-dark"]} py-2 px-3 `
: `mt-3 mt-md-0 ${style["submit-btn-footer"]} py-2 px-3 `
}
>
Sign Up
</button>
</form>
placeholder="Email Id"
onChange={handleEmailChange}
value={email}
/>
<br />
{Object.keys(emailErr).map((key) => {
return (
<div
className={`${style["validation-new"]} validation-new d-sm-none d-md-block`}
className={`${style["validation"]} d-sm-block d-md-none`}
key={key}
>
{emailErr[key]}
</div>
);
})}
</div>
</React.Fragment>
)}
<button
type="submit"
className={
dark
? `mt-3 mt-md-0 ${style["submit-btn-footer"]} py-2 px-3 mt-3 mt-md-0 ${style["submit-btn-footer-dark"]} py-2 px-3 `
: `mt-3 mt-md-0 ${style["submit-btn-footer"]} py-2 px-3 `
}
>
Sign Up
</button>
</form>
{Object.keys(emailErr).map((key) => {
return (
<div
className={`${style["validation-new"]} validation-new d-sm-none d-md-block`}
key={key}
>
{emailErr[key]}
</div>
);
})}
</div>
</React.Fragment>
</div>
<ul className={style["footer-nav"]}>
<li className={style["nav-item"]}>
Expand Down Expand Up @@ -384,6 +369,14 @@ export const Footer = (props) => {
<p className={`${style["cprt"]} py-2`}>
Copyright © {year} HITK Tech Community
</p>
{toast.toastStatus && (
<SimpleToast
open={toast.toastStatus}
message={toast.toastMessage}
handleCloseToast={() => { setToast({ toastStatus: false, toastMessage: "", toastType: "" }) }}
severity={toast.toastType}
/>
)}
</div>
</React.Fragment>
);
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/service/Subscriber.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { END_POINT } from "../config/api";
import { showToast } from "./toastService";

const postSubscriber = async (data, setToast) => {
try {
const response = await fetch(`${END_POINT}/subscriber/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});

if (response.ok) {
const _data = await response.json();
showToast(setToast, "Newsletter Subscribed successfully", "success");
return true;
} else {
const errorData = await response.json();
console.error("Error:", errorData);
showToast(setToast, "You already subscribed", "error");
return false;
}
} catch (err) {
console.error("Network Error:", err);
showToast(setToast, "Something went wrong", "error");
return false;
}
};

export { postSubscriber };
Loading