From 23518f00d952a74d9dda0a6ff0dce48dcc8b3f5e Mon Sep 17 00:00:00 2001 From: Priyatham Sai Chand Date: Thu, 11 Nov 2021 13:51:58 +0530 Subject: [PATCH] add css for bounces --- src/BulkEmail.js | 98 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 23 deletions(-) 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 ( <>
- {loading ? + {loading ? + <> +
+
+
+ Loading... +
+
+
+ : + <> +{data_loading ? <> +
+

+ Sent Details +

Delivered emails

- {delivered_emails} + + {delivered_emails.length !== 0 ? (
+
    +{delivered_emails.map((item,index) => +
  • {item}
  • +)} +
+ +
) : (
No emails sent
)} +

Bounced Emails

- {bounced_emails} + {bounced_emails.length !== 0 ? (
+
    +{bounced_emails.map((item,index) => +
  • {item}
  • +)} +
+ + +
) : (
No bounces
)}
+
@@ -162,17 +214,12 @@ const EmailTemplate = () => { >
-

Enter sender's Email

-
nametodisplay <email-id>
-

email in angular brackets

- setSender_Email(e.target.value)} - /> +

Select sender's Email

+
@@ -189,6 +236,11 @@ const EmailTemplate = () => { } + + } + + + );