feat: POP 시연 준비 — 5개 화면 + 버그 수정 + 재고검증

This commit is contained in:
SeongHyun Kim
2026-04-09 14:28:57 +09:00
parent 0d62af8c8b
commit bfac350ed4
25 changed files with 2804 additions and 284 deletions
+23 -3
View File
@@ -51,6 +51,7 @@ export interface UseCartSyncReturn {
addItem: (item: CartItem, rowKey: string) => void;
removeItem: (rowKey: string) => void;
updateItemQuantity: (rowKey: string, quantity: number, packageUnit?: string, packageEntries?: CartItem["packageEntries"]) => void;
updateItemRow: (rowKey: string, partialRow: Record<string, unknown>) => void;
isItemInCart: (rowKey: string) => boolean;
getCartItem: (rowKey: string) => CartItemWithId | undefined;
@@ -137,7 +138,7 @@ function areItemsEqual(a: CartItemWithId[], b: CartItemWithId[]): boolean {
const serialize = (items: CartItemWithId[]) =>
items
.map((item) => `${item.rowKey}:${item.quantity}:${item.packageUnit || ""}:${item.status}`)
.map((item) => `${item.rowKey}:${item.quantity}:${item.packageUnit || ""}:${item.status}:${JSON.stringify(item.row)}`)
.sort()
.join("|");
@@ -249,6 +250,20 @@ export function useCartSync(
[],
);
// row 객체에 임의 필드를 부분 업데이트 (예: inspectionResult)
const updateItemRow = useCallback(
(rowKey: string, partialRow: Record<string, unknown>) => {
setCartItems((prev) =>
prev.map((i) =>
i.rowKey === rowKey
? { ...i, row: { ...i.row, ...partialRow } }
: i,
),
);
},
[],
);
const isItemInCart = useCallback(
(rowKey: string) => cartItems.some((i) => i.rowKey === rowKey),
[cartItems],
@@ -272,7 +287,9 @@ export function useCartSync(
if (!c.cartId) return false;
const saved = savedMap.get(c.rowKey);
if (!saved) return false;
return c.quantity !== saved.quantity || c.packageUnit !== saved.packageUnit || c.status !== saved.status;
// row JSON 비교 (검사 결과 등 포함)
const rowChanged = JSON.stringify(c.row) !== JSON.stringify(saved.row);
return c.quantity !== saved.quantity || c.packageUnit !== saved.packageUnit || c.status !== saved.status || rowChanged;
});
return {
@@ -301,10 +318,12 @@ export function useCartSync(
if (!c.cartId) return false;
const saved = savedMap.get(c.rowKey);
if (!saved) return false;
const rowChanged = JSON.stringify(c.row) !== JSON.stringify(saved.row);
return (
c.quantity !== saved.quantity ||
c.packageUnit !== saved.packageUnit ||
c.status !== saved.status
c.status !== saved.status ||
rowChanged
);
});
@@ -354,6 +373,7 @@ export function useCartSync(
addItem,
removeItem,
updateItemQuantity,
updateItemRow,
isItemInCart,
getCartItem,
getChanges,