diff --git a/src/BulkEmail.js b/src/BulkEmail.js index 97e601c..f45e6bf 100644 --- a/src/BulkEmail.js +++ b/src/BulkEmail.js @@ -6,6 +6,7 @@ const EmailTemplate = () => { const [name, setName] = useState([]); const [html, setHtml] = useState(""); const [loading, setLoading] = useState(false); + const [data_loading, setDataLoading] = useState(false); const [subject, setSubject] = useState(""); const [sender_email, setSender_Email] = useState(""); const [bounced_emails, setBouncedEmails] = useState([]); @@ -28,6 +29,7 @@ const EmailTemplate = () => { }; var emailarray = email.toString().split(","); + emailarray = emailarray.filter(function (e) { return e }); async function handleSubmit(e) { e.preventDefault(); emailarray = emailarray.map(value => value.trim()) @@ -38,6 +40,7 @@ const EmailTemplate = () => { if (html === "") { notifyPopup("error","html empty","danger"); return;} if (sender_email === "") { notifyPopup("error", "sender email empty", "danger"); return; } //setBouncedEmails([]) + setLoading(true); await fetch("https://slb37ny1bh.execute-api.ap-south-1.amazonaws.com/prod/email_batcher", { method: "post", body: JSON.stringify({ @@ -51,28 +54,44 @@ const EmailTemplate = () => { .then((res) => res.json()) .then((result) => { console.log(result); + console.log(result.length); + if(result.length) result.forEach((value, index) => { - setBouncedEmails(oldArray => [...oldArray, value.email.slice(2, -2).concat(',')]); + setBouncedEmails(oldArray => [...oldArray, value.email.slice(2, -2)]); }); }) //var common = emailarray.filter(x => bouncedarray.indexOf(x) !== -1) - if (!bounced_emails.length) { setDeliveredEmails(emailarray);} - setLoading(true); + setLoading(false); + setDataLoading(true); } + useEffect(() => { var bouncedarray = bounced_emails.toString().split(',') - bouncedarray = bouncedarray.map(value => value.trim()) + //bouncedarray = bouncedarray.map(value => value.trim()) + bouncedarray = bouncedarray.filter(function (e) { return e }); console.log("bounce array ", bouncedarray) + console.log("bounced array count", bounced_emails.length) + console.log("email array ", emailarray) + if (bounced_emails.length !== 0) { var common = emailarray.filter(x => !bouncedarray.includes(x)) - console.log("common array ", common) + console.log("common with bounced array ", common) setDeliveredEmails([]) - //if (!bounced_emails.length) { setDeliveredEmails(emailarray); return; } - common.forEach((value, index) => { - setDeliveredEmails(oldArray => [...oldArray,value.concat(',')] ); + common.forEach((value, index) => { setDeliveredEmails(oldArray => [...oldArray,value] ); }); - },[bounced_emails]) + } + if(bounced_emails.length === 0 && emailarray.length !== 0){ + console.log(" else bounce array ", bouncedarray) + console.log(" else bounced array count", bounced_emails.length) + console.log(" else email array ", emailarray) + setDeliveredEmails([]) + emailarray.forEach((value, index) => { + console.log("email with no bounces", value); setDeliveredEmails(oldArray => [...oldArray,value] ); + }) + } + //if (!bounced_emails.length) { setDeliveredEmails(emailarray); return; } + },[data_loading]) useEffect(() => { console.log("delivered ", delivered_emails ) @@ -80,18 +99,51 @@ const EmailTemplate = () => { return ( <>
email in angular brackets
- setSender_Email(e.target.value)} - /> +