-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/64: 로딩/에러 처리 #68
Changes from all commits
9a0bb8c
c6014f3
9ebe451
336950a
f053593
2416c55
2cd034d
1fd8aa4
a4f4fdb
5c04330
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ import { useStockInfoContext } from "@/context/stock-info-context"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useAuth } from "@/hooks/use-auth"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useToast } from "@/store/use-toast-store"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
import LoadingSpinner from "../../loading-spiner"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import Trade from "../trade"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import TransactionTable from "../transaction-table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import EditTableBody from "./edit-table-body"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -21,7 +22,11 @@ export default function EditCancel() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
const { showToast } = useToast(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const queryClient = useQueryClient(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { data: limitOrderData } = useQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data: limitOrderData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
isLoading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
isPending, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} = useQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
queryKey: ["limitOrder"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
queryFn: () => getTrade(token, stockName), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
enabled: !!isAuthenticated && !!token, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -65,6 +70,9 @@ export default function EditCancel() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
onSettled: () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
setIsCancelTable(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
onError: (error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
showToast(error.message, "error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { mutate: modifyTradeMutate } = useMutation({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -77,6 +85,9 @@ export default function EditCancel() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
setIsEditForm(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
setSelectedOrders([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
onError: (error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
showToast(error.message, "error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const handleCancelConfirm = (orderId: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -90,6 +101,10 @@ export default function EditCancel() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isLoading || isPending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return <LoadingSpinner className="mt-230" />; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isCancelTable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -125,17 +140,19 @@ export default function EditCancel() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
<table className="w-full text-center text-14-500"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<EditTableHeader /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{limitOrderData && limitOrderData.length > 0 ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
limitOrderData.map((data) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<EditTableBody | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
key={data.OrderId} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data={data} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
isChecked={selectedOrders.includes(data.OrderId.toString())} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
toggleSelection={toggleOrderSelection} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
[...limitOrderData] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.sort((a, b) => b.OrderId - a.OrderId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.map((data) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<EditTableBody | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
key={data.OrderId} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data={data} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
isChecked={selectedOrders.includes(data.OrderId.toString())} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
toggleSelection={toggleOrderSelection} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+143
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 성능 최적화가 필요합니다. 데이터 정렬 로직이 렌더링마다 실행되고 있습니다. useMemo를 사용하여 최적화하는 것이 좋겠습니다. + const sortedLimitOrderData = useMemo(
+ () =>
+ limitOrderData
+ ? [...limitOrderData].sort((a, b) => b.OrderId - a.OrderId)
+ : [],
+ [limitOrderData]
+ );
- [...limitOrderData]
- .sort((a, b) => b.OrderId - a.OrderId)
- .map((data) => (
+ sortedLimitOrderData.map((data) => ( 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<tr> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<td colSpan={5} className="py-20 text-center text-gray-500"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<td colSpan={5} className="py-20 text-center text-16-500"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
src="/images/green-wallet.png" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
width={150} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -149,18 +166,20 @@ export default function EditCancel() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</table> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div className="mt-20 text-center"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
variant="red" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
className="mr-10 w-120 bg-[#1DA65A] hover:bg-[#1DA65A]/95" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
onClick={handleEdit} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
정정 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Button variant="red" className="w-120" onClick={handleCancel}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
취소 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{limitOrderData && limitOrderData.length > 0 && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div className="mt-20 text-center"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
variant="red" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
className="mr-10 w-120 text-black bg-[#0FED78] hover:bg-[#0FED78]/95" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
onClick={handleEdit} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
정정 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+171
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 버튼 스타일링에 일관성이 필요합니다.
다음과 같이 수정하는 것을 추천드립니다: - <Button
- variant="red"
- className="mr-10 w-120 text-black bg-[#0FED78] hover:bg-[#0FED78]/95"
- onClick={handleEdit}
- >
+ <Button
+ variant="primary"
+ className="mr-10 w-120"
+ onClick={handleEdit}
+ >
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Button variant="red" className="w-120" onClick={handleCancel}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
취소 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 메시지 처리 방식 개선이 필요합니다.
현재 에러 메시지를 직접 표시하고 있는데, 사용자 친화적인 에러 메시지로 변환하는 것이 좋겠습니다.
Also applies to: 88-90