Skip to content

Commit

Permalink
[Feat] 종목 검색 관련 알림 토스트 메시지 구현
Browse files Browse the repository at this point in the history
- 목록에 없는 종목 검색할 시 안내 토스트 메세지 뜨도록 구현

Issues #122
  • Loading branch information
novice1993 committed Sep 19, 2023
1 parent b59e7e9 commit b7fb08f
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions client/src/components/Headers/stockSearchComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import React, { useState } from "react";
import { useDispatch } from "react-redux";
import styled from "styled-components";
import { toast } from "react-toastify";
import { changeCompanyId } from "../../reducer/CompanyId-Reducer";
import useGetCompanyList from "../../hooks/useGetCompanyList";

Expand All @@ -9,6 +10,12 @@ const search = "검색";
const noExistCompany = "noExistCompany";
const existCompany = "existCompany";

const toastStyle = {
fontSize: "15px",
fontWeight: 350,
color: "black",
};

const StockSearchComponent: React.FC = () => {
const dispatch = useDispatch();
const { companyList } = useGetCompanyList();
Expand All @@ -21,15 +28,24 @@ const StockSearchComponent: React.FC = () => {
const handleSearchCompany = () => {
let searchResult: string = noExistCompany;

if (searchWord === "") {
return;
}

companyList.forEach((company: CompanyProps) => {
if (company.korName === searchWord) {
searchResult = existCompany ;
searchResult = existCompany;
dispatch(changeCompanyId(company.companyId));
}
});

if (searchResult === noExistCompany) {
dispatch(changeCompanyId(-1));
toast.error("존재하지 않는 종목입니다", {
style: toastStyle,
position: "top-right",
autoClose: 1500,
});
return;
}
};

Expand All @@ -42,12 +58,7 @@ const StockSearchComponent: React.FC = () => {

return (
<SearchContainer>
<StyledSearchInput
value={searchWord}
onChange={handleChangeSearchWord}
onKeyDown={handlePressEnterToSearch}
placeholder={stockSearch}
/>
<StyledSearchInput value={searchWord} onChange={handleChangeSearchWord} onKeyDown={handlePressEnterToSearch} placeholder={stockSearch} />
<StyledSearchButton onClick={handleSearchCompany}>{search}</StyledSearchButton>
</SearchContainer>
);
Expand All @@ -56,20 +67,19 @@ const StockSearchComponent: React.FC = () => {
export default StockSearchComponent;

interface CompanyProps {
companyId: number;
code: string;
korName: string;
stockAsBiResponseDto: null;
stockInfResponseDto: null;
}

companyId: number;
code: string;
korName: string;
stockAsBiResponseDto: null;
stockInfResponseDto: null;
}

// 스타일 정의

const SearchContainer = styled.div`
display: flex;
align-items: center;
flex-grow: 0.7; // 여기에 추가
flex-grow: 0.7; // 여기에 추가
`;

const StyledSearchInput = styled.input.attrs({
Expand Down

0 comments on commit b7fb08f

Please sign in to comment.