updates
This commit is contained in:
parent
bd07939c3d
commit
bb1a237961
|
|
@ -6,8 +6,16 @@
|
|||
</v-card-title>
|
||||
<v-card-text class="pt-0">
|
||||
|
||||
<!-- Email Credentials Setup -->
|
||||
<EmailCredentialsSetup
|
||||
v-if="!hasEmailCredentials"
|
||||
@credentials-saved="onCredentialsSaved"
|
||||
/>
|
||||
|
||||
<div v-else>
|
||||
|
||||
<!-- Compose New Email -->
|
||||
<div class="mb-4">
|
||||
<div class="mb-4 d-flex align-center gap-2">
|
||||
<v-btn
|
||||
@click="showComposer = true"
|
||||
color="primary"
|
||||
|
|
@ -16,6 +24,15 @@
|
|||
>
|
||||
Compose Email
|
||||
</v-btn>
|
||||
<v-btn
|
||||
@click="loadEmailThread"
|
||||
variant="text"
|
||||
icon="mdi-refresh"
|
||||
:loading="isRefreshing"
|
||||
size="small"
|
||||
>
|
||||
<v-tooltip activator="parent">Refresh Emails</v-tooltip>
|
||||
</v-btn>
|
||||
</div>
|
||||
|
||||
<!-- Email Thread List -->
|
||||
|
|
@ -67,10 +84,11 @@
|
|||
</v-timeline>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="text-center py-8 text-grey">
|
||||
<v-icon size="48" class="mb-3">mdi-email-outline</v-icon>
|
||||
<div>No email communication yet</div>
|
||||
<!-- Empty State -->
|
||||
<div v-else class="text-center py-8 text-grey">
|
||||
<v-icon size="48" class="mb-3">mdi-email-outline</v-icon>
|
||||
<div>No email communication yet</div>
|
||||
</div>
|
||||
</div>
|
||||
</v-card-text>
|
||||
|
||||
|
|
@ -150,17 +168,121 @@
|
|||
ref="contentTextarea"
|
||||
/>
|
||||
|
||||
<!-- Signature Settings -->
|
||||
<v-expansion-panels variant="accordion" class="my-4">
|
||||
<v-expansion-panel>
|
||||
<v-expansion-panel-title>
|
||||
<v-icon class="mr-2">mdi-draw-pen</v-icon>
|
||||
Email Signature Settings
|
||||
</v-expansion-panel-title>
|
||||
<v-expansion-panel-text>
|
||||
<v-checkbox
|
||||
v-model="includeSignature"
|
||||
label="Include signature"
|
||||
hide-details
|
||||
class="mb-3"
|
||||
/>
|
||||
<div v-if="includeSignature">
|
||||
<v-text-field
|
||||
v-model="signatureConfig.name"
|
||||
label="Your Name"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
class="mb-2"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="signatureConfig.title"
|
||||
label="Job Title"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
class="mb-2"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="signatureConfig.company"
|
||||
label="Company"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
class="mb-2"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="signatureConfig.email"
|
||||
label="Email"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
class="mb-2"
|
||||
/>
|
||||
<v-textarea
|
||||
v-model="signatureConfig.contactInfo"
|
||||
label="Additional Contact Info"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
rows="2"
|
||||
/>
|
||||
</div>
|
||||
</v-expansion-panel-text>
|
||||
</v-expansion-panel>
|
||||
</v-expansion-panels>
|
||||
|
||||
<!-- Attachments -->
|
||||
<v-file-input
|
||||
v-model="emailDraft.attachments"
|
||||
label="Attachments"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
multiple
|
||||
chips
|
||||
prepend-icon="mdi-paperclip"
|
||||
class="mt-4"
|
||||
/>
|
||||
<div class="mt-4">
|
||||
<div class="text-body-2 mb-2">Attachments</div>
|
||||
|
||||
<!-- Attachment Options -->
|
||||
<v-btn-toggle v-model="attachmentMode" mandatory class="mb-3">
|
||||
<v-btn value="upload" size="small">
|
||||
<v-icon start>mdi-upload</v-icon>
|
||||
Upload Files
|
||||
</v-btn>
|
||||
<v-btn value="browse" size="small">
|
||||
<v-icon start>mdi-folder-open</v-icon>
|
||||
Browse Files
|
||||
</v-btn>
|
||||
</v-btn-toggle>
|
||||
|
||||
<!-- Upload Mode -->
|
||||
<v-file-input
|
||||
v-if="attachmentMode === 'upload'"
|
||||
v-model="emailDraft.attachments"
|
||||
label="Select files to attach"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
multiple
|
||||
chips
|
||||
prepend-icon="mdi-paperclip"
|
||||
show-size
|
||||
/>
|
||||
|
||||
<!-- Browse Mode -->
|
||||
<div v-else>
|
||||
<v-btn
|
||||
@click="openFileBrowser"
|
||||
variant="outlined"
|
||||
block
|
||||
size="large"
|
||||
prepend-icon="mdi-folder-open"
|
||||
>
|
||||
Browse Files
|
||||
</v-btn>
|
||||
</div>
|
||||
|
||||
<!-- Selected Files Preview -->
|
||||
<div v-if="selectedBrowserFiles.length > 0" class="mt-3">
|
||||
<div class="text-caption mb-2">Selected from browser:</div>
|
||||
<v-chip
|
||||
v-for="(file, i) in selectedBrowserFiles"
|
||||
:key="i"
|
||||
size="small"
|
||||
color="primary"
|
||||
variant="tonal"
|
||||
closable
|
||||
@click:close="removeBrowserFile(i)"
|
||||
class="mr-2 mb-2"
|
||||
>
|
||||
<v-icon start size="small">mdi-file</v-icon>
|
||||
{{ file.name }}
|
||||
</v-chip>
|
||||
</div>
|
||||
</div>
|
||||
</v-card-text>
|
||||
|
||||
<v-divider />
|
||||
|
|
@ -180,11 +302,31 @@
|
|||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
|
||||
<!-- File Browser Dialog -->
|
||||
<v-dialog v-model="showFileBrowser" max-width="1200" height="80vh">
|
||||
<v-card height="80vh">
|
||||
<v-card-title class="d-flex align-center">
|
||||
<v-icon class="mr-2">mdi-folder-open</v-icon>
|
||||
Select Files from Browser
|
||||
<v-spacer />
|
||||
<v-btn icon="mdi-close" variant="text" @click="showFileBrowser = false"></v-btn>
|
||||
</v-card-title>
|
||||
<v-divider />
|
||||
<v-card-text class="pa-0" style="height: calc(100% - 64px);">
|
||||
<FileBrowser
|
||||
selection-mode
|
||||
@file-selected="handleFileSelected"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Interest } from '~/utils/types';
|
||||
import FileBrowser from '~/pages/dashboard/file-browser.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
interest: Interest;
|
||||
|
|
@ -200,6 +342,14 @@ const showComposer = ref(false);
|
|||
const isSending = ref(false);
|
||||
const emailThreads = ref<any[]>([]);
|
||||
const contentTextarea = ref<any>(null);
|
||||
const isRefreshing = ref(false);
|
||||
const attachmentMode = ref('upload');
|
||||
const selectedBrowserFiles = ref<any[]>([]);
|
||||
const hasEmailCredentials = ref(false);
|
||||
const sessionId = ref<string>('');
|
||||
const includeSignature = ref(true);
|
||||
const signatureConfig = ref<any>({});
|
||||
const showFileBrowser = ref(false);
|
||||
|
||||
const emailDraft = ref<{
|
||||
subject: string;
|
||||
|
|
@ -211,6 +361,33 @@ const emailDraft = ref<{
|
|||
attachments: []
|
||||
});
|
||||
|
||||
// Check for stored session on mount
|
||||
onMounted(() => {
|
||||
const storedSession = localStorage.getItem('emailSessionId');
|
||||
if (storedSession) {
|
||||
sessionId.value = storedSession;
|
||||
hasEmailCredentials.value = true;
|
||||
}
|
||||
|
||||
// Load signature config
|
||||
const storedSignature = localStorage.getItem('emailSignature');
|
||||
if (storedSignature) {
|
||||
signatureConfig.value = JSON.parse(storedSignature);
|
||||
}
|
||||
|
||||
loadEmailThread();
|
||||
|
||||
// Auto-refresh every 30 seconds
|
||||
const refreshInterval = setInterval(() => {
|
||||
loadEmailThread();
|
||||
}, 30000);
|
||||
|
||||
// Clean up interval on unmount
|
||||
onUnmounted(() => {
|
||||
clearInterval(refreshInterval);
|
||||
});
|
||||
});
|
||||
|
||||
// Check if interest has EOI or berth
|
||||
const hasEOI = computed(() => {
|
||||
const eoiDocs = props.interest['EOI Document'];
|
||||
|
|
@ -224,17 +401,13 @@ const hasBerth = computed(() => {
|
|||
return !!(hasBerthsArray || props.interest['Berth Number']);
|
||||
});
|
||||
|
||||
// Load email thread on mount
|
||||
onMounted(() => {
|
||||
loadEmailThread();
|
||||
});
|
||||
|
||||
// Watch for interest changes
|
||||
watch(() => props.interest.Id, () => {
|
||||
loadEmailThread();
|
||||
});
|
||||
|
||||
const loadEmailThread = async () => {
|
||||
isRefreshing.value = true;
|
||||
try {
|
||||
const response = await $fetch<{
|
||||
success: boolean;
|
||||
|
|
@ -254,6 +427,8 @@ const loadEmailThread = async () => {
|
|||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load email thread:', error);
|
||||
} finally {
|
||||
isRefreshing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -312,22 +487,83 @@ const sendEmail = async () => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!sessionId.value) {
|
||||
toast.error('Please set up email credentials first');
|
||||
hasEmailCredentials.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
isSending.value = true;
|
||||
|
||||
try {
|
||||
// Format email content with proper line breaks
|
||||
const formattedContent = emailDraft.value.content
|
||||
.split('\n')
|
||||
.map(line => line.trim() ? `<p>${line}</p>` : '<br>')
|
||||
.join('');
|
||||
// First, upload any attachments to MinIO
|
||||
const uploadedAttachments = [];
|
||||
|
||||
// Prepare email data
|
||||
// Handle regular file attachments
|
||||
if (emailDraft.value.attachments && emailDraft.value.attachments.length > 0) {
|
||||
for (const file of emailDraft.value.attachments) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
// Use the client's name for the attachment folder
|
||||
const clientName = props.interest['Full Name']
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^a-z0-9-]/g, '');
|
||||
|
||||
const uploadResponse = await $fetch<{
|
||||
success: boolean;
|
||||
path: string;
|
||||
fileName: string
|
||||
}>('/api/files/upload', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': '094ut234'
|
||||
},
|
||||
query: {
|
||||
path: `${clientName}-attachments`,
|
||||
bucket: 'client-emails'
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (uploadResponse.success) {
|
||||
uploadedAttachments.push({
|
||||
name: file.name,
|
||||
path: uploadResponse.path
|
||||
});
|
||||
}
|
||||
} catch (uploadError) {
|
||||
console.error('Failed to upload attachment:', uploadError);
|
||||
toast.error(`Failed to upload ${file.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle files selected from browser
|
||||
if (selectedBrowserFiles.value.length > 0) {
|
||||
for (const file of selectedBrowserFiles.value) {
|
||||
// Files from browser are already in MinIO
|
||||
// Include bucket information
|
||||
uploadedAttachments.push({
|
||||
name: file.displayName || file.name,
|
||||
path: file.name,
|
||||
bucket: file.bucket || 'client-portal' // Include bucket info
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare email data with the correct structure
|
||||
const emailData = {
|
||||
to: props.interest['Email Address'],
|
||||
toName: props.interest['Full Name'],
|
||||
subject: emailDraft.value.subject,
|
||||
html: formattedContent,
|
||||
interestId: props.interest.Id.toString()
|
||||
body: emailDraft.value.content, // Use 'body' not 'html'
|
||||
interestId: props.interest.Id.toString(),
|
||||
sessionId: sessionId.value,
|
||||
includeSignature: includeSignature.value,
|
||||
signatureConfig: signatureConfig.value,
|
||||
attachments: uploadedAttachments
|
||||
};
|
||||
|
||||
// Send email
|
||||
|
|
@ -350,7 +586,7 @@ const sendEmail = async () => {
|
|||
direction: 'sent',
|
||||
to: props.interest['Email Address'],
|
||||
subject: emailDraft.value.subject,
|
||||
content: formattedContent,
|
||||
content: emailDraft.value.content,
|
||||
timestamp: new Date().toISOString(),
|
||||
attachments: emailDraft.value.attachments.map((f: File) => ({ name: f.name }))
|
||||
});
|
||||
|
|
@ -376,6 +612,19 @@ const closeComposer = () => {
|
|||
content: '',
|
||||
attachments: []
|
||||
};
|
||||
attachmentMode.value = 'upload';
|
||||
selectedBrowserFiles.value = [];
|
||||
};
|
||||
|
||||
const removeBrowserFile = (index: number) => {
|
||||
selectedBrowserFiles.value.splice(index, 1);
|
||||
};
|
||||
|
||||
const onCredentialsSaved = (data: { sessionId: string }) => {
|
||||
sessionId.value = data.sessionId;
|
||||
localStorage.setItem('emailSessionId', data.sessionId);
|
||||
hasEmailCredentials.value = true;
|
||||
toast.success('Email credentials saved successfully');
|
||||
};
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
|
|
@ -399,6 +648,19 @@ const formatEmailContent = (content: string) => {
|
|||
// Convert plain text to HTML
|
||||
return content.split('\n').map(line => `<p>${line}</p>`).join('');
|
||||
};
|
||||
|
||||
const openFileBrowser = () => {
|
||||
showFileBrowser.value = true;
|
||||
};
|
||||
|
||||
const handleFileSelected = (file: any) => {
|
||||
// Check if file is already selected
|
||||
const exists = selectedBrowserFiles.value.some(f => f.name === file.name);
|
||||
if (!exists) {
|
||||
selectedBrowserFiles.value.push(file);
|
||||
}
|
||||
toast.success(`Added ${file.displayName || file.name} to attachments`);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
|||
|
|
@ -45,9 +45,11 @@
|
|||
<div class="mb-4">
|
||||
<v-btn
|
||||
@click="showUploadDialog = true"
|
||||
variant="outlined"
|
||||
:variant="hasEOI ? 'tonal' : 'outlined'"
|
||||
:color="hasEOI ? 'success' : 'primary'"
|
||||
prepend-icon="mdi-upload"
|
||||
:disabled="isUploading"
|
||||
size="large"
|
||||
>
|
||||
{{ hasEOI ? 'Upload Signed EOI' : 'Upload EOI Document' }}
|
||||
</v-btn>
|
||||
|
|
@ -133,34 +135,108 @@
|
|||
Regenerate EOI
|
||||
</v-btn>
|
||||
</div>
|
||||
|
||||
<!-- Reminder Settings -->
|
||||
<v-divider v-if="hasEOI" class="mt-4 mb-4" />
|
||||
<v-row v-if="hasEOI" dense align="center">
|
||||
<v-col cols="auto">
|
||||
<v-switch
|
||||
v-model="remindersEnabled"
|
||||
@update:model-value="updateReminderSettings"
|
||||
color="primary"
|
||||
hide-details
|
||||
density="compact"
|
||||
>
|
||||
<template v-slot:label>
|
||||
<span class="text-body-2">
|
||||
Automatic Reminders
|
||||
<v-tooltip activator="parent" location="top">
|
||||
<div style="max-width: 300px">
|
||||
When enabled, automatic reminders will be sent at 9am and 4pm daily to unsigned recipients
|
||||
</div>
|
||||
</v-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
</v-switch>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
|
||||
<!-- Upload Dialog -->
|
||||
<v-dialog v-model="showUploadDialog" max-width="500">
|
||||
<v-dialog v-model="showUploadDialog" max-width="600">
|
||||
<v-card>
|
||||
<v-card-title>Upload EOI Document</v-card-title>
|
||||
<v-card-text>
|
||||
<v-file-input
|
||||
v-model="selectedFile"
|
||||
label="Select EOI document (PDF)"
|
||||
accept=".pdf"
|
||||
prepend-icon="mdi-file-pdf-box"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
:rules="[v => !!v || 'Please select a file']"
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-card-title class="d-flex align-center">
|
||||
<v-icon class="mr-2" color="primary">mdi-upload</v-icon>
|
||||
Upload EOI Document
|
||||
<v-spacer />
|
||||
<v-btn @click="showUploadDialog = false">Cancel</v-btn>
|
||||
<v-btn icon="mdi-close" variant="text" @click="closeUploadDialog"></v-btn>
|
||||
</v-card-title>
|
||||
|
||||
<v-divider />
|
||||
|
||||
<v-card-text class="pa-6">
|
||||
<div class="text-center mb-6">
|
||||
<v-icon size="80" color="primary" class="mb-4">mdi-file-pdf-box</v-icon>
|
||||
<div class="text-h6 mb-2">Choose how to upload your EOI</div>
|
||||
<div class="text-body-2 text-grey">Upload a signed PDF document</div>
|
||||
</div>
|
||||
|
||||
<v-tabs v-model="uploadTab" class="mb-4">
|
||||
<v-tab value="upload">
|
||||
<v-icon start>mdi-upload</v-icon>
|
||||
Upload File
|
||||
</v-tab>
|
||||
<v-tab value="browse">
|
||||
<v-icon start>mdi-folder-open</v-icon>
|
||||
Browse Files
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
|
||||
<v-window v-model="uploadTab">
|
||||
<v-window-item value="upload">
|
||||
<v-file-input
|
||||
v-model="selectedFile"
|
||||
label="Drop your PDF here or click to browse"
|
||||
accept=".pdf"
|
||||
prepend-icon=""
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
:rules="[v => !!v || 'Please select a file']"
|
||||
show-size
|
||||
class="mt-4"
|
||||
>
|
||||
<template v-slot:prepend-inner>
|
||||
<v-icon color="primary">mdi-file-pdf-box</v-icon>
|
||||
</template>
|
||||
</v-file-input>
|
||||
</v-window-item>
|
||||
|
||||
<v-window-item value="browse">
|
||||
<div class="text-center py-8 text-grey">
|
||||
<v-icon size="48" class="mb-3">mdi-folder-open</v-icon>
|
||||
<div>File browser integration coming soon</div>
|
||||
</div>
|
||||
</v-window-item>
|
||||
</v-window>
|
||||
</v-card-text>
|
||||
|
||||
<v-divider />
|
||||
|
||||
<v-card-actions class="pa-4">
|
||||
<v-spacer />
|
||||
<v-btn @click="closeUploadDialog" variant="text" size="large">
|
||||
Cancel
|
||||
</v-btn>
|
||||
<v-btn
|
||||
color="primary"
|
||||
variant="flat"
|
||||
@click="handleUpload"
|
||||
:loading="isUploading"
|
||||
:disabled="!selectedFile"
|
||||
:disabled="!selectedFile && uploadTab === 'upload'"
|
||||
size="large"
|
||||
prepend-icon="mdi-upload"
|
||||
>
|
||||
Upload
|
||||
Upload EOI
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
|
|
@ -185,6 +261,17 @@ const isGenerating = ref(false);
|
|||
const showUploadDialog = ref(false);
|
||||
const isUploading = ref(false);
|
||||
const selectedFile = ref<File | null>(null);
|
||||
const uploadTab = ref('upload');
|
||||
|
||||
// Reminder settings
|
||||
const remindersEnabled = ref(true);
|
||||
|
||||
// Initialize reminder state from interest data
|
||||
watch(() => props.interest, (newInterest) => {
|
||||
if (newInterest) {
|
||||
remindersEnabled.value = (newInterest as any)['reminder_enabled'] !== false;
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
const hasEOI = computed(() => {
|
||||
return !!(props.interest['Signature Link Client'] ||
|
||||
|
|
@ -353,4 +440,37 @@ const handleUpload = () => {
|
|||
uploadEOI(selectedFile.value);
|
||||
}
|
||||
};
|
||||
|
||||
const updateReminderSettings = async (value: boolean | null) => {
|
||||
if (value === null) return;
|
||||
|
||||
try {
|
||||
await $fetch('/api/update-interest', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': '094ut234'
|
||||
},
|
||||
body: {
|
||||
id: props.interest.Id.toString(),
|
||||
data: {
|
||||
'reminder_enabled': value
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
toast.success(`Automatic reminders ${value ? 'enabled' : 'disabled'}`);
|
||||
emit('update'); // Refresh parent data
|
||||
} catch (error) {
|
||||
console.error('Failed to update reminder settings:', error);
|
||||
toast.error('Failed to update reminder settings');
|
||||
// Revert the switch on error
|
||||
remindersEnabled.value = !value;
|
||||
}
|
||||
};
|
||||
|
||||
const closeUploadDialog = () => {
|
||||
showUploadDialog.value = false;
|
||||
selectedFile.value = null;
|
||||
uploadTab.value = 'upload';
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -59,6 +59,47 @@
|
|||
/>
|
||||
</v-expansion-panel-text>
|
||||
</v-expansion-panel>
|
||||
|
||||
<v-expansion-panel>
|
||||
<v-expansion-panel-title>
|
||||
<v-icon class="mr-2">mdi-card-account-details</v-icon>
|
||||
Email Signature
|
||||
</v-expansion-panel-title>
|
||||
<v-expansion-panel-text>
|
||||
<v-text-field
|
||||
v-model="signature.name"
|
||||
label="Your Name"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
placeholder="John Doe"
|
||||
class="mb-3"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="signature.title"
|
||||
label="Job Title"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
placeholder="Sales & Marketing Director"
|
||||
class="mb-3"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="signature.company"
|
||||
label="Company"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
placeholder="Port Nimara"
|
||||
class="mb-3"
|
||||
/>
|
||||
<v-textarea
|
||||
v-model="signature.contactInfo"
|
||||
label="Additional Contact Info"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
rows="3"
|
||||
placeholder="Phone: +1234567890 Mobile: +0987654321"
|
||||
/>
|
||||
</v-expansion-panel-text>
|
||||
</v-expansion-panel>
|
||||
</v-expansion-panels>
|
||||
|
||||
<v-btn
|
||||
|
|
@ -82,6 +123,7 @@ import { ref, onMounted } from 'vue';
|
|||
|
||||
interface Emits {
|
||||
(e: 'connected', email: string): void;
|
||||
(e: 'credentials-saved', data: { sessionId: string }): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
|
@ -100,6 +142,13 @@ const credentials = ref({
|
|||
smtpHost: ''
|
||||
});
|
||||
|
||||
const signature = ref({
|
||||
name: '',
|
||||
title: 'Sales & Marketing Director',
|
||||
company: 'Port Nimara',
|
||||
contactInfo: ''
|
||||
});
|
||||
|
||||
const rules = {
|
||||
required: (v: string) => !!v || 'Required',
|
||||
email: (v: string) => /.+@.+\..+/.test(v) || 'Invalid email'
|
||||
|
|
@ -107,10 +156,10 @@ const rules = {
|
|||
|
||||
// Generate or get session ID
|
||||
const getSessionId = () => {
|
||||
let sessionId = sessionStorage.getItem('emailSessionId');
|
||||
let sessionId = localStorage.getItem('emailSessionId');
|
||||
if (!sessionId) {
|
||||
sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(2)}`;
|
||||
sessionStorage.setItem('emailSessionId', sessionId);
|
||||
localStorage.setItem('emailSessionId', sessionId);
|
||||
}
|
||||
return sessionId;
|
||||
};
|
||||
|
|
@ -139,9 +188,13 @@ const testConnection = async () => {
|
|||
|
||||
if (response.success) {
|
||||
toast.success('Email connection successful!');
|
||||
// Store email in session for later use
|
||||
sessionStorage.setItem('connectedEmail', credentials.value.email);
|
||||
// Store email and signature config
|
||||
localStorage.setItem('connectedEmail', credentials.value.email);
|
||||
localStorage.setItem('emailSignature', JSON.stringify(signature.value));
|
||||
|
||||
// Emit both events for compatibility
|
||||
emit('connected', credentials.value.email);
|
||||
emit('credentials-saved', { sessionId: getSessionId() });
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Connection test failed:', error);
|
||||
|
|
@ -152,7 +205,8 @@ const testConnection = async () => {
|
|||
if (proceed) {
|
||||
// Store credentials anyway
|
||||
toast.info('Proceeding with email setup...');
|
||||
sessionStorage.setItem('connectedEmail', credentials.value.email);
|
||||
localStorage.setItem('connectedEmail', credentials.value.email);
|
||||
localStorage.setItem('emailSignature', JSON.stringify(signature.value));
|
||||
|
||||
// Manually store encrypted credentials
|
||||
try {
|
||||
|
|
@ -161,6 +215,7 @@ const testConnection = async () => {
|
|||
|
||||
// We'll trust that the credentials are correct and proceed
|
||||
emit('connected', credentials.value.email);
|
||||
emit('credentials-saved', { sessionId: sessionId });
|
||||
} catch (e) {
|
||||
console.error('Failed to store credentials:', e);
|
||||
}
|
||||
|
|
@ -178,5 +233,15 @@ onMounted(() => {
|
|||
if (user.value?.email) {
|
||||
credentials.value.email = user.value.email;
|
||||
}
|
||||
|
||||
// Load saved signature
|
||||
const savedSignature = localStorage.getItem('emailSignature');
|
||||
if (savedSignature) {
|
||||
try {
|
||||
signature.value = JSON.parse(savedSignature);
|
||||
} catch (e) {
|
||||
console.error('Failed to load saved signature:', e);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -411,10 +411,24 @@ const breadcrumbItems = computed(() => {
|
|||
const loadFiles = async (retryCount = 0) => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await $fetch('/api/files/list', {
|
||||
// Get current user email for email attachments
|
||||
const user = useDirectusUser();
|
||||
const userEmail = user.value?.email || '';
|
||||
|
||||
const response = await $fetch<{
|
||||
success: boolean;
|
||||
files: FileItem[];
|
||||
count: number;
|
||||
currentPath: string;
|
||||
}>('/api/files/list-with-attachments', {
|
||||
headers: {
|
||||
'x-tag': '094ut234'
|
||||
},
|
||||
params: {
|
||||
prefix: currentPath.value,
|
||||
recursive: false,
|
||||
includeEmailAttachments: true,
|
||||
userEmail: userEmail
|
||||
},
|
||||
timeout: 15000 // 15 second timeout
|
||||
});
|
||||
|
|
|
|||
|
|
@ -90,8 +90,11 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
for (const attachment of attachments) {
|
||||
try {
|
||||
// Determine which bucket to use
|
||||
const bucket = attachment.bucket || 'client-portal'; // Default to client-portal
|
||||
|
||||
// Download file from MinIO
|
||||
const stream = await client.getObject('portnimaradev', attachment.path);
|
||||
const stream = await client.getObject(bucket, attachment.path);
|
||||
const chunks: Buffer[] = [];
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
|
|
@ -107,7 +110,7 @@ export default defineEventHandler(async (event) => {
|
|||
content: content
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Failed to attach file ${attachment.name}:`, error);
|
||||
console.error(`Failed to attach file ${attachment.name} from bucket ${attachment.bucket}:`, error);
|
||||
// Continue with other attachments
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,263 @@
|
|||
import { Client } from 'minio';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const query = getQuery(event);
|
||||
const prefix = (query.prefix as string) || '';
|
||||
const recursive = query.recursive === 'true';
|
||||
const includeEmailAttachments = query.includeEmailAttachments === 'true';
|
||||
const currentUserEmail = query.userEmail as string;
|
||||
|
||||
// Get files from main bucket (client-portal)
|
||||
const mainFiles = await listFilesFromBucket('client-portal', prefix, recursive);
|
||||
|
||||
let allFiles = [...mainFiles];
|
||||
|
||||
// If requested, also include email attachments from client-emails bucket
|
||||
if (includeEmailAttachments && currentUserEmail) {
|
||||
try {
|
||||
// Get the user's full name from their interests
|
||||
const { getInterests } = await import('~/server/utils/nocodb');
|
||||
const interests = await getInterests();
|
||||
const userInterest = interests.list?.find((interest: any) =>
|
||||
interest['Email Address']?.toLowerCase() === currentUserEmail.toLowerCase()
|
||||
);
|
||||
|
||||
if (userInterest && userInterest['Full Name']) {
|
||||
// Create the folder name from the user's name
|
||||
const clientName = userInterest['Full Name']
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^a-z0-9-]/g, '');
|
||||
|
||||
const attachmentFolder = `${clientName}-attachments`;
|
||||
|
||||
// List files from the user's attachment folder
|
||||
const attachmentFiles = await listFilesFromBucket('client-emails', attachmentFolder + '/', true);
|
||||
|
||||
// Add these files with a special flag to identify them as email attachments
|
||||
const formattedAttachmentFiles = attachmentFiles.map((file: any) => ({
|
||||
...file,
|
||||
isEmailAttachment: true,
|
||||
displayPath: `Email Attachments/${file.name.replace(attachmentFolder + '/', '')}`,
|
||||
bucket: 'client-emails'
|
||||
}));
|
||||
|
||||
// Create a virtual folder for email attachments
|
||||
if (formattedAttachmentFiles.length > 0 && !prefix) {
|
||||
allFiles.push({
|
||||
name: 'Email Attachments/',
|
||||
size: 0,
|
||||
lastModified: new Date(),
|
||||
etag: '',
|
||||
isFolder: true,
|
||||
isVirtualFolder: true,
|
||||
icon: 'mdi-email-multiple'
|
||||
});
|
||||
}
|
||||
|
||||
// If we're inside the Email Attachments folder, show the files
|
||||
if (prefix === 'Email Attachments/') {
|
||||
allFiles = formattedAttachmentFiles.map((file: any) => ({
|
||||
...file,
|
||||
name: file.name.replace(attachmentFolder + '/', '')
|
||||
}));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching email attachments:', error);
|
||||
// Continue without email attachments if there's an error
|
||||
}
|
||||
}
|
||||
|
||||
// Format file list with additional metadata
|
||||
const formattedFiles = allFiles.map(file => ({
|
||||
...file,
|
||||
sizeFormatted: file.isFolder ? '-' : formatFileSize(file.size),
|
||||
extension: file.isFolder ? 'folder' : getFileExtension(file.name),
|
||||
icon: file.icon || (file.isFolder ? 'mdi-folder' : getFileIcon(file.name)),
|
||||
displayName: file.displayPath || getDisplayName(file.name),
|
||||
}));
|
||||
|
||||
// Sort folders first, then files
|
||||
formattedFiles.sort((a, b) => {
|
||||
if (a.isFolder && !b.isFolder) return -1;
|
||||
if (!a.isFolder && b.isFolder) return 1;
|
||||
return a.displayName.localeCompare(b.displayName);
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
files: formattedFiles,
|
||||
count: formattedFiles.length,
|
||||
currentPath: prefix,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('Failed to list files:', error);
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: error.message || 'Failed to list files',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// List files from a specific bucket
|
||||
async function listFilesFromBucket(bucketName: string, prefix: string = '', recursive: boolean = false): Promise<any[]> {
|
||||
const config = useRuntimeConfig().minio;
|
||||
|
||||
const client = new Client({
|
||||
endPoint: config.endPoint,
|
||||
port: config.port,
|
||||
useSSL: config.useSSL,
|
||||
accessKey: config.accessKey,
|
||||
secretKey: config.secretKey,
|
||||
});
|
||||
|
||||
const files: any[] = [];
|
||||
const folders = new Set<string>();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const stream = client.listObjectsV2(bucketName, prefix, recursive);
|
||||
|
||||
stream.on('data', (obj) => {
|
||||
if (obj && obj.prefix) {
|
||||
folders.add(obj.prefix);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obj || typeof obj.name !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!recursive) {
|
||||
if (prefix) {
|
||||
const relativePath = obj.name.substring(prefix.length);
|
||||
if (!relativePath) return;
|
||||
|
||||
const firstSlash = relativePath.indexOf('/');
|
||||
|
||||
if (firstSlash > -1) {
|
||||
const folderName = relativePath.substring(0, firstSlash);
|
||||
folders.add(prefix + folderName + '/');
|
||||
} else if (relativePath && !obj.name.endsWith('/')) {
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size || 0,
|
||||
lastModified: obj.lastModified || new Date(),
|
||||
etag: obj.etag || '',
|
||||
isFolder: false,
|
||||
bucket: bucketName
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const firstSlash = obj.name.indexOf('/');
|
||||
|
||||
if (obj.name.endsWith('/')) {
|
||||
folders.add(obj.name);
|
||||
} else if (firstSlash > -1) {
|
||||
const folderName = obj.name.substring(0, firstSlash);
|
||||
folders.add(folderName + '/');
|
||||
} else {
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size || 0,
|
||||
lastModified: obj.lastModified || new Date(),
|
||||
etag: obj.etag || '',
|
||||
isFolder: false,
|
||||
bucket: bucketName
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!obj.name.endsWith('/')) {
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size || 0,
|
||||
lastModified: obj.lastModified || new Date(),
|
||||
etag: obj.etag || '',
|
||||
isFolder: false,
|
||||
bucket: bucketName
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', (error) => {
|
||||
console.error('Stream error:', error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
const folderItems = Array.from(folders).map(folder => ({
|
||||
name: folder,
|
||||
size: 0,
|
||||
lastModified: new Date(),
|
||||
etag: '',
|
||||
isFolder: true,
|
||||
bucket: bucketName
|
||||
}));
|
||||
|
||||
resolve([...folderItems, ...files]);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in listFilesFromBucket:', error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
function formatFileSize(bytes: number): string {
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
function getFileExtension(filename: string): string {
|
||||
const parts = filename.split('.');
|
||||
return parts.length > 1 ? parts.pop()?.toLowerCase() || '' : '';
|
||||
}
|
||||
|
||||
function getFileIcon(filename: string): string {
|
||||
const ext = getFileExtension(filename);
|
||||
const iconMap: Record<string, string> = {
|
||||
pdf: 'mdi-file-pdf-box',
|
||||
doc: 'mdi-file-document',
|
||||
docx: 'mdi-file-document',
|
||||
xls: 'mdi-file-excel',
|
||||
xlsx: 'mdi-file-excel',
|
||||
jpg: 'mdi-file-image',
|
||||
jpeg: 'mdi-file-image',
|
||||
png: 'mdi-file-image',
|
||||
gif: 'mdi-file-image',
|
||||
svg: 'mdi-file-image',
|
||||
zip: 'mdi-folder-zip',
|
||||
rar: 'mdi-folder-zip',
|
||||
txt: 'mdi-file-document-outline',
|
||||
csv: 'mdi-file-delimited',
|
||||
mp4: 'mdi-file-video',
|
||||
mp3: 'mdi-file-music',
|
||||
};
|
||||
return iconMap[ext] || 'mdi-file';
|
||||
}
|
||||
|
||||
function getDisplayName(filepath: string): string {
|
||||
if (filepath.endsWith('/')) {
|
||||
const parts = filepath.slice(0, -1).split('/');
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
const parts = filepath.split('/');
|
||||
const filename = parts[parts.length - 1];
|
||||
|
||||
const match = filename.match(/^\d{10,}-(.+)$/);
|
||||
return match ? match[1] : filename;
|
||||
}
|
||||
|
|
@ -12,24 +12,19 @@ export async function scheduleEOIReminders() {
|
|||
|
||||
console.log('[EOI Reminders] Scheduling reminder tasks...');
|
||||
|
||||
// Dynamic import for node-cron to avoid ESM issues
|
||||
const cron = await import('node-cron');
|
||||
// Check every hour if it's time to send reminders
|
||||
setInterval(async () => {
|
||||
const now = new Date();
|
||||
const parisTime = new Date(now.toLocaleString('en-US', { timeZone: 'Europe/Paris' }));
|
||||
const hour = parisTime.getHours();
|
||||
const minute = parisTime.getMinutes();
|
||||
|
||||
// Schedule for 9am daily
|
||||
cron.schedule('0 9 * * *', async () => {
|
||||
console.log('[EOI Reminders] Running 9am reminder check...');
|
||||
await processReminders();
|
||||
}, {
|
||||
timezone: 'Europe/Paris'
|
||||
});
|
||||
|
||||
// Schedule for 4pm daily
|
||||
cron.schedule('0 16 * * *', async () => {
|
||||
console.log('[EOI Reminders] Running 4pm reminder check...');
|
||||
await processReminders();
|
||||
}, {
|
||||
timezone: 'Europe/Paris'
|
||||
});
|
||||
// Check if it's 9am or 4pm (16:00)
|
||||
if ((hour === 9 || hour === 16) && minute === 0) {
|
||||
console.log(`[EOI Reminders] Running ${hour === 9 ? '9am' : '4pm'} reminder check...`);
|
||||
await processReminders();
|
||||
}
|
||||
}, 60000); // Check every minute
|
||||
|
||||
tasksScheduled = true;
|
||||
console.log('[EOI Reminders] Tasks scheduled successfully');
|
||||
|
|
@ -78,12 +73,14 @@ async function processReminders() {
|
|||
|
||||
async function sendReminder(interest: any) {
|
||||
try {
|
||||
// Use a full URL for the fetch since we're in a background task
|
||||
const baseUrl = process.env.NUXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||
const response = await $fetch<{
|
||||
success: boolean;
|
||||
remindersSent: number;
|
||||
results: any[];
|
||||
message?: string;
|
||||
}>('/api/eoi/send-reminders', {
|
||||
}>(`${baseUrl}/api/eoi/send-reminders`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': '094ut234' // System tag for automated processes
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ export function scheduleEmailProcessing() {
|
|||
|
||||
async function processEmails() {
|
||||
try {
|
||||
const response = await $fetch('/api/email/process-sales-eois', {
|
||||
// Use a full URL for the fetch since we're in a background task
|
||||
const baseUrl = process.env.NUXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||
const response = await $fetch(`${baseUrl}/api/email/process-sales-eois`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': '094ut234' // System tag for automated processes
|
||||
|
|
|
|||
Loading…
Reference in New Issue