From 58b2504e1454b69b05111f976832d62d886f02f9 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 10 Jun 2025 00:53:49 +0200 Subject: [PATCH] updates --- components/EOISection.vue | 30 ++++++++++++++++++++--- server/api/email/fetch-thread.ts | 6 +++++ server/api/email/generate-eoi-document.ts | 12 ++++----- server/api/email/send.ts | 18 +++++++++++--- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/components/EOISection.vue b/components/EOISection.vue index 30afa53..225ec92 100644 --- a/components/EOISection.vue +++ b/components/EOISection.vue @@ -160,14 +160,36 @@ const generateEOI = async () => { } }; -const copyLink = (link: string | undefined) => { +const copyLink = async (link: string | undefined) => { if (!link) return; - navigator.clipboard.writeText(link).then(() => { + try { + await navigator.clipboard.writeText(link); showToast('Signature link copied to clipboard'); - }).catch(() => { + + // Update EOI Time Sent if not already set + if (!props.interest['EOI Time Sent']) { + try { + await $fetch('/api/update-interest', { + method: 'POST', + headers: { + 'x-tag': '094ut234' + }, + body: { + id: props.interest.Id.toString(), + data: { + 'EOI Time Sent': new Date().toISOString() + } + } + }); + emit('update'); // Refresh parent data + } catch (error) { + console.error('Failed to update EOI Time Sent:', error); + } + } + } catch (error) { showToast('Failed to copy link'); - }); + } }; const formatDate = (dateString: string) => { diff --git a/server/api/email/fetch-thread.ts b/server/api/email/fetch-thread.ts index 6f2f05e..f1f714c 100644 --- a/server/api/email/fetch-thread.ts +++ b/server/api/email/fetch-thread.ts @@ -204,6 +204,12 @@ async function fetchImapEmails( // Search for emails both sent and received with this client // Note: BCC search might not be supported by all IMAP servers + if (!clientEmail || clientEmail.trim() === '') { + console.log('No client email provided, skipping search'); + searchNextFolder(); + return; + } + const searchCriteria = [ 'OR', ['FROM', clientEmail], diff --git a/server/api/email/generate-eoi-document.ts b/server/api/email/generate-eoi-document.ts index 33cca41..b401fa3 100644 --- a/server/api/email/generate-eoi-document.ts +++ b/server/api/email/generate-eoi-document.ts @@ -256,22 +256,22 @@ export default defineEventHandler(async (event) => { // 4. Update interest record const currentDate = new Date(); - const dateTimeString = currentDate.toLocaleString('en-US', { - year: 'numeric', - month: '2-digit', + const dateTimeString = currentDate.toLocaleString('en-GB', { day: '2-digit', + month: '2-digit', + year: 'numeric', hour: '2-digit', minute: '2-digit', - hour12: true + hour12: false }); const extraComments = interest['Extra Comments'] || ''; - const updatedComments = extraComments + (extraComments ? '\n' : '') + `EOI Sent ${dateTimeString}`; + const updatedComments = extraComments + (extraComments ? '\n' : '') + `EOI Generated ${dateTimeString}`; const updateData: any = { 'EOI Status': 'Waiting for Signatures', 'Sales Process Level': 'LOI and NDA Sent', - 'EOI Time Sent': currentDate.toISOString(), + // Don't set EOI Time Sent here - only when email is sent or link is copied 'Extra Comments': updatedComments }; diff --git a/server/api/email/send.ts b/server/api/email/send.ts index 6bc3965..816d7f7 100644 --- a/server/api/email/send.ts +++ b/server/api/email/send.ts @@ -1,6 +1,7 @@ import nodemailer from 'nodemailer'; import { getCredentialsFromSession, decryptCredentials } from '~/server/utils/encryption'; import { uploadFile } from '~/server/utils/minio'; +import { updateInterest } from '~/server/utils/nocodb'; export default defineEventHandler(async (event) => { const xTagHeader = getRequestHeader(event, "x-tag"); @@ -49,14 +50,13 @@ export default defineEventHandler(async (event) => { const signature = includeSignature ? `

+ Port Nimara
${sig.name || defaultName}
${sig.title || 'Sales & Marketing Director'}
${sig.company || 'Port Nimara'}
${contactLines ? contactLines + '
' : ''} ${sig.email || email}

- Port Nimara -
The information in this message is confidential and may be privileged.
It is intended for the addressee alone.
@@ -92,7 +92,7 @@ export default defineEventHandler(async (event) => { html: htmlBody // HTML version with signature }); - // Store email in MinIO for thread history + // Store email in MinIO for thread history and update EOI Time Sent if (interestId) { try { const emailData = { @@ -115,6 +115,18 @@ export default defineEventHandler(async (event) => { buffer, 'application/json' ); + + // Update EOI Time Sent if the email contains an EOI link + if (emailBody.includes('signatures.portnimara.dev/sign/')) { + try { + await updateInterest(interestId, { + 'EOI Time Sent': new Date().toISOString() + }); + } catch (updateError) { + console.error('Failed to update EOI Time Sent:', updateError); + // Continue even if update fails + } + } } catch (storageError) { console.error('Failed to store email in MinIO:', storageError); // Continue even if storage fails