diff --git a/src/App.js b/src/App.js index a8c1730..f2d1cb0 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,3 @@ -import logo from './logo.svg'; import './App.css'; import { BrowserRouter as Router, Route, Switch } from "react-router-dom"; import ReactNotification from "react-notifications-component"; diff --git a/src/BulkEmail.js b/src/BulkEmail.js index ce8eb8d..769d60d 100644 --- a/src/BulkEmail.js +++ b/src/BulkEmail.js @@ -1,15 +1,15 @@ import React, { useState, useEffect } from "react"; import { store } from "react-notifications-component"; -import axios from "axios"; const EmailTemplate = () => { const [email, setEmail] = useState([]); const [name, setName] = useState([]); const [html, setHtml] = useState(""); + const [loading, setLoading] = useState(false); const [subject, setSubject] = useState(""); const [sender_email, setSender_Email] = useState(""); - const [webinar_link, setWebinarLink] = useState(""); - + const [bounced_emails, setBouncedEmails] = useState([]); + const [delivered_emails, setDeliveredEmails] = useState([]); const notifyPopup = (title,message,type) => { store.addNotification({ title:title , @@ -27,24 +27,18 @@ const EmailTemplate = () => { }); }; + var emailarray = email.toString().split(","); async function handleSubmit(e) { e.preventDefault(); - var emailarray = email.toString().split(","); emailarray = emailarray.map(value => value.trim()) - if (emailarray == "") { notifyPopup("error","emails empty","danger"); } + if (!email.length) { notifyPopup("error","emails empty","danger"); return;} var namearray = name.toString().split(","); namearray = namearray.map(value => value.trim()) - if (namearray == "") { notifyPopup("error","names empty","danger"); } - if (subject == "") { notifyPopup("error","subject empty","danger"); } - if (html == "") { notifyPopup("error","html empty","danger"); } - if (sender_email == "") { notifyPopup("error","sender email empty","danger"); } - - console.log("emails "+emailarray) - console.log("names "+namearray) - console.log("html "+typeof(html)) - console.log("subject "+typeof( subject )) - console.log("sender" + typeof(sender_email)); - fetch("https://slb37ny1bh.execute-api.ap-south-1.amazonaws.com/prod/email_batcher", { + if (subject === "") { notifyPopup("error","subject empty","danger"); return;} + if (html === "") { notifyPopup("error","html empty","danger"); return;} + if (sender_email === "") { notifyPopup("error", "sender email empty", "danger"); return; } + //setBouncedEmails([]) + await fetch("https://slb37ny1bh.execute-api.ap-south-1.amazonaws.com/prod/email_batcher", { method: "post", body: JSON.stringify({ "email": emailarray, @@ -57,14 +51,52 @@ const EmailTemplate = () => { .then((res) => res.json()) .then((result) => { console.log(result); - notifyPopup("Success",result.toString(),"success"); - }); - + result.forEach((value, index) => { + setBouncedEmails(oldArray => [...oldArray, value.email.slice(2, -2).concat(',')]); + }); + }) + //var common = emailarray.filter(x => bouncedarray.indexOf(x) !== -1) + setLoading(true); } + useEffect(() => { + + var bouncedarray = bounced_emails.toString().split(',') + bouncedarray = bouncedarray.map(value => value.trim()) + console.log("bounce array ", bouncedarray) + var common = emailarray.filter(x => !bouncedarray.includes(x)) + console.log("common array ", common) + setDeliveredEmails([]) + common.forEach((value, index) => { + setDeliveredEmails(oldArray => [...oldArray,value.concat(',')] ); + }); + },[bounced_emails]) + useEffect(() => { + + console.log("delivered ", delivered_emails ) + },[delivered_emails]) return ( <>