Replace entire repo content with kottgard-production-v1.1.zip (for shahikitchen-prod repo)
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
import {
|
||||
addOrderLine,
|
||||
calculateOrderItemCount,
|
||||
calculateOrderTotal,
|
||||
updateOrderLineQuantity,
|
||||
} from '../shared/order-line';
|
||||
import type { CartAction, CartState } from './entities';
|
||||
|
||||
/** Pure cart state machine — no React, no localStorage. */
|
||||
export function cartReducer(state: CartState, action: CartAction): CartState {
|
||||
switch (action.type) {
|
||||
case 'ADD_ITEM':
|
||||
return { ...state, items: addOrderLine(state.items, action.payload) };
|
||||
|
||||
case 'REMOVE_ITEM':
|
||||
return {
|
||||
...state,
|
||||
items: state.items.filter((item) => item.id !== action.payload),
|
||||
};
|
||||
|
||||
case 'UPDATE_QUANTITY':
|
||||
return {
|
||||
...state,
|
||||
items: updateOrderLineQuantity(
|
||||
state.items,
|
||||
action.payload.id,
|
||||
action.payload.quantity
|
||||
),
|
||||
};
|
||||
|
||||
case 'CLEAR_CART':
|
||||
return { ...state, items: [] };
|
||||
|
||||
case 'RESTORE_ITEMS':
|
||||
return { ...state, items: action.payload };
|
||||
|
||||
case 'TOGGLE_CART':
|
||||
return { ...state, isOpen: !state.isOpen };
|
||||
|
||||
case 'OPEN_CART':
|
||||
return { ...state, isOpen: true };
|
||||
|
||||
case 'CLOSE_CART':
|
||||
return { ...state, isOpen: false };
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export function getCartTotals(items: CartState['items']) {
|
||||
return {
|
||||
totalItems: calculateOrderItemCount(items),
|
||||
totalPrice: calculateOrderTotal(items),
|
||||
};
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { OrderLine, NewOrderLine } from '../shared/order-line';
|
||||
|
||||
export type CartItem = OrderLine;
|
||||
export type NewCartItem = NewOrderLine;
|
||||
|
||||
export interface CartState {
|
||||
items: CartItem[];
|
||||
isOpen: boolean;
|
||||
}
|
||||
|
||||
export type CartAction =
|
||||
| { type: 'ADD_ITEM'; payload: NewCartItem }
|
||||
| { type: 'REMOVE_ITEM'; payload: string }
|
||||
| { type: 'UPDATE_QUANTITY'; payload: { id: string; quantity: number } }
|
||||
| { type: 'CLEAR_CART' }
|
||||
| { type: 'TOGGLE_CART' }
|
||||
| { type: 'OPEN_CART' }
|
||||
| { type: 'CLOSE_CART' }
|
||||
| { type: 'RESTORE_ITEMS'; payload: CartItem[] };
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { CartItem } from './entities';
|
||||
|
||||
/** Port: cart persistence (implemented by infrastructure). */
|
||||
export interface CartRepository {
|
||||
load(): CartItem[];
|
||||
save(items: CartItem[]): void;
|
||||
}
|
||||
Reference in New Issue
Block a user