Skip to content

Commit

Permalink
Merge branch 'dev' into feature/Choco-Express#4
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyeonjinn authored Sep 5, 2024
2 parents 746c44f + 9e430a6 commit b74b0c4
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 22 deletions.
19 changes: 12 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.7",

"axios": "^1.7.6",

"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-frame-component": "^5.2.7",
Expand Down
1 change: 0 additions & 1 deletion src/apis/instance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from "axios";
// Axios 인스턴스 생성
export const instance = axios.create({
baseURL: import.meta.env.VITE_BASE_URL,
withCredentials: true,
Expand Down
11 changes: 11 additions & 0 deletions src/apis/otherBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { instance } from "./instance";

export const getOtherBoxContents = async (box_id) => {
try {
const res = await instance.get(`/api/box/${box_id}`);
return res;
} catch (err) {
console.log(err);
throw err;
}
};
15 changes: 15 additions & 0 deletions src/apis/postChoco.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { instance } from "./instance";

export const postChocolate = async (boxId, nickname, contents, chocoType) => {
try {
const res = await instance.post(`/api/box/${boxId}/choco`, {
nickname,
contents,
chocoType,
});
return res;
} catch (err) {
console.log(err);
throw err;
}
};
2 changes: 1 addition & 1 deletion src/assets/images/Chocolates/Chocolate_5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/assets/images/Chocolates/Chocolate_6.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions src/components/ChocoSelector/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ export const BoxItem = styled.div`
display: flex;
justify-self: center;
align-self: center;
width: 98px;
height: 91px;
width: 100px;
height: 113.136px;
img {
width: 100%;
height: 100%;
object-fit: contain;
filter: ${({ selected }) =>
selected ? "drop-shadow(0px 0px 15px rgba(255, 20, 147, 0.8))" : "none"};
cursor: pointer;
}
`;

Expand Down
4 changes: 4 additions & 0 deletions src/components/common/Button/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export const Btn = styled.div`
font-weight: 600;
line-height: 120%; /* 20.4px */
cursor: pointer;
&:hover,
:active {
background: #f34381;
}
`;
2 changes: 1 addition & 1 deletion src/constants/Chocolates/data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CHOCO_1 from "../../assets/images/Chocolates/chocolate_1.png";
import CHOCO_1 from "../../assets/images/Chocolates/Chocolate_1.svg";
import CHOCO_2 from "../../assets/images/Chocolates/Chocolate_2.svg";
import CHOCO_3 from "../../assets/images/Chocolates/Chocolate_3.svg";
import CHOCO_4 from "../../assets/images/Chocolates/Chocolate_4.svg";
Expand Down
24 changes: 24 additions & 0 deletions src/hooks/useOtherBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getOtherBoxContents } from "../apis/otherBox";
import React, { useState, useEffect } from "react";
import { useParams } from "react-router-dom";

export const useOtherBox = () => {
const { boxId } = useParams();
console.log("박스 id는 :", boxId);
const [otherData, setOtherData] = useState(null);

const fetchOtherBoxData = async () => {
try {
const res = await getOtherBoxContents(boxId);
setOtherData(res.data.result);
} catch (err) {
console.log(err);
}
};

useEffect(() => {
fetchOtherBoxData();
}, []);

return { otherData };
};
21 changes: 19 additions & 2 deletions src/pages/LetterPage/LetterPostPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import HeartBackG from "../../components/common/Heartbackground/heartBackG";
import ChocoSelector from "../../components/ChocoSelector/ChocoSelector";
import { LetterPost } from "../../components/letterPost/LetterPost";
import { useNavigate } from "react-router-dom";
import { useParams } from "react-router-dom";
import { postChocolate } from "../../apis/postChoco";

export const LetterPostPage = () => {
const navigate = useNavigate();
const { boxId } = useParams();
const [selectedChoco, setSelectedChoco] = useState("");
const [isSelectedChoco, setIsSelectedChoco] = useState(false);
const [nickName, setNickName] = useState("");
Expand Down Expand Up @@ -35,11 +39,24 @@ export const LetterPostPage = () => {
setIsNameSetting(false);
};

const handleContentSubmit = (content) => {
const handleContentSubmit = async (content) => {
console.log(content);
//서버에 post 후 완료페이지로 이동
navigate("/box/complete");

try {
const res = await postChocolate(boxId, nickName, content, selectedChoco);

if (res.status === 201) {
console.log("초콜릿전달 성공");
navigate("/box/complete");
} else {
console.log("초콜릿 전송 실패");
}
} catch (err) {
console.log(err);
}
};

return (
<S.Container>
<HeartBackG />
Expand Down
16 changes: 13 additions & 3 deletions src/pages/otherboxPage/otherboxPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ import * as S from "./styled";
import HeartBackG from "../../components/common/Heartbackground/heartBackG";
import { useNavigate } from "react-router-dom";
import { BOXES } from "../../constants/Boxes/data";
import { useOtherBox } from "../../hooks/useOtherBox";
import { useParams } from "react-router-dom";
export const OtherboxPage = () => {
const { boxId } = useParams();
const { otherData } = useOtherBox();
console.log("otherData:", otherData);
const navigate = useNavigate();

const MoveOnLetterP = () => {
navigate("letter");
navigate(`box/${boxId}/choco`);
};
if (!otherData) {
return <div>Loading...</div>; // 데이터가 로드되기 전에 로딩 메시지를 표시하거나 로딩 스피너를 추가할 수 있음
}
const selectedBox = BOXES.find((box) => box.id === otherData.boxType);
return (
<S.Container>
<HeartBackG />
<S.Wrapper>
<div className="Box">
<div>[하채민] 의 초콜릿 상자</div>
<div>[{otherData.boxName}] 의 초콜릿 상자</div>
<S.BoxContainer>
<img src={BOXES[1].src} className="boxImg" />
<img src={selectedBox.src} className="boxImg" />
</S.BoxContainer>
</div>
<S.ButtonContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ const router = createBrowserRouter([
element: <App />,
children: [
{
path: "/box",
path: "/box/:boxId",
element: <OtherboxPage />,
},
{
path: "/box/complete",
element: <CompletePage />,
},
{
path: "/box/letter",
path: "box/:boxId/choco",
element: <LetterPostPage />,
},

Expand Down

0 comments on commit b74b0c4

Please sign in to comment.