Skip to content

Commit b5e8690

Browse files
authored
Merge pull request #4 from pythonkr/fix/shop-cart-fail-on-not-initialized-cart
fix: 장바구니 컴포넌트가 렌더링되지 않을 수 있는 문제 수정
2 parents 1b8ae60 + 59afe8f commit b5e8690

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

package/pyconkr-shop/apis/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace ShopAPIRoute {
8686
* @returns 현재 장바구니 상태
8787
*/
8888
export const retrieveCart = () =>
89-
shopAPIClient.get<ShopAPISchema.Order>("v1/orders/cart/");
89+
shopAPIClient.get<ShopAPISchema.Order | ShopAPISchema.EmptyObject>("v1/orders/cart/");
9090

9191
/**
9292
* 장바구니에 상품을 추가합니다.

package/pyconkr-shop/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as R from "remeda";
22

33
namespace ShopAPISchema {
4+
export type EmptyObject = Record<string, never>;
5+
46
export type DetailedErrorSchema = {
57
code: string;
68
detail: string;

src/debug/page/shop_component/cart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const ShopCartList: React.FC<{ onPaymentCompleted?: () => void; }> = ({ o
8080
// eslint-disable-next-line react-hooks/rules-of-hooks
8181
const { data } = ShopAPIHook.useCart();
8282

83-
return data.products.length === 0
83+
return !data.hasOwnProperty('products') || data.products.length === 0
8484
? <Typography variant="body1" color="error">장바구니가 비어있어요!</Typography>
8585
: <>
8686
{data.products.map((prodRel) => <ShopCartItem key={prodRel.id} cartProdRel={prodRel} disabled={disabled} removeItemFromCartFunc={removeItemFromCart} />)}

0 commit comments

Comments
 (0)