Skip to content

Commit 172e502

Browse files
authored
Merge pull request #52 from 9ITHON/design/#47
feat/#47 api 기능들
2 parents 215866a + 22a945d commit 172e502

15 files changed

Lines changed: 178 additions & 23 deletions

src/api/addPoint.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { post } from "./index";
2+
export const addPoint = async () => {
3+
const response = await post("/point/add");
4+
return response.data;
5+
};

src/api/fetchCoupon.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { get } from "./index";
2+
3+
export const fetchCoupon = async (userId) => {
4+
const response = await get(`/coupon/all/${userId}`);
5+
return response.data.data;
6+
};

src/api/fetchPoint.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { get } from "./index";
2+
export const fetchPoint = async () => {
3+
const response = await get("/user/point");
4+
return response.data;
5+
};

src/api/subtractPoint.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { post } from "./index";
2+
3+
export const subtractPoint = async (point) => {
4+
const response = await post("/point/subtract", { subtractPoint: point });
5+
return response.data;
6+
};

src/components/CouponMenuItem.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ const CouponMenuItem = ({
1414
onClick={isAvailable ? onClick : null}
1515
>
1616
<div className="flex flex-row justify-center gap-4">
17-
<div className="bg-amber-200 w-15 h-15 rounded-xl flex justify-center items-center">
17+
<div className="bg-white w-15 h-15 rounded-xl flex justify-center items-center">
1818
{imageUrl ? (
19-
<img src={imageUrl} alt="쿠폰 이미지" className="w-6 h-6" />
19+
<img
20+
src={imageUrl}
21+
alt="쿠폰 이미지"
22+
className="w-full h-full object-cover rounded-xl"
23+
/>
2024
) : (
2125
<div className="text-xs text-white">No Img</div>
2226
)}

src/components/GoodsCard.jsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
import React from "react";
2-
3-
const GoodsCard = ({ imageSrc, title, description, point }) => {
2+
import { subtractPoint } from "../api/subtractPoint";
3+
const GoodsCard = ({
4+
imageSrc,
5+
title,
6+
description,
7+
point,
8+
myPoint,
9+
setPoint,
10+
}) => {
11+
const handleClick = async () => {
12+
try {
13+
console.log(point);
14+
await subtractPoint(point);
15+
setPoint(myPoint - point);
16+
console.log("포인트 차감 성공!");
17+
} catch (error) {
18+
console.error("포인트 차감 실패:", error);
19+
}
20+
};
421
return (
5-
<div className="flex flex-col items-center justify-between bg-white rounded-xl p-2 w-full max-w-[160px]">
22+
<div
23+
onClick={handleClick}
24+
className="flex flex-col items-center justify-between bg-white rounded-xl p-2 w-full max-w-[160px]"
25+
>
626
<div className="w-full h-auto rounded-md overflow-hidden flex justify-center items-center">
727
<img
828
src={imageSrc}

src/components/KakaoMap.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CurrentPinSvg from "../assets/icons/CurrentPin.svg";
66

77
const KakaoMap = ({ lat = 37.4024068885376, lng = 127.101100614 }) => {
88
const [state, setState] = useState({
9-
center: { lat: lat - 0.0007, lng },
9+
center: { lat: lat - 0.0009, lng },
1010
isPanto: true,
1111
});
1212

@@ -17,7 +17,7 @@ const KakaoMap = ({ lat = 37.4024068885376, lng = 127.101100614 }) => {
1717
if (lat && lng) {
1818
setState((prev) => ({
1919
...prev,
20-
center: { lat: lat - 0.0007, lng },
20+
center: { lat: lat - 0.0009, lng },
2121
}));
2222
}
2323
}, [lat, lng]);
@@ -33,7 +33,7 @@ const KakaoMap = ({ lat = 37.4024068885376, lng = 127.101100614 }) => {
3333
} else if (lat && lng) {
3434
setState((prev) => ({
3535
...prev,
36-
center: { lat: lat - 0.0007, lng },
36+
center: { lat: lat - 0.0009, lng },
3737
}));
3838
}
3939
}, [selectedLocation, lat, lng]);
@@ -59,7 +59,7 @@ const KakaoMap = ({ lat = 37.4024068885376, lng = 127.101100614 }) => {
5959
position={{ lat: lat, lng: lng }}
6060
image={{
6161
src: CurrentPinSvg, // public 폴더 기준 경로
62-
size: { width: 40, height: 40 },
62+
size: { width: 55, height: 55 },
6363
options: { offset: { x: 20, y: 40 } },
6464
}}
6565
/>

src/components/Popup/CouponPopup.jsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { useState, useEffect } from "react";
22
import Back3DBtnIcon from "../../assets/icons/Back_3D_btn.svg";
33
import { useNavStore } from "../../stores/navStore";
4+
import { useUserStore } from "../../stores/userStore";
45
import { getDDay } from "../../utils/getDay";
56
import CouponMenuItem from "../CouponMenuItem";
67
import CouponClickPopup from "./CouponClickPopup";
8+
import { fetchCoupon } from "../../api/fetchCoupon";
79
const dummyCoupons = [
810
{
911
id: 1,
@@ -52,10 +54,30 @@ const CouponPopup = ({ onClose }) => {
5254
// 네비바 주스탠드로 상태 관리
5355
const hideNav = useNavStore((state) => state.hideNav);
5456
const showNav = useNavStore((state) => state.showNav);
57+
const userId = useUserStore((state) => state.id);
5558
const [activeTab, setActiveTab] = useState("사용 가능");
5659
const [selectedCoupon, setSelectedCoupon] = useState(null); // 추가
57-
60+
const [coupons, setCoupons] = useState("");
5861
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+
})();
5981
hideNav(); // 진입시 네비 숨김
6082
return showNav; // 언마운트(나갈 때) 복구
6183
}, []);
@@ -122,7 +144,9 @@ const CouponPopup = ({ onClose }) => {
122144
{filteredCoupons.map((coupon) => (
123145
<CouponMenuItem
124146
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+
}
126150
title={coupon.title}
127151
date={getDDay(coupon.deadline)}
128152
isAvailable={coupon.isAvailable}

src/components/Popup/DonateDecidePopup.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import React from "react";
22
import WaringBlockSVG from "../../assets/icons/WarningBlock.svg";
33
import XblockSVG from "../../assets/icons/Xblock.svg";
4+
import { subtractPoint } from "../../api/subtractPoint";
45

5-
const DonateDecidePopup = ({ onClose }) => {
6+
const DonateDecidePopup = ({ onClose, point, setPoint }) => {
7+
const handleClick = async () => {
8+
try {
9+
// point 값을 넘겨서 API 호출
10+
await subtractPoint(20);
11+
setPoint(point - 20);
12+
console.log("포인트 차감 성공!");
13+
// 필요하다면 사용자 알림이나 UI 업데이트 로직 추가
14+
} catch (error) {
15+
console.error("포인트 차감 실패:", error);
16+
}
17+
};
618
return (
719
<div className="fixed inset-0 bg-black/40 gap-2 flex flex-col justify-center items-center z-50 p-4">
820
<div className=" flex w-full justify-end">
@@ -24,7 +36,10 @@ const DonateDecidePopup = ({ onClose }) => {
2436
>
2537
취소
2638
</button>
27-
<button className="mainColor text-white rounded-full px-4 py-2 flex-1/2">
39+
<button
40+
className="mainColor text-white rounded-full px-4 py-2 flex-1/2"
41+
onClick={handleClick}
42+
>
2843
기부
2944
</button>
3045
</div>

src/components/Popup/DonatePopup.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PigPNG from "../../assets/pig.png";
55
import DonateLogItem from "../DonateLoItem";
66
import DonateDecidePopup from "./DonateDecidePopup";
77
import { useNavStore } from "../../stores/navStore";
8-
const DonatePopup = ({ onClose, point, donateLogs }) => {
8+
const DonatePopup = ({ onClose, point, donateLogs, setPoint }) => {
99
const [donateDecidePopup, setDonateDecidePopup] = useState(false);
1010
// 네비바 주스탠드로 상태 관리
1111
const hideNav = useNavStore((state) => state.hideNav);
@@ -54,7 +54,11 @@ const DonatePopup = ({ onClose, point, donateLogs }) => {
5454
</div>
5555

5656
{donateDecidePopup && (
57-
<DonateDecidePopup onClose={() => setDonateDecidePopup(false)} />
57+
<DonateDecidePopup
58+
onClose={() => setDonateDecidePopup(false)}
59+
point={point}
60+
setPoint={setPoint}
61+
/>
5862
)}
5963
</div>
6064
);

0 commit comments

Comments
 (0)