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

Production Release 2023-08-23 #867

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/user/adSet/AdSetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StatsMetric } from "user/analytics/analyticsOverview/types";
import { AdSetFragment } from "graphql/ad-set.generated";
import { AdDetailTable } from "user/views/user/AdDetailTable";
import { displayFromCampaignState } from "util/displayState";
import { uiLabelsForBillingType } from "util/billingType";

interface Props {
loading: boolean;
Expand Down Expand Up @@ -98,8 +99,7 @@ export function AdSetList({ campaign, loading, engagements }: Props) {
},
{
title: "Type",
value: (c) =>
c.billingType === "cpm" ? "Impressions (CPM)" : "Clicks (CPC)",
value: (c) => uiLabelsForBillingType(c.billingType).longLabel,
},
{
title: "Platforms",
Expand Down
10 changes: 10 additions & 0 deletions src/user/library/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,14 @@ describe("pricing logic (write)", () => {
expect(inputObject.price).toEqual("9");
expect(inputObject.priceType).toEqual(ConfirmationType.Click);
});

it("should not convert CPV to per-impression values when populating a CPV creative", () => {
const inputObject = transformCreative(creative, {
billingType: "cpv",
price: 9,
});

expect(inputObject.price).toEqual("9");
expect(inputObject.priceType).toEqual(ConfirmationType.Landed);
});
});
3 changes: 3 additions & 0 deletions src/user/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export function transformCreative(
if (campaign.billingType === "cpm") {
price = BigNumber(campaign.price).dividedBy(1000);
priceType = ConfirmationType.View;
} else if (campaign.billingType === "cpv") {
price = BigNumber(campaign.price);
priceType = ConfirmationType.Landed;
} else {
price = BigNumber(campaign.price);
priceType = ConfirmationType.Click;
Expand Down
2 changes: 1 addition & 1 deletion src/user/views/adsManager/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { defaultEndDate, defaultStartDate } from "form/DateFieldHelpers";
import { MIN_PER_CAMPAIGN } from "validation/CampaignSchema";
import { IAdvertiser } from "auth/context/auth.interface";

export type Billing = "cpm" | "cpc";
export type Billing = "cpm" | "cpc" | "cpv";

export type CampaignForm = {
draftId?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MIN_PER_CAMPAIGN, MIN_PER_DAY } from "validation/CampaignSchema";
import { useAdvertiser } from "auth/hooks/queries/useAdvertiser";
import _ from "lodash";
import { CardContainer } from "components/Card/CardContainer";
import { uiLabelsForBillingType } from "util/billingType";

interface Props {
isEdit: boolean;
Expand Down Expand Up @@ -94,8 +95,14 @@ export function BudgetField({ isEdit }: Props) {
<FormikRadioControl
name="billingType"
options={[
{ value: "cpm", label: "CPM (Impressions)" },
{ value: "cpc", label: "CPC (Clicks)" },
{
value: "cpm",
label: uiLabelsForBillingType("cpm").longLabel,
},
{
value: "cpc",
label: uiLabelsForBillingType("cpc").longLabel,
},
]}
disabled={isEdit && values.state !== "draft"}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CampaignForm } from "../../../../../types";
import { FormikErrors } from "formik";
import { ReviewField } from "./ReviewField";
import { ReviewContainer } from "user/views/adsManager/views/advanced/components/review/components/ReviewContainer";
import { uiLabelsForBillingType } from "util/billingType";

interface Props {
values: CampaignForm;
Expand All @@ -21,10 +22,6 @@ export function CampaignReview({ values, errors }: Props) {
return new Date(date).toLocaleDateString("en-US", options);
};

const billing = (v: string) => {
return v === "cpm" ? "Impressions (CPM)" : "Clicks (CPC)";
};

return (
<ReviewContainer name="Campaign" path="settings">
<ReviewField caption="Name" value={values.name} error={errors.name} />
Expand All @@ -46,7 +43,7 @@ export function CampaignReview({ values, errors }: Props) {
/>
<ReviewField
caption="Pricing Type"
value={billing(values.billingType)}
value={uiLabelsForBillingType(values.billingType).longLabel}
error={errors.billingType}
/>
<ReviewField
Expand Down
26 changes: 26 additions & 0 deletions src/util/billingType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
interface BillingTypeLabels {
value: string;
shortLabel: string;
longLabel: string;
}

const BILLING_TYPES = [
{ value: "cpm", shortLabel: "CPM", longLabel: "CPM (Views)" },
{ value: "cpc", shortLabel: "CPC", longLabel: "CPC (Clicks)" },
{ value: "cpv", shortLabel: "CPV", longLabel: "CPV (Visits)" },
];
export function uiLabelsForBillingType(
billingType: string | undefined | null,
): BillingTypeLabels {
if (!billingType) {
return { value: "N/A", shortLabel: "N/A", longLabel: "Unknown" };
}
const entry = BILLING_TYPES.find((bt) => bt.value === billingType);
return (
entry ?? {
value: billingType,
shortLabel: billingType.toUpperCase(),
longLabel: billingType.toUpperCase(),
}
);
}