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 @@
{sendMessageRecipient.name}
{sendMessageRecipient.email}
- Sender type: {campaign.template?.email ? 'Email (SMTP)' : 'API Sender'} + Sender type: {campaign.template?.smtpConfigurationID ? 'SMTP' : 'API Sender'}
{#if recipient.sentAt}