Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clone campaign created in self-serve, remove deleted ads in edit #887

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/Campaigns/CloneCampaign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -62,7 +63,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) {
onClick={() => {
setOpen(true);
}}
disabled={loading || !campaignFragment}
disabled={loading || !campaignFragment || disabled}
icon={<ContentCopyIcon fontSize="small" />}
/>
) : (
Expand All @@ -74,7 +75,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) {
e.preventDefault();
setOpen(true);
}}
disabled={loading || !campaignFragment}
disabled={loading || !campaignFragment || disabled}
startIcon={<ContentCopyIcon />}
>
Clone Campaign
Expand All @@ -84,7 +85,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) {
<DialogTitle>{`Copy campaign: "${campaignFragment?.name}"?`}</DialogTitle>
<DialogContent>
<DialogContentText>
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.
</DialogContentText>
{loading && <LinearProgress />}
Expand Down
7 changes: 5 additions & 2 deletions src/user/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
IanKrieger marked this conversation as resolved.
Show resolved Hide resolved
const price = billingType === "cpm" ? rawPrice.multipliedBy(1000) : rawPrice;

return {
Expand Down
50 changes: 32 additions & 18 deletions src/user/views/user/CampaignView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Stack direction="row" alignItems="center" spacing={2}>
<Typography variant="h2">Campaigns</Typography>
<Tooltip title={tooltip}>
<Stack direction="row" alignItems="center" spacing={2}>
<CloneCampaign campaignFragment={data?.campaign} useChip />
<Chip
color="primary"
label="Edit"
disabled={
!oneCampaignSelected || !data?.campaign || !isValidCampaign
}
component={RouterLink}
to={`/user/main/adsmanager/advanced/${firstCampaign}/settings`}
icon={<EditIcon fontSize="small" />}
clickable
/>
</Stack>
</Tooltip>
<Stack direction="row" alignItems="center" spacing={2}>
<Tooltip
title={isValidCampaign ? "Clone Campaign" : "Cannot clone campaign"}
>
<span>
IanKrieger marked this conversation as resolved.
Show resolved Hide resolved
<CloneCampaign
campaignFragment={data?.campaign}
useChip
disabled={
!oneCampaignSelected || !data?.campaign || !isValidCampaign
}
/>
</span>
</Tooltip>
<Tooltip
title={isValidCampaign ? "Edit campaign" : "Cannot Edit Campaign"}
>
<span>
<Chip
color="primary"
label="Edit"
disabled={
!oneCampaignSelected || !data?.campaign || !isValidCampaign
}
component={RouterLink}
to={`/user/main/adsmanager/advanced/${firstCampaign}/settings`}
icon={<EditIcon fontSize="small" />}
clickable
/>
</span>
</Tooltip>
</Stack>
</Stack>
);
}
Loading