Skip to content

Commit

Permalink
feat: 재도전 버튼 검증 미리 하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
마현우 committed Dec 10, 2023
1 parent de3863b commit cfd9839
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ export const postSmoke = async (body: SmokeType) => {
return data;
} catch (e) {
}
}
}

export const checkSmoked = async () => {
const { data } = await instance.get("/api/smoke/check", {
headers: {
Authorization: `Bearer ${localStorage.getItem("accessToken")}`,
}
});
return data;
};
20 changes: 18 additions & 2 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -21,6 +21,7 @@ const Home = () => {
const BottomSheetBackground = useRef<any>();
const [stats, setStats] = useState<SimpleStatsType>(simpleStatsTypeDefault);
const [grass, setGrass] = useState<GrassType>(grassTypeDefault);
const [isSmoked, setIsSmoked] = useState<any>();

useEffect(() => {
const accessToken = localStorage.getItem("accessToken");
Expand All @@ -42,6 +43,11 @@ const Home = () => {
setGrass(data);
};

const checkSmoke = async () => {
const res = await checkSmoked();
setIsSmoked(res);
};

localStorage.removeItem("email");
localStorage.removeItem("isRegister");

Expand All @@ -51,8 +57,11 @@ const Home = () => {
}

getStats();
checkSmoke();
}, []);



return (
<Layout>
<Screen bgcolor={color.gray100}>
Expand Down Expand Up @@ -87,7 +96,14 @@ const Home = () => {
<TwoButton
large="재도전"
small="닫기"
largeOnClick={() => { window.location.href = "/retry" }}
largeOnClick={() => {
if (isSmoked) {
setBottomSheetOpen(false);
alert("이미 금연 실패 버튼을 눌렀습니다.");
return;
}
window.location.href = "/retry";
}}
smallOnClick={() => setBottomSheetOpen(false)} />
</BottomSheetContent>
</BottomSheetContainer>
Expand Down

0 comments on commit cfd9839

Please sign in to comment.