diff --git a/src/graphql/advertiser.generated.tsx b/src/graphql/advertiser.generated.tsx index 26f5cf356..e45b3ff77 100644 --- a/src/graphql/advertiser.generated.tsx +++ b/src/graphql/advertiser.generated.tsx @@ -136,7 +136,6 @@ export type AdvertiserPriceFragment = { price: string; billingType: Types.BillingType; format: Types.CampaignFormat; - isDefault: boolean; }; export type AdvertiserImagesQueryVariables = Types.Exact<{ @@ -165,7 +164,6 @@ export type AdvertiserPricesQuery = { price: string; billingType: Types.BillingType; format: Types.CampaignFormat; - isDefault: boolean; }>; } | null; }; @@ -236,7 +234,6 @@ export const AdvertiserPriceFragmentDoc = gql` price billingType format - isDefault } `; export const AdvertiserDocument = gql` diff --git a/src/graphql/advertiser.graphql b/src/graphql/advertiser.graphql index 61795c772..f8b95b5f0 100644 --- a/src/graphql/advertiser.graphql +++ b/src/graphql/advertiser.graphql @@ -69,7 +69,6 @@ fragment AdvertiserPrice on AdvertiserPrice { price billingType format - isDefault } query advertiserImages($id: String!) { diff --git a/src/user/views/adsManager/views/advanced/components/campaign/CampaignSettings.tsx b/src/user/views/adsManager/views/advanced/components/campaign/CampaignSettings.tsx index 208765493..f6302035e 100644 --- a/src/user/views/adsManager/views/advanced/components/campaign/CampaignSettings.tsx +++ b/src/user/views/adsManager/views/advanced/components/campaign/CampaignSettings.tsx @@ -4,8 +4,9 @@ import { CampaignDateRange } from "components/Campaigns/CampaignDateRange"; import { LocationField } from "user/views/adsManager/views/advanced/components/campaign/fields/LocationField"; import { Typography } from "@mui/material"; import { FormatField } from "user/views/adsManager/views/advanced/components/campaign/fields/FormatField"; +import { AdvertiserPriceFragment } from "graphql/advertiser.generated"; -export function CampaignSettings() { +export function CampaignSettings(props: { prices: AdvertiserPriceFragment[] }) { const { isDraft } = useIsEdit(); return ( @@ -20,7 +21,7 @@ export function CampaignSettings() { - + {isDraft && } diff --git a/src/user/views/adsManager/views/advanced/components/campaign/fields/BudgetField.tsx b/src/user/views/adsManager/views/advanced/components/campaign/fields/BudgetField.tsx index 037d1a2e9..df9101587 100644 --- a/src/user/views/adsManager/views/advanced/components/campaign/fields/BudgetField.tsx +++ b/src/user/views/adsManager/views/advanced/components/campaign/fields/BudgetField.tsx @@ -16,15 +16,8 @@ import { uiLabelsForBillingType } from "util/billingType"; import { uiTextForCampaignFormat } from "user/library"; import { CampaignFormat } from "graphql/types"; -type DefaultPrice = { cpm: number; cpc: number }; -const campaignDefaultPrices = new Map([ - [CampaignFormat.PushNotification, { cpm: 6, cpc: 0.1 }], - [CampaignFormat.NewsDisplayAd, { cpm: 10, cpc: 0.15 }], -]); - export function BudgetField() { const [, , dailyBudget] = useField("dailyBudget"); - const [, , price] = useField("price"); const { isDraft } = useIsEdit(); const { advertiser } = useAdvertiser(); const { values, errors } = useFormikContext(); @@ -102,13 +95,6 @@ export function BudgetField() { { - const defaultPrice = campaignDefaultPrices.get(values.format); - if (defaultPrice) - price.setValue( - defaultPrice[e.target.value as keyof DefaultPrice], - ); - }} options={[ { value: "cpm", diff --git a/src/user/views/adsManager/views/advanced/components/campaign/fields/FormatField.tsx b/src/user/views/adsManager/views/advanced/components/campaign/fields/FormatField.tsx index fb2208a39..f1e29b306 100644 --- a/src/user/views/adsManager/views/advanced/components/campaign/fields/FormatField.tsx +++ b/src/user/views/adsManager/views/advanced/components/campaign/fields/FormatField.tsx @@ -12,8 +12,13 @@ import _ from "lodash"; import HelpIcon from "@mui/icons-material/Help"; import { useIsEdit } from "form/FormikHelpers"; import { Billing } from "user/views/adsManager/types"; +import { AdvertiserPriceFragment } from "graphql/advertiser.generated"; -export function FormatField() { +interface PriceProps { + prices: AdvertiserPriceFragment[]; +} + +export function FormatField({ prices }: PriceProps) { return ( @@ -34,18 +39,24 @@ export function FormatField() { - - + + ); } -const FormatItemButton = (props: { format: CampaignFormat }) => { +const FormatItemButton = (props: { format: CampaignFormat } & PriceProps) => { const { isEdit } = useIsEdit(); const [, meta, format] = useField("format"); - const [, , price] = useField("price"); - const [, , billing] = useField("billingType"); + const [, , price] = useField("price"); + const [, bMeta, billing] = useField("billingType"); return ( { selected={meta.value === props.format} onClick={() => { format.setValue(props.format); + const found = props.prices.find((p) => { + return ( + p.format === props.format && + p.billingType === bMeta.value.toUpperCase() + ); + }); + console.log(found); if (props.format === CampaignFormat.NewsDisplayAd) { - price.setValue(10); + price.setValue(found?.price ?? "10"); billing.setValue("cpm"); } else { - price.setValue(6); + price.setValue(found?.price ?? "6"); } }} sx={{ diff --git a/src/user/views/adsManager/views/advanced/components/form/EditCampaign.tsx b/src/user/views/adsManager/views/advanced/components/form/EditCampaign.tsx index e10bff9c1..90d477b08 100644 --- a/src/user/views/adsManager/views/advanced/components/form/EditCampaign.tsx +++ b/src/user/views/adsManager/views/advanced/components/form/EditCampaign.tsx @@ -96,7 +96,7 @@ export function EditCampaign() { }} validationSchema={CampaignSchema(data.prices)} > - + ); diff --git a/src/user/views/adsManager/views/advanced/components/form/NewCampaign.tsx b/src/user/views/adsManager/views/advanced/components/form/NewCampaign.tsx index 79903afaf..544d79834 100644 --- a/src/user/views/adsManager/views/advanced/components/form/NewCampaign.tsx +++ b/src/user/views/adsManager/views/advanced/components/form/NewCampaign.tsx @@ -74,6 +74,7 @@ export function NewCampaign() { return ( { setSubmitting(true); @@ -84,7 +85,7 @@ export function NewCampaign() { validationSchema={CampaignSchema(data.prices)} > <> - + diff --git a/src/user/views/adsManager/views/advanced/components/form/components/BaseForm.tsx b/src/user/views/adsManager/views/advanced/components/form/components/BaseForm.tsx index bf964cb23..82571bef7 100644 --- a/src/user/views/adsManager/views/advanced/components/form/components/BaseForm.tsx +++ b/src/user/views/adsManager/views/advanced/components/form/components/BaseForm.tsx @@ -10,12 +10,14 @@ import { Route, Switch, useRouteMatch } from "react-router-dom"; import { BudgetSettings } from "user/views/adsManager/views/advanced/components/campaign/BudgetSettings"; import { FormContext } from "state/context"; import { useState } from "react"; +import { AdvertiserPriceFragment } from "graphql/advertiser.generated"; interface Props { hasPaymentIntent?: boolean | null; + prices: AdvertiserPriceFragment[]; } -export function BaseForm({ hasPaymentIntent }: Props) { +export function BaseForm({ hasPaymentIntent, prices }: Props) { const { url } = useRouteMatch(); const [isShowingAds, setIsShowingAds] = useState(false); @@ -23,7 +25,7 @@ export function BaseForm({ hasPaymentIntent }: Props) { { label: "Campaign Settings", path: `${url}/settings`, - component: , + component: , }, { label: "Budget", diff --git a/src/validation/CampaignSchema.tsx b/src/validation/CampaignSchema.tsx index 53b31e61a..796156132 100644 --- a/src/validation/CampaignSchema.tsx +++ b/src/validation/CampaignSchema.tsx @@ -19,9 +19,8 @@ import BigNumber from "bignumber.js"; export const MIN_PER_DAY = 33; export const MIN_PER_CAMPAIGN = 100; -export type PriceFragment = Omit; -export const CampaignSchema = (prices: PriceFragment[]) => +export const CampaignSchema = (prices: AdvertiserPriceFragment[]) => object().shape({ name: string().label("Campaign Name").required(), format: string() @@ -177,7 +176,7 @@ export const CampaignSchema = (prices: PriceFragment[]) => }); export function findPrice( - prices: PriceFragment[], + prices: AdvertiserPriceFragment[], format: CampaignFormat, billingType: BillingType, defaultPrice: string,