From 4460f722270c8a713a01e24f26e3574430703756 Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Fri, 25 Aug 2023 16:49:16 -0400 Subject: [PATCH] fix: edit values --- .../Creatives/CreateCreativeButton.tsx | 5 ++++- .../Creatives/CreativeSpecificPreview.tsx | 14 +++++++++++++ .../Creatives/NotificationSelect.tsx | 21 +++++++++++-------- src/user/library/index.ts | 17 +++++++++------ .../advanced/components/adSet/NewAdSet.tsx | 9 +++++++- .../review/components/AdSetReview.tsx | 14 +++++-------- 6 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/components/Creatives/CreateCreativeButton.tsx b/src/components/Creatives/CreateCreativeButton.tsx index e65360833..79e595614 100644 --- a/src/components/Creatives/CreateCreativeButton.tsx +++ b/src/components/Creatives/CreateCreativeButton.tsx @@ -47,7 +47,10 @@ export function CreateCreativeButton() { e.preventDefault(); create({ variables: { - input: { ...newMeta.value, advertiserId: advertiser.id }, + input: { + ..._.omit(newMeta.value, "included"), + advertiserId: advertiser.id, + }, }, }); }} diff --git a/src/components/Creatives/CreativeSpecificPreview.tsx b/src/components/Creatives/CreativeSpecificPreview.tsx index 939be7bc6..0a438ec08 100644 --- a/src/components/Creatives/CreativeSpecificPreview.tsx +++ b/src/components/Creatives/CreativeSpecificPreview.tsx @@ -5,15 +5,18 @@ import { Stack, Typography } from "@mui/material"; import { PropsWithChildren } from "react"; import { useField } from "formik"; import { Creative } from "user/views/adsManager/types"; +import { DisplayError } from "user/views/adsManager/views/advanced/components/review/components/ReviewField"; interface Props extends PropsWithChildren { options: Creative[]; useSimpleHeader?: boolean; + error?: string; } export function CreativeSpecificPreview({ options, useSimpleHeader, + error, children, }: Props) { const [, format] = useField("format"); @@ -30,6 +33,17 @@ export function CreativeSpecificPreview({ )); } + if (error) { + return ( + <> + + Ads + + + + ); + } + return ( <> {useSimpleHeader && ( diff --git a/src/components/Creatives/NotificationSelect.tsx b/src/components/Creatives/NotificationSelect.tsx index 0d28845d3..4b6d552d8 100644 --- a/src/components/Creatives/NotificationSelect.tsx +++ b/src/components/Creatives/NotificationSelect.tsx @@ -14,6 +14,7 @@ export function NotificationSelect(props: { useSelectedAdStyle?: boolean; showState?: boolean; index?: number; + hideCreated?: boolean; }) { const index = props.index; const { values, setFieldValue } = useFormikContext(); @@ -32,7 +33,7 @@ export function NotificationSelect(props: { const foundIndex = values.adSets[index].creatives.findIndex( (co) => c.id === co.id, ); - if (foundIndex >= 0) { + if (foundIndex !== undefined) { void setFieldValue( `adSets.${index}.creatives.${foundIndex}.included`, selected, @@ -72,14 +73,16 @@ export function NotificationSelect(props: { body={co.payloadNotification?.body} selected={isSelected(co)} /> - - created {moment(co.createdAt).fromNow()} - + {!(props.hideCreated ?? false) && ( + + created {moment(co.createdAt).fromNow()} + + )} ))} diff --git a/src/user/library/index.ts b/src/user/library/index.ts index 4992a02ad..b762d6da3 100644 --- a/src/user/library/index.ts +++ b/src/user/library/index.ts @@ -137,7 +137,7 @@ export function editCampaignValues( })), isNotTargeting: seg.length === 1 && seg[0].code === "Svp7l-zGN", name: adSet.name || adSet.id.split("-")[0], - creatives: creativeList(advertiserId, adSet.ads), + creatives: creativeList(advertiserId, adSet.ads, ads), } as AdSetForm; }), isCreating: false, @@ -165,19 +165,24 @@ export function editCampaignValues( function creativeList( advertiserId: string, - ads?: AdFragment[] | null, + adSetAds?: AdFragment[] | null, + allAds?: AdFragment[] | null, includeId?: boolean, ): Creative[] { - return _.uniqBy( - (ads ?? []) + const filterAds = (a?: AdFragment[] | null, included?: boolean) => { + return (a ?? []) .filter((ad) => ad.creative !== null && ad.state !== "deleted") .map((ad) => { const c = ad.creative; return { - ...validCreativeFields(c, advertiserId, true), + ...validCreativeFields(c, advertiserId, included), creativeInstanceId: includeId !== false ? ad.id : undefined, }; - }), + }); + }; + + return _.uniqBy( + [...filterAds(adSetAds, true), ...filterAds(allAds, false)], "id", ); } diff --git a/src/user/views/adsManager/views/advanced/components/adSet/NewAdSet.tsx b/src/user/views/adsManager/views/advanced/components/adSet/NewAdSet.tsx index 0847965e2..f36d63ec7 100644 --- a/src/user/views/adsManager/views/advanced/components/adSet/NewAdSet.tsx +++ b/src/user/views/adsManager/views/advanced/components/adSet/NewAdSet.tsx @@ -13,8 +13,10 @@ import { CampaignForm, initialAdSet } from "user/views/adsManager/types"; import { useRef } from "react"; import RemoveCircleOutlineIcon from "@mui/icons-material/RemoveCircleOutline"; import { useIsEdit } from "form/FormikHelpers"; +import { useAdvertiserCreatives } from "user/hooks/useAdvertiserCreatives"; export function NewAdSet() { + const { creatives } = useAdvertiserCreatives(); const { isEdit } = useIsEdit(); const history = useHistory(); const { values } = useFormikContext(); @@ -22,6 +24,11 @@ export function NewAdSet() { const selected = useRef(0); selected.current = Number(params.get("current") ?? 0); + const initial = { + ...initialAdSet, + creatives, + }; + return ( <> @@ -77,7 +84,7 @@ export function NewAdSet() { pb={0} pt={0} component={Button} - onClick={() => helper.push(initialAdSet)} + onClick={() => helper.push(initial)} border="1px solid #ededed" > diff --git a/src/user/views/adsManager/views/advanced/components/review/components/AdSetReview.tsx b/src/user/views/adsManager/views/advanced/components/review/components/AdSetReview.tsx index fdfc14f9b..1917ae07a 100644 --- a/src/user/views/adsManager/views/advanced/components/review/components/AdSetReview.tsx +++ b/src/user/views/adsManager/views/advanced/components/review/components/AdSetReview.tsx @@ -51,15 +51,11 @@ export function AdSetReview({ adSet, idx, errors }: Props) { conversions={adSet.conversions} convErrors={adSetError?.conversions} /> - {hasErrors ? ( - - ) : ( - - )} + ); }