From fec7aa231fb520e528a5b69551a2cc67b68968f4 Mon Sep 17 00:00:00 2001 From: Ethan Lanting Date: Tue, 29 Oct 2024 16:00:56 -0500 Subject: [PATCH 1/2] refactor: mailto links for better formatting and sort help requests by latest to earliest --- components/HelpRequests.jsx | 111 ++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 44 deletions(-) diff --git a/components/HelpRequests.jsx b/components/HelpRequests.jsx index a064b09..bdf7cb7 100644 --- a/components/HelpRequests.jsx +++ b/components/HelpRequests.jsx @@ -93,6 +93,24 @@ const HelpRequests = () => { getData() }, []) + const getMailtoLink = (helpRequestInfo) => { + const formattedBody = + `Hi [NAME],%0A%0A%0A%0A%0A%0A` + + `Best Regards,%0A` + + `[YOUR NAME]%0A` + + `Truth Sleuth Support Team%0A%0A` + + `---%0A%0AForwarded Help Request:%0A%0A` + + `User ID: ${helpRequestInfo.userID}%0A` + + `Email: ${helpRequestInfo.email}%0A` + + `Subject: ${helpRequestInfo.subject}%0A` + + `Message: ${helpRequestInfo.message}%0A` + + `Created Date: ${helpRequestInfo.createdDate}%0A` + + `Images: ${helpRequestInfo.images.join(', ')}%0A` + + const mailtoLink = `mailto:${helpRequestInfo.email}?subject=${encodeURIComponent(helpRequestInfo.subject)}%20-%20Truth%20Sleuth%20Help%20Request&body=${formattedBody}` + return mailtoLink + } + return ( <>
@@ -130,50 +148,54 @@ const HelpRequests = () => { )} {helpRequests.length > 0 && - helpRequests.map((request) => ( - { - const { id, ...data } = request - handleRequestModalShow(data) - }} - key={request.id} - className={style.table_tr}> - {request.subject} - {request.message} - - { - e.stopPropagation() - }} - className="underline" - href={`mailto:${request.email}`} - target="_blank"> - {request.email} - - - {request.createdDate} - e.stopPropagation()}> - - - - ))} + helpRequests + .sort( + (a, b) => new Date(b.createdDate) - new Date(a.createdDate), + ) + .map((request) => ( + { + const { id, ...data } = request + handleRequestModalShow(data) + }} + key={request.id} + className={style.table_tr}> + {request.subject} + {request.message} + + { + e.stopPropagation() + }} + className="underline" + href={getMailtoLink(request)} + target="_blank"> + {request.email} + + + {request.createdDate} + e.stopPropagation()}> + + + + ))}
@@ -183,6 +205,7 @@ const HelpRequests = () => { )} From ffe798cce578a4c330e5126aa7dac6da060228d6 Mon Sep 17 00:00:00 2001 From: Ethan Lanting Date: Tue, 29 Oct 2024 16:01:16 -0500 Subject: [PATCH 2/2] refactor: add a Reply button with mailto link --- components/modals/HelpRequestsModal.jsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/components/modals/HelpRequestsModal.jsx b/components/modals/HelpRequestsModal.jsx index 00a4ef3..0548fe4 100644 --- a/components/modals/HelpRequestsModal.jsx +++ b/components/modals/HelpRequestsModal.jsx @@ -1,3 +1,4 @@ +import { Button } from '@material-tailwind/react' import Image from 'next/image' import Link from 'next/link' import React, { Fragment } from 'react' @@ -34,7 +35,7 @@ const formatLabel = (label) => { return label.replace(/([a-z])([A-Z])/g, '$1 $2') } -const HelpRequestsModal = ({ helpRequestInfo, handleClose }) => { +const HelpRequestsModal = ({ helpRequestInfo, handleClose, mailtoLink }) => { return (
@@ -50,7 +51,7 @@ const HelpRequestsModal = ({ helpRequestInfo, handleClose }) => {
-
+
{Object.entries(helpRequestInfo).map(([key, value], index) => ( @@ -81,7 +82,7 @@ const HelpRequestsModal = ({ helpRequestInfo, handleClose }) => {
) : key === 'email' ? ( {value} @@ -95,6 +96,20 @@ const HelpRequestsModal = ({ helpRequestInfo, handleClose }) => {
+ + + +