Skip to content

Commit

Permalink
Feat : 메인 & 정보거래소 api연결
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeonsu00-12 committed Sep 11, 2024
2 parents b4a0342 + c5f0413 commit fdd9374
Show file tree
Hide file tree
Showing 47 changed files with 1,358 additions and 369 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="kr">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/SkerrImg.png" />
Expand Down
33 changes: 22 additions & 11 deletions src/Component/Calculator/calculator.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";
import Dropdown from "../Dropdown/Dropdown";
import Button from "../Button/button";
import Img from "../../img/calcul.png";
import Img from "../../img/SkerrImg.png";
import { Colors } from "../../Styles/Colors";
import { useState } from "react";
import { CalculResultProps } from "../../constants/interface";
Expand Down Expand Up @@ -120,7 +120,7 @@ const Calculator = () => {
const [selectedMonth, setSelectedMonth] = useState("01");
const [selectedDay, setSelectedDay] = useState("01");
const [result, setResult] = useState<CalculResultProps | null>(null);
const [error, setError] = useState("");
const [errorMsg, setErrorMsg] = useState("");

const location = useLocation();
const code = location.pathname.split("/")[2];
Expand All @@ -133,20 +133,27 @@ const Calculator = () => {
}&price=${price}`
)
.then((res) => {
const data = res.data;
setResult(data);
setError("해당 주식이 상장되지 않은 날짜입니다.");
if (res.status === 200) {
const data = res.data;
setResult(data);
}
})
.catch((error) => {
nav("/error");
if (error.response && error.response.data.status === 400) {
const message = error.response.data.message;
setErrorMsg(message);
setIsValid(false);
} else {
nav("/error");
}
});
};

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;

if (value.includes("-")) {
setError("음수 값은 입력 불가합니다");
setErrorMsg("음수 값은 입력 불가합니다");
setIsValid(false);
return;
}
Expand All @@ -157,10 +164,10 @@ const Calculator = () => {
setIsValid(true);
}
if (value === "" || parseInt(value) === 0) {
setError("금액을 입력해주세요");
setErrorMsg("금액을 입력해주세요");
setIsValid(false);
} else if (isNaN(Number(value))) {
setError("숫자를 입력해주세요");
setErrorMsg("숫자를 입력해주세요");
setIsValid(false);
}
};
Expand Down Expand Up @@ -216,7 +223,11 @@ const Calculator = () => {
) : (
<Container>
<TitleContainer>
<img src={Img} alt="앵무새가 컴퓨터 보는 이미지" />
<img
src={Img}
alt="앵무새가 컴퓨터 보는 이미지"
style={{ width: "45px", height: "30px" }}
/>
<span style={{ fontSize: "20px" }}>
만약 <User>{userName}</User>님이 이 때 샀다면?
</span>
Expand All @@ -237,7 +248,7 @@ const Calculator = () => {
placeholder="금액"
size="small"
colorType="strokeType"
errorMessage={error}
errorMessage={errorMsg}
value={price}
onChange={handleInputChange}
isValid={isValid}
Expand Down
Loading

0 comments on commit fdd9374

Please sign in to comment.