From 4ada45882c5e64dc247d261a98d9bd045d85edc3 Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Fri, 15 Sep 2023 08:49:09 -0400 Subject: [PATCH 1/2] fix: clone campaigns only created in self-serve, remove deleted ads in edit --- src/components/Campaigns/CloneCampaign.tsx | 9 ++-- src/user/library/index.ts | 7 ++- src/user/views/user/CampaignView.tsx | 50 ++++++++++++++-------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/components/Campaigns/CloneCampaign.tsx b/src/components/Campaigns/CloneCampaign.tsx index 1214878f..a8915a61 100644 --- a/src/components/Campaigns/CloneCampaign.tsx +++ b/src/components/Campaigns/CloneCampaign.tsx @@ -25,9 +25,10 @@ import { FilterContext } from "state/context"; interface Props { campaignFragment?: CampaignFragment | null; useChip?: boolean; + disabled?: boolean; } -export function CloneCampaign({ campaignFragment, useChip }: Props) { +export function CloneCampaign({ campaignFragment, useChip, disabled }: Props) { const { advertiser } = useAdvertiser(); const { fromDate } = useContext(FilterContext); const { userId } = useUser(); @@ -62,7 +63,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) { onClick={() => { setOpen(true); }} - disabled={loading || !campaignFragment} + disabled={loading || !campaignFragment || disabled} icon={} /> ) : ( @@ -74,7 +75,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) { e.preventDefault(); setOpen(true); }} - disabled={loading || !campaignFragment} + disabled={loading || !campaignFragment || disabled} startIcon={} > Clone Campaign @@ -84,7 +85,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) { {`Copy campaign: "${campaignFragment?.name}"?`} - Copying a campaign will take all properties including ad sets and + Cloning a campaign will take all properties including ad sets and ads, and create a new draft campaign with them. {loading && } diff --git a/src/user/library/index.ts b/src/user/library/index.ts index e76d387b..3d13df89 100644 --- a/src/user/library/index.ts +++ b/src/user/library/index.ts @@ -110,11 +110,14 @@ export function editCampaignValues( campaign: CampaignFragment, advertiserId: string, ): CampaignForm { - const ads: AdFragment[] = _.flatMap(campaign.adSets, "ads"); + const ads: AdFragment[] = _.filter( + _.flatMap(campaign.adSets, "ads"), + (a) => a.state !== "deleted", + ); const billingType = (_.head(campaign.adSets)?.billingType ?? "cpm") as Billing; - const rawPrice = BigNumber(_.head(ads)?.price ?? "0.006"); + const rawPrice = BigNumber(_.head(ads)?.price ?? "0.1"); const price = billingType === "cpm" ? rawPrice.multipliedBy(1000) : rawPrice; return { diff --git a/src/user/views/user/CampaignView.tsx b/src/user/views/user/CampaignView.tsx index 7054a1f9..dedf38d2 100644 --- a/src/user/views/user/CampaignView.tsx +++ b/src/user/views/user/CampaignView.tsx @@ -100,35 +100,49 @@ function CampaignHeader(props: { selectedCampaigns: string[] }) { skip: !oneCampaignSelected || !firstCampaign, }); - let tooltip: string | null = "Please select one campaign to clone or edit"; let isValidCampaign = false; if (!loading && data?.campaign) { isValidCampaign = data.campaign.source === CampaignSource.SelfServe && editableCampaigns.includes(data.campaign.format) && data.campaign.state !== "completed"; - tooltip = isValidCampaign ? null : "Cannot edit this campaign"; } return ( Campaigns - - - - } - clickable - /> - - + + + + + + + + + } + clickable + /> + + + ); } From 19480860f5b44f4e6e5f0f8ebb339d98ab849b49 Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Fri, 15 Sep 2023 09:22:07 -0400 Subject: [PATCH 2/2] test: change default --- src/user/library/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user/library/index.test.ts b/src/user/library/index.test.ts index 254f396c..3aca2f99 100644 --- a/src/user/library/index.test.ts +++ b/src/user/library/index.test.ts @@ -161,7 +161,7 @@ describe("pricing logic (read)", () => { c.adSets = []; }); const formObject = editCampaignValues(campaign, "abc"); - expect(formObject.price).toEqual(6); + expect(formObject.price).toEqual(100); expect(formObject.billingType).toEqual("cpm"); }); });