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

Feature/update creative uri to creative urls #187

Merged
merged 5 commits into from
Oct 17, 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
20 changes: 0 additions & 20 deletions src/components/AdDisplay/AdDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,11 @@ function Ad({
function AdContainer({
secure_url,
index,
fileImage,
setFileImage,
scale,
children,
}: {
secure_url: string;
index: number;
fileImage: object[] | undefined;
setFileImage: any;
scale: number | undefined;
children: React.ReactNode;
}) {
Expand Down Expand Up @@ -113,19 +109,15 @@ function AdContainer({
}

function Ads({
fileImage,
imageMedia,
setFileImage,
scale,
adTitle,
adCopy,
target,
callToAction,
buttonText,
}: {
fileImage: object[] | undefined;
imageMedia: { secure_url: string; mediaUrlType: string }[];
setFileImage: any;
scale: number | undefined;
adTitle?: string | undefined;
adCopy?: string | undefined;
Expand All @@ -134,9 +126,7 @@ function Ads({
buttonText?: string | undefined;
}) {
const ads = getAds(
fileImage,
imageMedia,
setFileImage,
scale,
adTitle,
adCopy,
Expand All @@ -154,19 +144,15 @@ function Ads({
);
}
export default function AdDisplay({
fileImage,
imageMedia,
setFileImage,
scale,
adTitle,
adCopy,
target,
callToAction,
buttonText,
}: {
fileImage: object[];
imageMedia: { secure_url: string; mediaUrlType: string }[];
setFileImage: any;
scale?: number | undefined;
adTitle?: string | undefined;
adCopy?: string | undefined;
Expand All @@ -176,9 +162,7 @@ export default function AdDisplay({
}) {
return (
<Ads
fileImage={fileImage}
imageMedia={imageMedia}
setFileImage={setFileImage}
scale={scale}
adTitle={adTitle}
adCopy={adCopy}
Expand All @@ -190,9 +174,7 @@ export default function AdDisplay({
}

function getAds(
fileImage: object[] | undefined,
imageMedia: { secure_url: string; mediaUrlType: string }[],
setFileImage: any,
scale: number | undefined,
adTitle?: string,
adCopy?: string,
Expand All @@ -212,8 +194,6 @@ function getAds(
key={`${index}-ad-container`}
secure_url={secure_url}
index={index}
fileImage={fileImage}
setFileImage={setFileImage}
scale={scale}
>
<Ad
Expand Down
20 changes: 12 additions & 8 deletions src/components/DefaultAdDisplay/DefaultAdDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ interface MediaObject {
mediaUrlType: string | null;
}

const getMedia = (fileImage?: object[] | undefined): any => {
return typeof fileImage !== 'undefined'
const getMedia = (fileImage?: object[] | string[] | undefined): any => {
if (typeof fileImage === 'undefined') return fileImage;
if (typeof fileImage?.length === 'undefined') return fileImage;
return typeof fileImage[0] !== 'string'
? fileImage.map((media: any): MediaObject | undefined => {
const secure_url: string | null = media?.secure_url || null;
if (!secure_url) return undefined;
Expand All @@ -16,20 +18,24 @@ const getMedia = (fileImage?: object[] | undefined): any => {
mediaUrlType: detectMediaType(secure_url),
};
})
: fileImage;
: fileImage.map((url) => {
const secure_url: string = url as string;
return {
secure_url: secure_url,
mediaUrlType: detectMediaType(secure_url),
};
});
};
export default function DefaultAdDisplay({
fileImage,
setFileImage,
scale,
adTitle,
adCopy,
target,
callToAction,
buttonText,
}: {
fileImage: object[] | undefined;
setFileImage: any;
fileImage: object[] | string[] | undefined;
scale: number | undefined;
adTitle?: string | undefined;
adCopy?: string | undefined;
Expand All @@ -44,9 +50,7 @@ export default function DefaultAdDisplay({
className={'' /*"promo-scale-65 sm:promo--translate-x-4 promo--w-full"*/}
>
<AdDisplay
fileImage={fileImage}
imageMedia={media}
setFileImage={setFileImage}
scale={scale}
adTitle={adTitle}
adCopy={adCopy}
Expand Down
5 changes: 2 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function PromoButton({

let [isSubmitted, setIsSubmitted] = useState(false);
let [isSubmitting, setIsSubmitting] = useState(false);
let [fileImage, setFileImage] = useState(options?.inputValues?.creativeUri);
let [fileImage, setFileImage] = useState(options?.inputValues?.creativeUrls);
let [imageUploadError, setImageUploadError] = useState(false);
let [targetLinkError, setTargetLinkError] = useState(false);
let [adTitle, setAdTitle] = useState(options?.inputValues?.adTitle);
Expand Down Expand Up @@ -140,7 +140,7 @@ function PromoButton({
content.setPromoData({
target: data.target_link,
budget: data.budget,
creativeUri: fileImage,
creativeUrls: fileImage,
adTitle: data.asset_title,
buttonText: data.buttonText,
adCallToAction: data.callToAction,
Expand Down Expand Up @@ -341,7 +341,6 @@ function PromoButton({
</Suspense>
<AdDisplay
fileImage={fileImage}
setFileImage={setFileImage}
scale={65}
adTitle={adTitle || 'Tincre.dev Promo Button'}
adCopy={
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface InputValues {
adCallToAction?: string;
buttonText?: string;
creativeUri?: object[];
creativeUrls?: string[];
isFlat?: boolean;
}
export interface InputConfig {
Expand Down
Loading