From 8fba84c3bab73ff477c6d2005d13375f9341a9e4 Mon Sep 17 00:00:00 2001 From: Ronni Skansing Date: Sat, 30 Aug 2025 18:39:05 +0200 Subject: [PATCH] added a update button to an not started campaign --- frontend/src/routes/campaign/+page.svelte | 18 +++++++ .../src/routes/campaign/[id]/+page.svelte | 49 +++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/frontend/src/routes/campaign/+page.svelte b/frontend/src/routes/campaign/+page.svelte index e49915d..dc34e8a 100644 --- a/frontend/src/routes/campaign/+page.svelte +++ b/frontend/src/routes/campaign/+page.svelte @@ -2,6 +2,7 @@ import { api } from '$lib/api/apiProxy.js'; import { onMount } from 'svelte'; import { goto } from '$app/navigation'; + import { page } from '$app/stores'; import { newTableURLParams } from '$lib/service/tableURLParams.js'; import Headline from '$lib/components/Headline.svelte'; import TextField from '$lib/components/TextField.svelte'; @@ -262,6 +263,23 @@ try { await refreshCampaigns(); tableURLParams.onChange(refreshCampaigns); + + // Check if we should auto-open the update modal + const updateId = $page.url.searchParams.get('update'); + if (updateId) { + // Clear the URL parameter + const url = new URL($page.url); + url.searchParams.delete('update'); + goto(url.pathname + url.search, { replaceState: true }); + + // Open the update modal + try { + await openUpdateModal(updateId); + } catch (e) { + addToast('Failed to open campaign for editing', 'Error'); + console.error('Failed to open update modal:', e); + } + } } catch (e) { addToast('Failed to load data', 'Error'); console.error('failed to load data', e); diff --git a/frontend/src/routes/campaign/[id]/+page.svelte b/frontend/src/routes/campaign/[id]/+page.svelte index 2a2e5e7..e21e750 100644 --- a/frontend/src/routes/campaign/[id]/+page.svelte +++ b/frontend/src/routes/campaign/[id]/+page.svelte @@ -36,6 +36,8 @@ import EventTimeline from '$lib/components/EventTimeline.svelte'; import CellCopy from '$lib/components/table/CopyCell.svelte'; import EventName from '$lib/components/table/EventName.svelte'; + import { goto } from '$app/navigation'; + import { globalButtonDisabledAttributes } from '$lib/utils/form'; // services const appStateService = AppStateService.instance; @@ -651,6 +653,37 @@ console.error('failed to load events', e); } }; + + const campaignUpdateDisabledAndTitle = (campaign) => { + const c = globalButtonDisabledAttributes(campaign, contextCompanyID); + if (c?.disabled) { + return c; + } + + const now = new Date(); + const fiveMinutesFromNow = new Date(now.getTime() + 5 * 60 * 1000); + + // Check if campaign is closed + const isClosed = campaign.closedAt != null; + + // Check if less than 5 minutes to start + const isNearStart = + campaign.sendStartAt != null && new Date(campaign.sendStartAt) <= fiveMinutesFromNow; + + if (isClosed) { + return { disabled: true, title: 'Campaign is closed' }; + } + + if (isNearStart) { + return { disabled: true, title: 'Campaign starts in less than 5 minutes' }; + } + + return { disabled: false, title: '' }; + }; + + const onClickUpdateCampaign = () => { + goto(`/campaign?update=${$page.params.id}`); + }; @@ -1066,25 +1099,33 @@

Actions

+ {#if !campaignUpdateDisabledAndTitle(campaign).disabled} + + {/if}