From 500332fa928a1a34ed2077bbe4c628a278522b87 Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 28 May 2024 13:03:01 -0700 Subject: [PATCH 1/5] updated URL --- cron/sendEmail.mjs | 2 +- src/app/admin/emailHandler.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cron/sendEmail.mjs b/cron/sendEmail.mjs index 76c7429..eca69b8 100644 --- a/cron/sendEmail.mjs +++ b/cron/sendEmail.mjs @@ -32,7 +32,7 @@ const sendEmail = async recipient => {
  • Payment Plans: Choose from flexible payment plans that suit your budget and hiring needs.
  • Ready to take your hiring to the next level? Sign up now via the link below and start reaching the talent you've been looking for!

    -

    Sign Up Now

    +

    Sign Up Now

    Don't miss out on the opportunity to find your next great hire effortlessly. Join us today and experience the power of our job panel!

    Best regards,

    The [Job Panel] Team

    `, diff --git a/src/app/admin/emailHandler.js b/src/app/admin/emailHandler.js index a9dc32b..d5b327d 100644 --- a/src/app/admin/emailHandler.js +++ b/src/app/admin/emailHandler.js @@ -42,7 +42,7 @@ const sendEmail = async recipient => {
  • Payment Plans: Choose from flexible payment plans that suit your budget and hiring needs.
  • Ready to take your hiring to the next level? Sign up now via the link below and start reaching the talent you've been looking for!

    -

    Sign Up Now

    +

    Sign Up Now

    Don't miss out on the opportunity to find your next great hire effortlessly. Join us today and experience the power of our job panel!

    Best regards,

    The [Job Panel] Team

    `, From 789996d26376f09b11a14f35aabc7e052761a32b Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 28 May 2024 21:04:37 -0700 Subject: [PATCH 2/5] updated env name --- cron/sendEmail.mjs | 2 +- src/app/admin/emailHandler.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cron/sendEmail.mjs b/cron/sendEmail.mjs index eca69b8..dbae36d 100644 --- a/cron/sendEmail.mjs +++ b/cron/sendEmail.mjs @@ -32,7 +32,7 @@ const sendEmail = async recipient => {
  • Payment Plans: Choose from flexible payment plans that suit your budget and hiring needs.
  • Ready to take your hiring to the next level? Sign up now via the link below and start reaching the talent you've been looking for!

    -

    Sign Up Now

    +

    Sign Up Now

    Don't miss out on the opportunity to find your next great hire effortlessly. Join us today and experience the power of our job panel!

    Best regards,

    The [Job Panel] Team

    `, diff --git a/src/app/admin/emailHandler.js b/src/app/admin/emailHandler.js index d5b327d..55109d6 100644 --- a/src/app/admin/emailHandler.js +++ b/src/app/admin/emailHandler.js @@ -42,7 +42,7 @@ const sendEmail = async recipient => {
  • Payment Plans: Choose from flexible payment plans that suit your budget and hiring needs.
  • Ready to take your hiring to the next level? Sign up now via the link below and start reaching the talent you've been looking for!

    -

    Sign Up Now

    +

    Sign Up Now

    Don't miss out on the opportunity to find your next great hire effortlessly. Join us today and experience the power of our job panel!

    Best regards,

    The [Job Panel] Team

    `, From 5d0fa5aeb22b2a026787ff940fd188f6fab33c74 Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 28 May 2024 21:04:51 -0700 Subject: [PATCH 3/5] added alert after sending email --- src/app/admin/page.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/admin/page.js b/src/app/admin/page.js index 2a230ed..4cca1ac 100644 --- a/src/app/admin/page.js +++ b/src/app/admin/page.js @@ -83,6 +83,8 @@ export default function Home() { console.error('Error sending email:', error); } + alert('Email sent to ' + recipient); + setEmails(prevEmails => prevEmails.map(emailObj => emailObj.email === recipient ? { ...emailObj, sent: true } : emailObj From 57eebdceaf2993089691e4648e98e79abd35eeee Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 28 May 2024 21:54:43 -0700 Subject: [PATCH 4/5] sort email by added time --- src/app/admin/page.js | 10 ++++------ src/app/api/contact-stat/route.js | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/app/admin/page.js b/src/app/admin/page.js index 4cca1ac..4679407 100644 --- a/src/app/admin/page.js +++ b/src/app/admin/page.js @@ -20,27 +20,25 @@ export default function Home() { const userData = await response.json(); if (userData.data && userData.data.admin === true) { setUser(userData); - console.log('User is admin'); } else { - console.log('User is not admin'); setUnauthorized(true); setTimeout(() => { window.location.href = '/'; - }, 3000); // Redirect after 3 seconds + }, 2000); // Redirect after 2 seconds } } else { console.error('Failed to fetch user:', response.statusText); setUnauthorized(true); setTimeout(() => { window.location.href = '/'; - }, 3000); // Redirect after 3 seconds + }, 2000); // Redirect after 2 seconds } } catch (error) { console.error('Error fetching user:', error); setUnauthorized(true); setTimeout(() => { window.location.href = '/'; - }, 3000); // Redirect after 3 seconds + }, 2000); // Redirect after 2 seconds } finally { setLoading(false); } @@ -67,7 +65,7 @@ export default function Home() { const updateEmails = (emailObj, isAdd) => { if (isAdd) { - setEmails(prevEmails => [...prevEmails, emailObj]); + setEmails(prevEmails => [emailObj, ...prevEmails]); } else if (!isAdd) { const updatedEmails = emails.filter( existingEmail => existingEmail.email !== emailObj.email diff --git a/src/app/api/contact-stat/route.js b/src/app/api/contact-stat/route.js index 53b07c3..3bcb576 100644 --- a/src/app/api/contact-stat/route.js +++ b/src/app/api/contact-stat/route.js @@ -11,7 +11,7 @@ export async function GET() { mongoose.models['contact-stats'] || mongoose.model('contact-stats', contactStat); - const contactStats = await ContactStat.find(); + const contactStats = await ContactStat.find().sort({ _id: -1 }); return NextResponse.json({ contactStats }, { status: 200 }); } catch (error) { From fcb8f1097d1299523b17407f398117ffc52b1f7c Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 28 May 2024 21:55:07 -0700 Subject: [PATCH 5/5] added indication while adding and sending email --- src/components/component/addEmailModal.jsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/component/addEmailModal.jsx b/src/components/component/addEmailModal.jsx index e42f863..3377a5a 100644 --- a/src/components/component/addEmailModal.jsx +++ b/src/components/component/addEmailModal.jsx @@ -32,6 +32,8 @@ const CloseButton = ({ onClick }) => ( export function AddEmailModal({ open, onClose, updateEmails }) { const [email, setEmail] = useState(''); const [emailsAdded, setEmailsAdded] = useState(1); + const [isAdding, setIsAdding] = useState(false); + const [isAddingAndSending, setIsAddingAndSending] = useState(false); // Reset email state when the modal is opened useEffect(() => { @@ -47,6 +49,9 @@ export function AddEmailModal({ open, onClose, updateEmails }) { }; const handleAddEmail = async () => { + // Set isAdding to true to indicate that the email is being added + setIsAdding(true); + try { if (!validateEmail(email)) { alert('Please enter a valid email address'); @@ -55,6 +60,7 @@ export function AddEmailModal({ open, onClose, updateEmails }) { // Call the addEmailObjects function with an array of length 1 containing the email object const emailsAdded = await emailHandler.addEmailObjects([ { email, sent: false }, + //indicate to UI that email is being added ]); setEmailsAdded(emailsAdded); setEmail(''); @@ -64,10 +70,15 @@ export function AddEmailModal({ open, onClose, updateEmails }) { updateEmails({ email, sent: false }, isAdd); } catch (error) { console.error('Error adding email objects:', error); + } finally { + // Set isAdding to false after adding the email + setIsAdding(false); } }; const handleAddAndSendEmail = async () => { + setIsAddingAndSending(true); + try { if (!validateEmail(email)) { alert('Please enter a valid email address'); @@ -83,6 +94,8 @@ export function AddEmailModal({ open, onClose, updateEmails }) { updateEmails({ email, sent: true }, isAdd); } catch (error) { console.error('Error adding email objects:', error); + } finally { + setIsAddingAndSending(false); } }; @@ -109,9 +122,11 @@ export function AddEmailModal({ open, onClose, updateEmails }) { />
    - +
    {/* Display warning/notification field if emailsAdded is less than 1 */}