Please check your inbox and click the link to continue.
+
+
+ );
+};
+
+export default EmailVerificationPage;
diff --git a/src/pages/SubscribePage.js b/src/pages/SubscribePage.js
index e448856..01fe967 100644
--- a/src/pages/SubscribePage.js
+++ b/src/pages/SubscribePage.js
@@ -1,11 +1,20 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import axios from "axios";
import { toast } from "react-hot-toast";
import { Link } from "react-router-dom";
+import Cookies from "js-cookie";
+import { useNavigate } from "react-router-dom";
export const SubscriptionPage = () => {
const [email, setEmail] = useState("");
+ const navigate = useNavigate();
+ useEffect(() => {
+ const storedEmail = Cookies.get("email");
+ if (storedEmail) {
+ setEmail(storedEmail);
+ }
+ }, []);
const handleSubscribe = async (e) => {
e.preventDefault();
@@ -24,7 +33,10 @@ export const SubscriptionPage = () => {
if (response.status === 200) {
toast.success("Subscription successful!");
- setEmail("");
+ } else if (response.status === 202) {
+ toast("I know you are excited but you are already subscribed!", {
+ icon: "😃",
+ });
} else {
toast.error("Failed to subscribe");
}
@@ -47,15 +59,18 @@ export const SubscriptionPage = () => {
try {
const response = await axios.post(
- "http://localhost:4000/api/users/unsubscribe",
+ "http://localhost:4000/api/users/email-unsubscribe",
{
email: email,
}
);
if (response.status === 200) {
- toast.success("Unsubscribe successful!");
- setEmail("");
+ navigate("/email");
+ } else if (response.status === 202) {
+ toast("You are no longer subscribed, please stop trying.", {
+ icon: "🤷♂️",
+ });
} else {
toast.error("Failed to unsubscribe");
}
@@ -87,9 +102,8 @@ export const SubscriptionPage = () => {
Do you want to receive notifications when there is a new post?
- Enter your email address to which you wish to receive notifications
- from us. If you are already subscribed and want to unsubscribe,
- enter your email and click on the unsubscribe button.
+ If you subscribe and then want to unsubscribe you have to verify
+ your email (you can only subscribe your email in session)