clickSize("tall")}
+ onClick={() => clickSize("Tall")}
>
톨
@@ -113,11 +127,11 @@ const CustomModal = ({
clickSize("grande")}
+ onClick={() => clickSize("Grande")}
>
그란데
@@ -134,11 +148,11 @@ const CustomModal = ({
clickSize("venti")}
+ onClick={() => clickSize("Venti")}
>
벤티
diff --git a/src/components/organisms/RecommendationModal.tsx b/src/components/organisms/RecommendationModal.tsx
new file mode 100644
index 0000000..35e6f80
--- /dev/null
+++ b/src/components/organisms/RecommendationModal.tsx
@@ -0,0 +1,70 @@
+import React, { useRef, useState } from "react";
+import { BasketMenuType } from "../../types/menu";
+import { useSession } from "../../hooks/basketContext";
+import { useQuery } from "react-query";
+import { ApiClient } from "../../apis/apiClient";
+import MenuCard from "./MenuCard";
+
+const RecommendationModal = ({
+ message,
+ modalToggle,
+ modalToggle2,
+ setMenuFunc,
+ setFromRecommend,
+ count,
+ setCountFunc,
+}: {
+ message: string;
+ modalToggle: () => void;
+ modalToggle2: () => void;
+ setMenuFunc: () => void;
+ setFromRecommend: () => void;
+ count: number;
+ setCountFunc: () => void;
+}) => {
+ const clickConfirm = () => {
+ modalToggle2();
+ };
+
+ const { isLoading, data } = useQuery({
+ queryKey: ["recommendations"],
+ queryFn: () => {
+ const res = ApiClient.getInstance().getRecommendationList();
+ return res;
+ },
+ });
+
+ return (
+
+
+
+
modalToggle2()}
+ />
+
+
+ {message}
+
+
modalToggle()}
+ count={count}
+ setCountFunc={setCountFunc}
+ />
+
+
clickConfirm()}
+ >
+ 선택 완료
+
+
+
+
+ );
+};
+
+export default RecommendationModal;
diff --git a/src/context/basketContext.tsx b/src/hooks/basketContext.tsx
similarity index 81%
rename from src/context/basketContext.tsx
rename to src/hooks/basketContext.tsx
index 348f19c..3207433 100644
--- a/src/context/basketContext.tsx
+++ b/src/hooks/basketContext.tsx
@@ -80,10 +80,16 @@ const reducer = (basket: BasketType, { type, payload }: Action): BasketType => {
case "plusMenu":
for (let i = 0; i < basket.basketList.length; i++) {
- let menu = basket.basketList[i];
+ let menu = { ...basket.basketList[i] };
if (menu.basketIdx == payload) {
- newer = [...basket.basketList];
- newer[i].orderDetailCount++;
+ i == basket.basketList.length - 1
+ ? (newer = basket.basketList.slice(0, i))
+ : (newer = [
+ ...basket.basketList.slice(0, i),
+ ...basket.basketList.slice(i + 1, basket.basketList.length),
+ ]);
+ menu.orderDetailCount = basket.basketList[i].orderDetailCount + 1;
+ newer.splice(i, 0, menu);
newer2 += menu.menuPrice;
break;
}
@@ -92,10 +98,16 @@ const reducer = (basket: BasketType, { type, payload }: Action): BasketType => {
case "minusMenu":
for (let i = 0; i < basket.basketList.length; i++) {
- let menu = basket.basketList[i];
+ let menu = { ...basket.basketList[i] };
if (menu.basketIdx == payload) {
- newer = [...basket.basketList];
- newer[i].orderDetailCount--;
+ i == basket.basketList.length - 1
+ ? (newer = basket.basketList.slice(0, i))
+ : (newer = [
+ ...basket.basketList.slice(0, i),
+ ...basket.basketList.slice(i + 1, basket.basketList.length),
+ ]);
+ menu.orderDetailCount = basket.basketList[i].orderDetailCount - 1;
+ newer.splice(i, 0, menu);
newer2 -= menu.menuPrice;
break;
}
diff --git a/src/pages/MenuPage.tsx b/src/pages/MenuPage.tsx
index 25a4f7c..832ecc5 100644
--- a/src/pages/MenuPage.tsx
+++ b/src/pages/MenuPage.tsx
@@ -6,14 +6,17 @@ import Category from "../components/ui/Category";
import { CategoryType } from "../types/category";
import CustomModal from "../components/organisms/CustomModal";
import { BasketMenuType } from "../types/menu";
-import { useSession } from "../context/basketContext";
+import { useSession } from "../hooks/basketContext";
import BasketMenu from "../components/molecules/BasketMenu";
import BasketCard from "../components/organisms/BasketCard";
+import RecommendationModal from "../components/organisms/RecommendationModal";
const MenuPage = () => {
const [categoryIdx, setCategoryIdx] = useState
(1);
const [categoryList, setCategoryList] = useState([]);
const [openModal, setOpenModal] = useState(false);
+ const [openModal2, setOpenModal2] = useState(false);
+ const [fromRecommend, setFromRecommend] = useState(false);
const [selectedMenu, setSelectedMenu] = useState();
const [count, setCount] = useState(1);
@@ -43,6 +46,10 @@ const MenuPage = () => {
setOpenModal(true);
};
+ const setOpenModal2Func = () => {
+ setOpenModal2(true);
+ };
+
const setMenuFunc = (menu: BasketMenuType) => {
setSelectedMenu(menu);
};
@@ -51,6 +58,13 @@ const MenuPage = () => {
setCount(count + 1);
};
+ const clickConfirm = () => {
+ if (basket.basketList.length == 0) {
+ return;
+ }
+ setOpenModal2(!openModal2);
+ };
+
return (
@@ -59,8 +73,21 @@ const MenuPage = () => {
setOpenModal(!openModal)}
+ modalToggle2={() => setOpenModal2(!openModal2)}
menu={selectedMenu!}
setCountFunc={setCountFunc}
+ fromRecommend={fromRecommend}
+ />
+ )}
+ {openModal2 && (
+ setOpenModal(!openModal)}
+ modalToggle2={() => setOpenModal2(!openModal2)}
+ setMenuFunc={setCountFunc}
+ setFromRecommend={() => setFromRecommend(!fromRecommend)}
+ count={count}
+ setCountFunc={setCountFunc}
/>
)}
@@ -121,7 +148,7 @@ const MenuPage = () => {