Skip to content

Commit

Permalink
Merge pull request #888 from brave/master
Browse files Browse the repository at this point in the history
Production Release 2023-09-15
  • Loading branch information
IanKrieger authored Sep 15, 2023
2 parents f5487f1 + 09302cf commit e63b632
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 43 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@
"@typescript-eslint/parser": "6.6.0",
"@vitejs/plugin-basic-ssl": "1.0.1",
"@vitejs/plugin-react": "4.0.4",
"eslint": "8.48.0",
"eslint": "8.49.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-react": "7.33.2",
"husky": "8.0.3",
"prettier": "3.0.3",
"typescript": "5.2.2",
"vite": "4.4.9",
"vite-plugin-checker": "0.6.2",
"vite-tsconfig-paths": "4.2.0",
"vite-tsconfig-paths": "4.2.1",
"vitest": "0.34.4"
},
"overrides": {
Expand Down
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
2 changes: 1 addition & 1 deletion src/user/library/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
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");
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>
<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>
);
}

0 comments on commit e63b632

Please sign in to comment.