|
1 | 1 | import React, { useState, useEffect } from "react"; |
2 | 2 | import Back3DBtnIcon from "../../assets/icons/Back_3D_btn.svg"; |
3 | 3 | import { useNavStore } from "../../stores/navStore"; |
| 4 | +import { useUserStore } from "../../stores/userStore"; |
4 | 5 | import { getDDay } from "../../utils/getDay"; |
5 | 6 | import CouponMenuItem from "../CouponMenuItem"; |
6 | 7 | import CouponClickPopup from "./CouponClickPopup"; |
| 8 | +import { fetchCoupon } from "../../api/fetchCoupon"; |
7 | 9 | const dummyCoupons = [ |
8 | 10 | { |
9 | 11 | id: 1, |
@@ -52,10 +54,30 @@ const CouponPopup = ({ onClose }) => { |
52 | 54 | // 네비바 주스탠드로 상태 관리 |
53 | 55 | const hideNav = useNavStore((state) => state.hideNav); |
54 | 56 | const showNav = useNavStore((state) => state.showNav); |
| 57 | + const userId = useUserStore((state) => state.id); |
55 | 58 | const [activeTab, setActiveTab] = useState("사용 가능"); |
56 | 59 | const [selectedCoupon, setSelectedCoupon] = useState(null); // 추가 |
57 | | - |
| 60 | + const [coupons, setCoupons] = useState(""); |
58 | 61 | useEffect(() => { |
| 62 | + (async () => { |
| 63 | + try { |
| 64 | + const result = await fetchCoupon(userId); |
| 65 | + const today = new Date(); |
| 66 | + |
| 67 | + const processedCoupons = result.map((coupon) => { |
| 68 | + const expiresAt = new Date(coupon.expiresAt); |
| 69 | + return { |
| 70 | + ...coupon, |
| 71 | + isAvailable: expiresAt > today, |
| 72 | + }; |
| 73 | + }); |
| 74 | + |
| 75 | + console.log(processedCoupons); |
| 76 | + setCoupons(processedCoupons); |
| 77 | + } catch (error) { |
| 78 | + console.error("API 호출 실패:", error); |
| 79 | + } |
| 80 | + })(); |
59 | 81 | hideNav(); // 진입시 네비 숨김 |
60 | 82 | return showNav; // 언마운트(나갈 때) 복구 |
61 | 83 | }, []); |
@@ -122,7 +144,9 @@ const CouponPopup = ({ onClose }) => { |
122 | 144 | {filteredCoupons.map((coupon) => ( |
123 | 145 | <CouponMenuItem |
124 | 146 | key={coupon.id} |
125 | | - imageUrl={coupon.imageUrl} |
| 147 | + imageUrl={ |
| 148 | + "https://cdn.pixabay.com/photo/2017/06/23/16/20/coupon-2435163_640.png" |
| 149 | + } |
126 | 150 | title={coupon.title} |
127 | 151 | date={getDDay(coupon.deadline)} |
128 | 152 | isAvailable={coupon.isAvailable} |
|
0 commit comments