Skip to content

Commit 9d2c8a3

Browse files
committed
fix(promotion): handling nullish coaleshing
1 parent 76e555d commit 9d2c8a3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

common/components/elements/MultiplePromotion.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ interface MultiplePromotionProps {
1212
}
1313

1414
export default function MultiplePromotion({ path }: MultiplePromotionProps) {
15-
const { data, isLoading } = useSWR('/api/ads/banner', fetcher)
15+
const { data, isLoading, error } = useSWR('/api/ads/banner', fetcher)
1616
if (isLoading) return
17-
const banners: IAdsBanner[] = data?.data.filter((item: IAdsBanner) => item.showingOn.includes(path))
17+
const banners: IAdsBanner[] = data?.data?.filter((item: IAdsBanner) => item?.showingOn?.includes(path))
18+
if (!banners.length || error) return null
1819
return (
1920
<div className="mt-6 flex flex-col items-center gap-2">
2021
{banners?.map((banner: IAdsBanner, index: number) => <AdsBanner key={index} data={banner} />)}

common/components/elements/SinglePromotion.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ interface SinglePromotionProps {
1313
}
1414

1515
export default function SinglePromotion({ path }: SinglePromotionProps) {
16-
const { data, isLoading } = useSWR('/api/ads/banner', fetcher)
16+
const { data, isLoading, error } = useSWR('/api/ads/banner', fetcher)
1717
if (isLoading) return <Skeleton className="h-10 w-72" />
18-
const banner: IAdsBanner = data?.data.find((item: IAdsBanner) => item.showingOn.includes(path))
19-
console.log(banner)
18+
const banner: IAdsBanner = data?.data?.find((item: IAdsBanner) => item?.showingOn?.includes(path))
19+
if (!banner || error) return null
2020
return <AdsBanner data={banner} />
2121
}

0 commit comments

Comments
 (0)