diff --git a/packages/common/components/src/api/attachment.ts b/packages/common/components/src/api/attachment.ts new file mode 100644 index 000000000..f1645013e --- /dev/null +++ b/packages/common/components/src/api/attachment.ts @@ -0,0 +1,14 @@ +import { getConfig } from "@common/config"; +import { ENDPOINT } from "../config"; + +const { PROXY_HOST } = getConfig(); +const BASE_URL = `${PROXY_HOST}/server`; + +export const getImageUrlByAtflCd = async (atflCd: string): Promise => { + if (!atflCd) return ""; + const response = await fetch( + `${BASE_URL}/${ENDPOINT.ATTACH_SERVICE.IMAGES}/atflCd/${atflCd}`, + ); + const blob = await response.blob(); + return URL.createObjectURL(blob); +}; diff --git a/packages/common/components/src/api/banner.ts b/packages/common/components/src/api/banner.ts new file mode 100644 index 000000000..b002755be --- /dev/null +++ b/packages/common/components/src/api/banner.ts @@ -0,0 +1,35 @@ +import { getApiClient } from "./client"; +import { getConfig } from "@common/config"; +import { ENDPOINT } from "../config"; + +export interface Banner { + bnrSn: number; + bnrTypeCd: string; + bnrTypeNm: string; + bnrTtl: string; + lnkgUrlAddr: string; + useYn: string; + atflCd: string; + mdfcnDt: string; + mdfr: string; + mdfrNm: string; + } + + + const { PROXY_HOST } = getConfig(); + const BASE_URL = `${PROXY_HOST}/server`; + +const client = getApiClient(); + +export const getBannerList = async (siteId: string) => { + const response = await client.get( + `${BASE_URL}/${ENDPOINT.CMS_SERVICE.BANNERS}/${siteId}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }, + ); + return response.data; +}; diff --git a/packages/common/components/src/api/index.ts b/packages/common/components/src/api/index.ts index d569765c2..1b4428333 100644 --- a/packages/common/components/src/api/index.ts +++ b/packages/common/components/src/api/index.ts @@ -1,3 +1,5 @@ +export * from "./attachment"; +export * from "./banner"; export * from "./client"; export * from "./connection-log"; export * from "./menu"; diff --git a/packages/common/components/src/config/api.ts b/packages/common/components/src/config/api.ts index 019a86d75..62aeb59f7 100644 --- a/packages/common/components/src/config/api.ts +++ b/packages/common/components/src/config/api.ts @@ -9,8 +9,12 @@ export const ENDPOINT = { CONNECTION_LOG: "/cms-service/api/v1/cntnlog", NOTICE: "/cms-service/api/v1/noti", NOTICE_USER: "/cms-service/api/v1/noti/user", + BANNERS: "/cms-service/api/v1/bnrs/user", }, USER_SERVICE: { USERS: "/user-service/api/v1/users", }, + ATTACH_SERVICE: { + IMAGES: "/attach-service/api/v1/images", + }, }; diff --git a/packages/common/components/src/ui/footer/index.tsx b/packages/common/components/src/ui/footer/index.tsx index 34b2e46e9..2ef415dce 100644 --- a/packages/common/components/src/ui/footer/index.tsx +++ b/packages/common/components/src/ui/footer/index.tsx @@ -1,8 +1,9 @@ import { useRef } from "react"; +import Image from "next/image"; import Autoplay from "embla-carousel-autoplay"; import { useQuery } from "@tanstack/react-query"; import { ENDPOINT } from "../../config"; -import { getSiteInfo } from "../../api"; +import { getSiteInfo, getBannerList, getImageUrlByAtflCd } from "../../api"; import { getCookie } from "../../lib"; import { Carousel, @@ -14,17 +15,67 @@ import { const siteId = getCookie("site-id-key") ?? ""; +type BannerImageProps = { + atflCd: string; + bnrSn: number; + lnkgUrlAddr: string; +}; + +const BannerImage = ({ atflCd, bnrSn, lnkgUrlAddr }: BannerImageProps) => { + const { data: imageUrl, isLoading } = useQuery({ + queryKey: [ENDPOINT.ATTACH_SERVICE.IMAGES, atflCd], + queryFn: () => getImageUrlByAtflCd(atflCd), + enabled: !!atflCd, + }); + + const handleClick = () => { + if (lnkgUrlAddr) { + window.open(lnkgUrlAddr, '_blank'); + } + }; + + if (isLoading) { + return ( +
+
로딩 중...
+
+ ); + } + + if (!imageUrl) { + return ( +
+
이미지 없음
+
+ ); + } + + return ( +
+ 배너 이미지 +
+ ); +}; + export function Footer() { const { data: siteInfo } = useQuery({ queryKey: [ENDPOINT.CMS_SERVICE.SITES, siteId], queryFn: () => getSiteInfo(siteId), }); + const { data: bannerList } = useQuery({ + queryKey: [ENDPOINT.CMS_SERVICE.BANNERS, siteId], + queryFn: () => getBannerList(siteId), + }); + const plugin = useRef(Autoplay({ delay: 2000, stopOnInteraction: true })); return ( -