diff --git a/src/apis/index.ts b/src/apis/index.ts index a457d6c..a58b45a 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -78,4 +78,13 @@ export const postSmoke = async (body: SmokeType) => { return data; } catch (e) { } -} \ No newline at end of file +} + +export const checkSmoked = async () => { + const { data } = await instance.get("/api/smoke/check", { + headers: { + Authorization: `Bearer ${localStorage.getItem("accessToken")}`, + } + }); + return data; +}; \ No newline at end of file diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index ba09bd9..5f763c2 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -12,7 +12,7 @@ import ThreeDaysCheckBox from "../../components/ThreeDaysCheckBox/ThreeDaysCheck import GrassChart from "../../components/GrassChart/GrassChart"; import RateBox from "../../components/RateBox/RateBox"; import TwoButton from "../../components/atoms/TwoButton"; -import { getGrassChart, getSimpleStats } from "../../apis"; +import { checkSmoked, getGrassChart, getSimpleStats } from "../../apis"; import { GrassType, grassTypeDefault } from "../Record/type"; import { SimpleStatsType, simpleStatsTypeDefault } from "./type"; @@ -21,6 +21,7 @@ const Home = () => { const BottomSheetBackground = useRef(); const [stats, setStats] = useState(simpleStatsTypeDefault); const [grass, setGrass] = useState(grassTypeDefault); + const [isSmoked, setIsSmoked] = useState(); useEffect(() => { const accessToken = localStorage.getItem("accessToken"); @@ -42,6 +43,11 @@ const Home = () => { setGrass(data); }; + const checkSmoke = async () => { + const res = await checkSmoked(); + setIsSmoked(res); + }; + localStorage.removeItem("email"); localStorage.removeItem("isRegister"); @@ -51,8 +57,11 @@ const Home = () => { } getStats(); + checkSmoke(); }, []); + + return ( @@ -87,7 +96,14 @@ const Home = () => { { window.location.href = "/retry" }} + largeOnClick={() => { + if (isSmoked) { + setBottomSheetOpen(false); + alert("이미 금연 실패 버튼을 눌렀습니다."); + return; + } + window.location.href = "/retry"; + }} smallOnClick={() => setBottomSheetOpen(false)} />