-
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
Sp1/#566 cart page api #576
Conversation
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.
ํ ์๊ณ ํ์
จ์ต๋๋น LGTM
ํธ๋ฌ๋ธ์ํ
์ ์ ์ด์ฃผ์ ๋ด์ฉ์ ์ ๋ ๋ ์๊ฐํด๋ณผ๊ฒ์ฉ
<> | ||
<EmptyView /> | ||
</> |
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.
์๊ฑฐ ๋นํ๊ทธ ์์ด๋ ๋์ง ์์๊น์??
const debouncedFetchData = useCallback( | ||
debounce((newQuantity) => fetchData(newQuantity), 300), | ||
[], | ||
); |
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.
์ค... ๊ตฟ!
window.location.reload(); | ||
}) | ||
.catch((err) => { | ||
console.log(err); |
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.
์ฝ์ ์ฝ์
setResponse(data.data); | ||
}) | ||
.catch(err => { | ||
setError(err); |
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.
์ฌ๊ธฐ๋ ์๋ฌํ์ด์ง๋ก ์ด๋ํ๊ฒ ํด์ค์ผํ์ง ์๋์ฉ?!
setError(err); | |
setError(err); | |
navigate('/error') |
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.
ํธ๋ฌ๋ธ ์ํ
๊ด๋ จ ์๊ฒฌ์ ํด๋น ๋ถ๋ถ์ ๋ฆฌ๋ทฐ ๋จ๊ฒจ๋์์ต๋๋ค
์๊ณ ํ์
จ์ต๋๋ค ! ๐ฏ
const { response, error, loading } = useGetOrdersheet( | ||
state ? state : ({ stickerId: 0, count: 0 } as OrderSheetRequest), | ||
); |
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.
state๋ฅผ ๋๊ฒจ์ฃผ์ง ์๊ณ ๋ณ๋ ์ธ์ ์์ด useGetOrdersheet์ ํธ์ถํ๋ฉด ์๋ฌ๋๋๊ฑธ๊น์? ์ ๋ ์ฒ์์ ์ด๋ ๊ฒ ๊ฐ๊ฐ 0์ผ๋ก ์ง์ ํด์ค ํ์ ์์ด ์์ state ์๋๊ฒจ์ฃผ๋ฉด ์์์ undefined ์ฒ๋ฆฌ ๋ ๊ฑฐ๋ผ๊ณ ์๊ฐํ๋๋ฐ !
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.
์กฐ๊ฑด ํ๋ฒ ์์ ํด๋ณผ๊ฒ์~
const url = | ||
stickerId && count | ||
? `/order/ordersheet?stickerId=${stickerId}&count=${count}` | ||
: '/order/ordersheet'; | ||
|
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.
๐
{orderSheetStickersRes.map((item) => { | ||
return <ProductInfo key={item.name} orderSheetSticker={item} />; | ||
})} |
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.
์ ์ด๋ถ๋ถ์ ๋ฐ์ ์ํ๋ค์ ๊ฐ์ฌํฉ๋๋ค!
const DeleteCartModal = ({ setModalOn, id }: DeleteCartModalProps) => { | ||
const navigate = useNavigate(); | ||
|
||
const handleClickDeleteModal = async () => { | ||
await api | ||
.delete(`/cart/${id}`) | ||
.then(() => { | ||
setModalOn(false); | ||
window.location.reload(); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
navigate('/error'); | ||
}); | ||
}; |
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.
ํธ๋ฌ๋ธ ์ํ
๊ด๋ จํด์ ์ฒจ์ธํ์๋ฉด
๊ตฌํ ์์ ๋ณด๋๊น ์ฌ์ฉ์ ๊ฒฝํ์ด ๋ง์ด ๋จ์ด์ง๊ฒ ๋๋ ๊ฒ ๊ฐ์์ reload๋ ์์ฐ๋๊ฒ ๋ง๋ ๊ฒ ๊ฐ๊ณ ๊ทธ๋์ ์ผ๋จ state๋ก ๊ด๋ฆฌํ๋๊ฒ ๊ด์ฐฎ์ ๋ณด์ด๋ ๊ฒ ๊ฐ์ต๋๋ค (๋ฌผ๋ก ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์ผ๋ฉด ์ข๊ฒ ์ง๋ง)
์ด์ฐจํผ ์๋๋ CartItem์์ state๋ก ๊ด๋ฆฌํ๊ณ ์์ผ๋๊น ์ฅ๋ฐ๊ตฌ๋ ์์ดํ
์ ๋ณด state๋ฅผ ๊ฐ์ฒด๋ฐฐ์ด๋ก ๋ง๋ค์ด์ ํ state๋ก ์๋ ์กฐ์ ๋ฐ ์ญ์ ๋ค ๊ด๋ฆฌํด์ฃผ๋๊ฑด ์ด๋จ๊น์?
quantity๋ item list ๋ฐ๋ก ๊ด๋ฆฌํ์ง ๋ง๊ณ ์์ดํ
id๋ quantity ํ๋กํผํฐ ๋๊ฐ๋ง ๊ฐ์ ธ๊ฐ์ ์ญ์ ํต์ ์ฑ๊ณต ์์ quantity 0์ผ๋ก ๋ง๋ค๊ณ 0์ธ ์ ๋ค์ ๋ ๋๋ง ์ํ๋ ์์ผ๋ก ํด์ฃผ๋ ๋ฐฉ์์ด ์ผ๋จ ๋น์ฅ ๋ ์ค๋ฅด๋ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ๋ฐฉ๋ฒ? ์ธ ๊ฒ ๊ฐ์ต๋๋ค!
(์ด์ฐจํผ ์ฅ๋ฐ๊ตฌ๋ ํ์ด์ง ๋ค์ด์ฌ ๋๋ง๋ค ์๋ก ์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ๋ถ๋ฌ์์ state ์ด๊ธฐํ ์์ผ์ค ํ
๋๊น ์ญ์ ํ ์์ดํ
์ด quantity 0 ์ํ๋ก ์ ๋ณด ๋จ์์๋๊ฑด ๋ณ๋ก ์ ๊ฒฝ์ฐ์ง ์์๋ ๋ ๊ฒ ๊ฐ์์!)
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.
SP2๋ก ๊ฐ์ ธ๊ฐ๊ฒ ์ต๋๋ค. ํน์ ๋ฉด์ ๋๋๊ณ ,,,
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.
์๊ณ ํ์ จ์ด๋๋ค!
id: number; | ||
mainImageUrl: string; | ||
name: string; | ||
price: number; | ||
originalPrice: number; | ||
count: number; | ||
handleClickQuantityButton: (price: number) => void; | ||
}) => { |
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.
interface๋ก ๋นผ์ฃผ๋๊ฒ ๊ฐ๋ ์ฑ์ด ์ข์๊ฒ ๊ฐ์์ฉ
const debouncedFetchData = useCallback( | ||
debounce((newQuantity) => fetchData(newQuantity), 300), | ||
[], |
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.
์ค ์ข์ ์ฝ๋ ๋ฐฐ์๊ฐ๋๋ค
}: { | ||
items: CartItemProps[]; | ||
handleClickQuantityButton: (price: number) => void; | ||
}) => { |
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.
์ฌ๊ธฐ๋ ๋ณต์กํ props type๋ค์ interface๋ก ๋ฐ๋ก ๋นผ์ฃผ๋ฉด ๋ ๊ฐ๋ ์ฑ์ด ์ข์๊ฒ ๊ฐ์ต๋๋น
export interface CartItemProps { | ||
stickerId: number; | ||
id: number; | ||
mainImageUrl: string; | ||
name: string; | ||
price: number; | ||
discountPrice: number; | ||
count: number; | ||
} |
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.
์๊ฑฐ ์์ props๋ค์ type์ผ๋ก๋ ์ฐ์ด๋๊ฒ ๊ฐ์๋ฐ type ํ์ผ์ ๋นผ๋๊ณ extends ํด์ ์ฐ๊ฑฐ๋ ํ๋ฉด ์ข์๊ฒ ๊ฐ์ต๋๋ค!
setModalOn(false); | ||
window.location.reload(); |
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.
์ ๋ ์นํฌ ์๊ฒฌ์ ๋์ํฉ๋๋ค
reload๋ณด๋ค๋ state๋ก ๊ด๋ฆฌํ๋๊ฒ ์ข์ ๋ณด์ฌ์!
๐ฅ Related Issues
resolved #566
๐ ์์ ๋ด์ฉ
โ PR Point
ํด๋น ๋ถ๋ถ์์ ์๋์ ์ฆ๊ฐ ์ํฌ ์ debounce๋ฅผ ์ด์ฉํ์ฌ ์ผ์ ์๊ฐ ์ดํ ์ ๋ ฅ์ด ์์ ์์๋ง ์๋ฒ์ API ํต์ ์ ์งํํ๋๋ก ํ์ต๋๋ค. throttle, debounce ์ฐธ๊ณ ํ์ธ์.
์ฅ๋ฐ๊ตฌ๋์์ ๋์ด์ฌ ๋๋ state๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ด๋ฐ ์์ผ๋ก ์ฒ๋ฆฌํ์ต๋๋ค.
๋ฐ๋ผ์ url๋ stickerId์ count ์ ๋ฌด๋ก ๋ค๋ฅด๊ฒ ์ง์ ํ์ต๋๋ค.
CompletePage๋ ๋ฐฐ์ด๋ก ์ํ๋๋๋ก ์์ ํ์ต๋๋ค.
๐ก Trouble Shooting
ํ์ฌ ์ฅ๋ฐ๊ตฌ๋๋ฅผ ์ญ์ ํ๊ณ ํ๋ฉด์ reloadํด์ฃผ๋ ๋ฐฉ์์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ด๊ฒ ์ฌ์ฉ์ฑ์ด ์์ข์๋ณด์ด๊ธฐ๋ ํด์ ์ฅ๋ฐ๊ตฌ๋ item๋ค์ ์ ๋ถ state๋ก ๊ด๋ฆฌํ๋๊ฒ ๋ง์์ง ๊ณ ๋ฏผ์ ๋๋ค.
ํด๋น item ์ญ์ ๋ฅผ ํด์ผ ํจ.
โ๏ธ ์คํฌ๋ฆฐ์ท / GIF / ํ๋ฉด ๋ นํ
๐ Reference