From 7b74dce3ad38b6ea38816080b730d6178b45ec92 Mon Sep 17 00:00:00 2001 From: dongree Date: Tue, 3 Dec 2024 23:53:52 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=94=A7=20fix:=20=EB=A7=A4=EC=88=98,?= =?UTF-8?q?=20=EB=A7=A4=EB=8F=84=20initial=20count=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20count=200=20=EC=9D=BC=EB=95=8C=20=EB=A7=A4=EC=88=98/?= =?UTF-8?q?=EB=A7=A4=EB=8F=84=20=EB=B2=84=ED=8A=BC=20=EB=B9=84=ED=99=9C?= =?UTF-8?q?=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StocksDetail/TradeSection/BuySection.tsx | 14 +++++++------- .../StocksDetail/TradeSection/SellSection.tsx | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/FE/src/components/StocksDetail/TradeSection/BuySection.tsx b/FE/src/components/StocksDetail/TradeSection/BuySection.tsx index ba17325..7819307 100644 --- a/FE/src/components/StocksDetail/TradeSection/BuySection.tsx +++ b/FE/src/components/StocksDetail/TradeSection/BuySection.tsx @@ -38,7 +38,7 @@ export default function BuySection({ code, detailInfo }: BuySectionProps) { const { isOpen, toggleModal } = useTradeAlertModalStore(); - const [count, setCount] = useState(0); + const [count, setCount] = useState(1); const [upperLimitFlag, setUpperLimitFlag] = useState(false); const [lowerLimitFlag, setLowerLimitFlag] = useState(false); @@ -110,14 +110,14 @@ export default function BuySection({ code, detailInfo }: BuySectionProps) { <>
-
+

매수 가격

{lowerLimitFlag && ( @@ -130,13 +130,13 @@ export default function BuySection({ code, detailInfo }: BuySectionProps) { 이 주식의 최대 가격은 {(+stck_mxpr).toLocaleString()}입니다.
)} -
+

수량

@@ -155,7 +155,7 @@ export default function BuySection({ code, detailInfo }: BuySectionProps) {
-
+
{lackAssetFlag && (

잔액이 부족해요!

)} @@ -164,7 +164,7 @@ export default function BuySection({ code, detailInfo }: BuySectionProps) { className={ 'rounded-lg bg-juga-red-60 py-2 text-white disabled:bg-juga-grayscale-100' } - disabled={!isLogin} + disabled={!isLogin || count === 0} > 매수하기 diff --git a/FE/src/components/StocksDetail/TradeSection/SellSection.tsx b/FE/src/components/StocksDetail/TradeSection/SellSection.tsx index aa1f674..45d8bf0 100644 --- a/FE/src/components/StocksDetail/TradeSection/SellSection.tsx +++ b/FE/src/components/StocksDetail/TradeSection/SellSection.tsx @@ -204,7 +204,7 @@ export default function SellSection({ code, detailInfo }: SellSectionProps) { className={ 'rounded-lg bg-juga-blue-50 py-2 text-white disabled:bg-juga-grayscale-100' } - disabled={!isLogin} + disabled={!isLogin || count === 0} > 매도하기 From f831627863ce1a907058b91400aa0c354c33bb34 Mon Sep 17 00:00:00 2001 From: dongree Date: Tue, 3 Dec 2024 23:56:44 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=94=A7=20fix:=20=ED=8F=89=EA=B7=A0=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=20=EB=82=B4=EB=A6=BC=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/Mypage/MyStocksList.tsx | 2 +- FE/src/components/StocksDetail/TradeSection/SellSection.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FE/src/components/Mypage/MyStocksList.tsx b/FE/src/components/Mypage/MyStocksList.tsx index 8b83dc9..1061edf 100644 --- a/FE/src/components/Mypage/MyStocksList.tsx +++ b/FE/src/components/Mypage/MyStocksList.tsx @@ -44,7 +44,7 @@ export default function MyStocksList({ stocks }: MyStocksListProps) { {(+stck_prpr).toLocaleString()}원

- {avg_price.toLocaleString()}원 + {Math.floor(avg_price).toLocaleString()}원

error

; const quantity = data.quantity; - const avg_price = data.avg_price; + const avg_price = Math.floor(data.avg_price); const pl = (+currPrice - avg_price) * count; const totalPrice = +currPrice * count; From e79ef9a2a91d27795de792c9ff69270514f559d8 Mon Sep 17 00:00:00 2001 From: dongree Date: Tue, 3 Dec 2024 23:58:40 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20chore:=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=ED=8C=8C=EC=9D=BC=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/FallbackUI.tsx | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 FE/src/components/FallbackUI.tsx diff --git a/FE/src/components/FallbackUI.tsx b/FE/src/components/FallbackUI.tsx deleted file mode 100644 index 72031aa..0000000 --- a/FE/src/components/FallbackUI.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { FallbackProps } from 'react-error-boundary'; - -export default function FallbackUI({ - error, - resetErrorBoundary, -}: FallbackProps) { - return ( -
-

Something went wrong:

-
{error.message}
- -
- ); -} From 4fe36f6434e51dc305fa9b9e26612c4d8b9c7cfe Mon Sep 17 00:00:00 2001 From: dongree Date: Wed, 4 Dec 2024 00:03:32 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=94=A7=20fix:=20checkAuth=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EB=90=9C=20reponse=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/Header.tsx | 9 ++++++--- FE/src/service/auth.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/FE/src/components/Header.tsx b/FE/src/components/Header.tsx index b958950..8c30a13 100644 --- a/FE/src/components/Header.tsx +++ b/FE/src/components/Header.tsx @@ -19,9 +19,12 @@ export default function Header() { useEffect(() => { const check = async () => { - const res = await checkAuth(); - if (res.ok) setIsLogin(true); - else setIsLogin(false); + try { + const res = await checkAuth(); + setIsLogin(res.isLogin); + } catch (error) { + console.log(error); + } }; check(); diff --git a/FE/src/service/auth.ts b/FE/src/service/auth.ts index fc0bade..fc8ad4c 100644 --- a/FE/src/service/auth.ts +++ b/FE/src/service/auth.ts @@ -14,7 +14,7 @@ export async function login( }).then((res) => res.json()); } -export async function checkAuth() { +export async function checkAuth(): Promise<{ isLogin: boolean }> { const url = import.meta.env.PROD ? `${import.meta.env.VITE_API_URL}/auth/check` : '/api/auth/check'; @@ -22,7 +22,7 @@ export async function checkAuth() { return fetch(url, { credentials: 'include', headers: { 'Content-Type': 'application/json' }, - }); + }).then((res) => res.json()); } export async function logout() { From 48c5f73bd37ace9c7f10f10c81a70a0007e21827 Mon Sep 17 00:00:00 2001 From: dongree Date: Wed, 4 Dec 2024 00:05:49 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=94=A7=20fix:=20header=20z-index=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/Header.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FE/src/components/Header.tsx b/FE/src/components/Header.tsx index 8c30a13..eaf4dd8 100644 --- a/FE/src/components/Header.tsx +++ b/FE/src/components/Header.tsx @@ -45,7 +45,7 @@ export default function Header() { }; return ( -
+
From f7596e39c65ea4e60f074c8728e375a9f13dece3 Mon Sep 17 00:00:00 2001 From: dongree Date: Wed, 4 Dec 2024 00:08:51 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9E=95=20add:=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A3=BC=EB=AC=B8=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=ED=98=84=ED=99=A9=20list=20=ED=81=B4=EB=A6=AD?= =?UTF-8?q?=EC=8B=9C=20=ED=95=B4=EB=8B=B9=20=EC=A3=BC=EC=8B=9D=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=93=A4=EC=96=B4?= =?UTF-8?q?=EA=B0=88=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/Mypage/Order.tsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/FE/src/components/Mypage/Order.tsx b/FE/src/components/Mypage/Order.tsx index df228bb..ec77c23 100644 --- a/FE/src/components/Mypage/Order.tsx +++ b/FE/src/components/Mypage/Order.tsx @@ -2,6 +2,7 @@ import useOrders from 'hooks/useOrder'; import useOrderCancelAlertModalStore from 'store/useOrderCancleAlertModalStore'; import CancelAlertModal from './CancelAlertModal.tsx'; import { formatTimestamp } from 'utils/format'; +import { useNavigate } from 'react-router-dom'; export default function Order() { const { orderQuery, removeOrder } = useOrders(); @@ -9,10 +10,16 @@ export default function Order() { const { data } = orderQuery; const { isOpen, open } = useOrderCancelAlertModalStore(); + const navigation = useNavigate(); + + const handleClick = (code: string) => { + navigation(`/stocks/${code}`); + }; + return (
-
-

종목

+
+

종목

요청 유형

수량

요청 가격

@@ -20,7 +27,7 @@ export default function Order() {

-
    +
      {data?.map((order) => { const { id, @@ -33,8 +40,12 @@ export default function Order() { } = order; return ( -
    • -
      +
    • handleClick(stock_code)} + > +

      {stock_name}

      {stock_code}

      @@ -47,15 +58,15 @@ export default function Order() { > {trade_type === 'BUY' ? '매수' : '매도'}

      -

      {amount}

      +

      {amount}

      {price.toLocaleString()}원

      -

      +

      {formatTimestamp(created_at)}

      From 8ccf20eb81f2fe27b19b60433ceb0f7dee48f6c2 Mon Sep 17 00:00:00 2001 From: dongree Date: Wed, 4 Dec 2024 00:22:11 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A6=90=EA=B2=A8?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0=20=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20unbookmark=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/Mypage/BookMark.tsx | 36 +++++++++++++++------------ FE/src/hooks/useBookmark.ts | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 FE/src/hooks/useBookmark.ts diff --git a/FE/src/components/Mypage/BookMark.tsx b/FE/src/components/Mypage/BookMark.tsx index 25218a9..8439eb7 100644 --- a/FE/src/components/Mypage/BookMark.tsx +++ b/FE/src/components/Mypage/BookMark.tsx @@ -1,6 +1,6 @@ -import { useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; -import { getBookmarkedStocks } from 'service/bookmark'; +import { HeartIcon } from '@heroicons/react/16/solid'; +import useBookmark from 'hooks/useBookmark'; export default function BookMark() { const navigation = useNavigate(); @@ -9,24 +9,20 @@ export default function BookMark() { navigation(`/stocks/${code}`); }; - const { data } = useQuery( - ['bookmark', 'stock'], - () => getBookmarkedStocks(), - { - staleTime: 1000, - suspense: true, - }, - ); + const { bookmarkQuery, unlike } = useBookmark(); + + const { data } = bookmarkQuery; return (

      -
      -

      종목

      +
      +

      종목

      현재가

      등락률

      +

      -
        +
          {data?.map((stock) => { const { code, name, stck_prpr, prdy_ctrt, prdy_vrss_sign } = stock; @@ -34,13 +30,16 @@ export default function BookMark() {
        • handleClick(code)} + onClick={(e) => { + if ((e.target as HTMLElement).closest('button')) return; + handleClick(code); + }} > -
          +

          {name}

          {code}

          -

          +

          {(+stck_prpr).toLocaleString()}원

          +

          + +

        • ); })} diff --git a/FE/src/hooks/useBookmark.ts b/FE/src/hooks/useBookmark.ts new file mode 100644 index 0000000..745451e --- /dev/null +++ b/FE/src/hooks/useBookmark.ts @@ -0,0 +1,25 @@ +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import { bookmark, getBookmarkedStocks, unbookmark } from 'service/bookmark'; + +export default function useBookmark() { + const queryClient = useQueryClient(); + + const bookmarkQuery = useQuery( + ['bookmark', 'stock'], + () => getBookmarkedStocks(), + { + staleTime: 1000, + suspense: true, + }, + ); + + const like = useMutation((code: string) => bookmark(code), { + onSuccess: () => queryClient.invalidateQueries(['bookmark', 'stock']), + }); + + const unlike = useMutation((code: string) => unbookmark(code), { + onSuccess: () => queryClient.invalidateQueries(['bookmark', 'stock']), + }); + + return { bookmarkQuery, like, unlike }; +}