diff --git a/package.json b/package.json index e373969..97cc53a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plunk", - "version": "1.3.4", + "version": "1.3.5", "private": true, "license": "agpl-3.0", "workspaces": { diff --git a/packages/dashboard/src/pages/contacts/[id].tsx b/packages/dashboard/src/pages/contacts/[id].tsx index f5a9f3d..e58e2ec 100644 --- a/packages/dashboard/src/pages/contacts/[id].tsx +++ b/packages/dashboard/src/pages/contacts/[id].tsx @@ -8,7 +8,7 @@ import dayjs from "dayjs"; import {motion} from "framer-motion"; import {Save} from "lucide-react"; import {useRouter} from "next/router"; -import React, {useEffect, useState} from "react"; +import React, {useEffect, useState, useMemo} from "react"; import {useFieldArray, useForm} from "react-hook-form"; import {toast} from "sonner"; import {z} from "zod"; @@ -167,6 +167,22 @@ export default function Index() { await router.push("/contacts"); }; + const emailStats = useMemo(() => { + const totalEmails = contact.emails.length; + const deliveredEmails = contact.emails.filter(email => email.status === 'DELIVERED').length; + const openedEmails = contact.emails.filter(email => email.status === 'OPENED').length; + const bouncedEmails = contact.emails.filter(email => email.status === 'BOUNCED').length; + const complaintEmails = contact.emails.filter(email => email.status === 'COMPLAINT').length; + + return { + total: totalEmails, + delivered: deliveredEmails, + opened: openedEmails, + bounced: bouncedEmails, + complaint: complaintEmails, + }; + }, [contact.emails]); + return ( <> + + {emailStats.total > 0 ? ( +
+
+
{emailStats.total}
+
Total Emails
+
+
+
{emailStats.delivered}
+
Delivered
+ {emailStats.total > 0 && ( +
+ {((emailStats.delivered / emailStats.total) * 100).toFixed(1)}% +
+ )} +
+
+
{emailStats.opened}
+
Opened
+ {emailStats.total > 0 && ( +
+ {((emailStats.opened / emailStats.total) * 100).toFixed(1)}% +
+ )} +
+
+
{emailStats.bounced}
+
Bounced
+ {emailStats.total > 0 && ( +
+ {((emailStats.bounced / emailStats.total) * 100).toFixed(1)}% +
+ )} +
+
+
{emailStats.complaint}
+
Complaints
+ {emailStats.total > 0 && ( +
+ {((emailStats.complaint / emailStats.total) * 100).toFixed(1)}% +
+ )} +
+
+ ) : ( +
+
No emails sent to this contact yet
+
+ )} +
{contact.triggers.length > 0 || contact.emails.length > 0 ? (