From 6368e3b7ee60cc5eddd7c6d7ffc59b2c561a5ac6 Mon Sep 17 00:00:00 2001 From: Ronni Skansing Date: Fri, 21 Nov 2025 10:40:28 +0100 Subject: [PATCH] fix send message always showed type as api sender. fix unneeded templates loading Signed-off-by: Ronni Skansing --- .../src/routes/campaign/[id]/+page.svelte | 171 ++++++++---------- 1 file changed, 78 insertions(+), 93 deletions(-) diff --git a/frontend/src/routes/campaign/[id]/+page.svelte b/frontend/src/routes/campaign/[id]/+page.svelte index f33af6c..3fa04f1 100644 --- a/frontend/src/routes/campaign/[id]/+page.svelte +++ b/frontend/src/routes/campaign/[id]/+page.svelte @@ -82,7 +82,7 @@ let timelineEvents = []; let isTimelineGhost = true; let recipientEvents = []; - let template = null; + // local state let result = { recipients: 0, @@ -116,7 +116,6 @@ return setRecipientEvents(recipientEventsRecipient.id); }); let contextCompanyID = null; - let templateMap = new BiMap({}); let recipientGroupMap = new BiMap({}); // self managed campaign are not scheduled for sending let isSelfManaged = false; @@ -156,17 +155,10 @@ }; }); - // lastPoll holds the last date we pulled from, so only pull the - // latest events and add them to the graph - const lastPoll = null; const refresh = async (showLoading = true) => { if (showLoading) { showIsLoading(); } - const templates = await fetchAllRows((options) => { - return api.campaignTemplate.getAll(options, contextCompanyID); - }); - templateMap = BiMap.FromArrayOfObjects(templates); const recipientGroups = await fetchAllRows((options) => { return api.recipient.getAllGroups(options, contextCompanyID); }); @@ -221,7 +213,13 @@ campaign.denyPage = t.denyPage; campaign.evasionPage = t.evasionPage; campaign.webhookID = t.webhookID; - campaign.template = templateMap.byKey(t.templateID); + // fetch the full template object + if (t.templateID) { + const templateRes = await api.campaignTemplate.getByID(t.templateID, true); + if (templateRes.success) { + campaign.template = templateRes.data; + } + } campaign.recipientGroups = t.recipientGroupIDs.map((id) => recipientGroupMap.byKey(id)); campaign.notableEventName = t.notableEventName; if (t.sendStartAt === null && t.sendEndAt === null) { @@ -331,23 +329,6 @@ } }; - /** - * @param {string} id - */ - const setTemplate = async (id) => { - try { - const res = await api.campaignTemplate.getByID(id, true); - if (!res.success) { - throw res.error; - } - template = res.data; - return; - } catch (e) { - addToast('Failed to load recipient events', 'Error'); - console.error('failed to load recipient events', e); - } - }; - const setResults = async () => { try { const res = await api.campaign.getResultStats($page.params.id); @@ -450,22 +431,11 @@ }; const openTemplateModal = async (id) => { - try { - showIsLoading(); - await setTemplate(id); - isTemplateModalVisible = true; - } catch (e) { - addToast('Failed to get template details', 'Error'); - console.error('failed to template details', e); - } finally { - hideIsLoading(); - } isTemplateModalVisible = true; }; const closeTemplateModal = () => { isTemplateModalVisible = false; - template = null; }; /** @param {string} campaignRecipientID */ @@ -1247,10 +1217,10 @@ @@ -1802,7 +1772,7 @@
- {#if template.email} + {#if campaign.template?.email} Email {:else} API @@ -1811,20 +1781,20 @@
- {#if template.beforeLandingPage || template.beforeLandingProxy || template.landingPage || template.landingProxy} + {#if campaign.template?.beforeLandingPage || campaign.template?.beforeLandingProxy || campaign.template?.landingPage || campaign.template?.landingProxy}
{/if} - {#if template.beforeLandingPage} + {#if campaign.template?.beforeLandingPage}
Before Landing
- {#if template.landingPage || template.landingProxy} + {#if campaign.template?.landingPage || campaign.template?.landingProxy}
{/if} - {:else if template.beforeLandingProxy} + {:else if campaign.template?.beforeLandingProxy}
- {#if template.landingPage || template.landingProxy} + {#if campaign.template?.landingPage || campaign.template?.landingProxy}
{/if} {/if} - {#if template.landingPage} + {#if campaign.template?.landingPage}
Main Landing
- {#if template.afterLandingPage || template.afterLandingProxy || template.afterLandingPageRedirectURL} + {#if campaign.template?.afterLandingPage || campaign.template?.afterLandingProxy || campaign.template?.afterLandingPageRedirectURL}
{/if} - {:else if template.landingProxy} + {:else if campaign.template?.landingProxy}
- {#if template.afterLandingPage || template.afterLandingProxy || template.afterLandingPageRedirectURL} + {#if campaign.template?.afterLandingPage || campaign.template?.afterLandingProxy || campaign.template?.afterLandingPageRedirectURL}
{/if} {/if} - {#if template.afterLandingPage} + {#if campaign.template?.afterLandingPage}
After Landing
- {:else if template.afterLandingProxy} + {:else if campaign.template?.afterLandingProxy}
{/if} - {#if template.afterLandingPageRedirectURL} + {#if campaign.template?.afterLandingPageRedirectURL}
Redirect
@@ -1894,95 +1864,104 @@
Name: - {template.name ?? ''} + {campaign.template?.name ?? ''} Query Key: {template.urlIdentifier?.name ?? ''}{campaign.template?.urlIdentifier?.name ?? ''} State Key: {template.stateIdentifier?.name ?? ''}{campaign.template?.stateIdentifier?.name ?? ''} Delivery : - {#if template.email} - Email ({template.email.name ?? ''}) + {#if campaign.template?.email} + Email ({campaign.template.email.name ?? ''}) {:else} - API Sender ({template.apiSender?.name ?? ''}) + API Sender ({campaign.template?.apiSender?.name ?? ''}) {/if} Before Page: - {#if template.beforeLandingPage} - {template.beforeLandingPage.name} - {:else if template.beforeLandingProxy} + {#if campaign.template?.beforeLandingPage} + {campaign.template.beforeLandingPage.name} + {:else if campaign.template?.beforeLandingProxy} - {template.beforeLandingProxy.name} + {campaign.template.beforeLandingProxy.name} + {:else} + N/A {/if} Main Page: - {#if template.landingPage} - {template.landingPage.name} - {:else if template.landingProxy} + {#if campaign.template?.landingPage} + {campaign.template.landingPage.name} + {:else if campaign.template?.landingProxy} - {template.landingProxy.name} + {campaign.template.landingProxy.name} + {:else} + N/A {/if} After Page: - {#if template.afterLandingPage} - {template.afterLandingPage.name} - {:else if template.afterLandingProxy} + {#if campaign.template?.afterLandingPage} + {campaign.template.afterLandingPage.name} + {:else if campaign.template?.afterLandingProxy} - {template.afterLandingProxy.name} + {campaign.template.afterLandingProxy.name} + {:else} + N/A {/if} Redirect URL: {template.afterLandingPageRedirectURL ?? ''}{campaign.template?.afterLandingPageRedirectURL ?? 'N/A'}
- {#if template.email} + {#if campaign.template?.email}

Email

Name: - {template.email.name} + {campaign.template?.email?.name} Envelope: - {template.email.mailEnvelopeFrom}{campaign.template?.email?.mailEnvelopeFrom} From: - {template.email.mailHeaderFrom} + {campaign.template?.email?.mailHeaderFrom} Subject: {template.email.mailHeaderSubject}{campaign.template?.email?.mailHeaderSubject} Tracking: {template.email.addTrackingPixel ? 'Enabled' : 'Disabled'}{campaign.template?.email?.addTrackingPixel ? 'Enabled' : 'Disabled'}
@@ -1999,65 +1978,71 @@
Host Site: {template.domain.hostWebsite ? 'Yes' : 'No'}{campaign.template?.domain?.hostWebsite ? 'Yes' : 'No'} Domain: - {template.domain?.name} + {campaign.template?.domain?.name} URL Path: - {template.urlPath} + {campaign.template?.urlPath} TLS: - {template.domain.managedTLS ? 'Managed' : template.domain.ownManagedTLS ? 'Own' : ''} + {campaign.template?.domain?.managedTLS + ? 'Managed' + : campaign.template?.domain?.ownManagedTLS + ? 'Own' + : ''}
- {#if template.smtpConfiguration || template.apiSender} + {#if campaign.template?.smtpConfiguration || campaign.template?.apiSender}

- {template.smtpConfiguration ? 'Email SMTP' : 'API Sender'} + {campaign.template?.smtpConfiguration ? 'Email SMTP' : 'API Sender'}

- {#if template.smtpConfiguration} + {#if campaign.template?.smtpConfiguration} Name: {template.smtpConfiguration.name}{campaign.template?.smtpConfiguration?.name} Host: {template.smtpConfiguration.host}{campaign.template?.smtpConfiguration?.host} Port: {template.smtpConfiguration.port}{campaign.template?.smtpConfiguration?.port} Username: - {template.smtpConfiguration.username || 'Not configured'} + {campaign.template?.smtpConfiguration?.username || 'Not configured'} Allow insecure: - {!template.smtpConfiguration.ignoreCertErrors ? 'Disabled' : 'Enabled'} + {!campaign.template?.smtpConfiguration?.ignoreCertErrors ? 'Disabled' : 'Enabled'} {:else} API Sender: - {template.apiSender?.name} + {campaign.template?.apiSender?.name} {/if}
@@ -2109,7 +2094,7 @@

{sendMessageRecipient.name}

{sendMessageRecipient.email}

- Sender type: {campaign.template?.email ? 'Email (SMTP)' : 'API Sender'} + Sender type: {campaign.template?.smtpConfigurationID ? 'SMTP' : 'API Sender'}

{#if recipient.sentAt}