1
- import React , { useState } from ' react' ;
1
+ import React , { useState } from " react" ;
2
2
import { useDispatch } from "react-redux" ;
3
3
import styled from "styled-components" ;
4
+ import { toast } from "react-toastify" ;
4
5
import { changeCompanyId } from "../../reducer/CompanyId-Reducer" ;
5
6
import useGetCompanyList from "../../hooks/useGetCompanyList" ;
6
7
@@ -9,6 +10,12 @@ const search = "검색";
9
10
const noExistCompany = "noExistCompany" ;
10
11
const existCompany = "existCompany" ;
11
12
13
+ const toastStyle = {
14
+ fontSize : "15px" ,
15
+ fontWeight : 350 ,
16
+ color : "black" ,
17
+ } ;
18
+
12
19
const StockSearchComponent : React . FC = ( ) => {
13
20
const dispatch = useDispatch ( ) ;
14
21
const { companyList } = useGetCompanyList ( ) ;
@@ -21,15 +28,24 @@ const StockSearchComponent: React.FC = () => {
21
28
const handleSearchCompany = ( ) => {
22
29
let searchResult : string = noExistCompany ;
23
30
31
+ if ( searchWord === "" ) {
32
+ return ;
33
+ }
34
+
24
35
companyList . forEach ( ( company : CompanyProps ) => {
25
36
if ( company . korName === searchWord ) {
26
- searchResult = existCompany ;
37
+ searchResult = existCompany ;
27
38
dispatch ( changeCompanyId ( company . companyId ) ) ;
28
39
}
29
40
} ) ;
30
41
31
42
if ( searchResult === noExistCompany ) {
32
- dispatch ( changeCompanyId ( - 1 ) ) ;
43
+ toast . error ( "존재하지 않는 종목입니다" , {
44
+ style : toastStyle ,
45
+ position : "top-right" ,
46
+ autoClose : 1500 ,
47
+ } ) ;
48
+ return ;
33
49
}
34
50
} ;
35
51
@@ -42,12 +58,7 @@ const StockSearchComponent: React.FC = () => {
42
58
43
59
return (
44
60
< SearchContainer >
45
- < StyledSearchInput
46
- value = { searchWord }
47
- onChange = { handleChangeSearchWord }
48
- onKeyDown = { handlePressEnterToSearch }
49
- placeholder = { stockSearch }
50
- />
61
+ < StyledSearchInput value = { searchWord } onChange = { handleChangeSearchWord } onKeyDown = { handlePressEnterToSearch } placeholder = { stockSearch } />
51
62
< StyledSearchButton onClick = { handleSearchCompany } > { search } </ StyledSearchButton >
52
63
</ SearchContainer >
53
64
) ;
@@ -56,20 +67,19 @@ const StockSearchComponent: React.FC = () => {
56
67
export default StockSearchComponent ;
57
68
58
69
interface CompanyProps {
59
- companyId : number ;
60
- code : string ;
61
- korName : string ;
62
- stockAsBiResponseDto : null ;
63
- stockInfResponseDto : null ;
64
- }
65
-
70
+ companyId : number ;
71
+ code : string ;
72
+ korName : string ;
73
+ stockAsBiResponseDto : null ;
74
+ stockInfResponseDto : null ;
75
+ }
66
76
67
77
// 스타일 정의
68
78
69
79
const SearchContainer = styled . div `
70
80
display: flex;
71
81
align-items: center;
72
- flex-grow: 0.7; // 여기에 추가
82
+ flex-grow: 0.7; // 여기에 추가
73
83
` ;
74
84
75
85
const StyledSearchInput = styled . input . attrs ( {
0 commit comments