From d8271dd502feb105106149fd1902c1032bad9a4f Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Wed, 28 Jan 2026 09:14:02 +0530 Subject: [PATCH] enh --- apps/admin-ui/app/(drawer)/orders/index.tsx | 3 +- .../app/(drawer)/prices-overview/index.tsx | 55 +++++++++++++++---- apps/backend/src/trpc/admin-apis/order.ts | 1 + .../app/(drawer)/(tabs)/home/index.tsx | 23 ++++++-- apps/user-ui/components/SlotSpecificView.tsx | 4 +- apps/user-ui/components/cart-page.tsx | 9 ++- apps/user-ui/hooks/cart-query-hooks.tsx | 4 ++ 7 files changed, 82 insertions(+), 17 deletions(-) diff --git a/apps/admin-ui/app/(drawer)/orders/index.tsx b/apps/admin-ui/app/(drawer)/orders/index.tsx index a33a916..2f82762 100644 --- a/apps/admin-ui/app/(drawer)/orders/index.tsx +++ b/apps/admin-ui/app/(drawer)/orders/index.tsx @@ -66,6 +66,7 @@ interface OrderType { unit: string; isPackaged?: boolean; isPackageVerified?: boolean; + productSize: number; }[]; createdAt: string; deliveryTime: string | null; @@ -437,7 +438,7 @@ const OrderItem = ({ order, refetch }: { order: OrderType; refetch: () => void } - {item.quantity} {item.unit} + {item.quantity * item.productSize } {item.unit} {item.name.length > 30 ? `${item.name.substring(0, 30)}...` : item.name} diff --git a/apps/admin-ui/app/(drawer)/prices-overview/index.tsx b/apps/admin-ui/app/(drawer)/prices-overview/index.tsx index 2c3ec88..091a8bb 100644 --- a/apps/admin-ui/app/(drawer)/prices-overview/index.tsx +++ b/apps/admin-ui/app/(drawer)/prices-overview/index.tsx @@ -41,6 +41,7 @@ const ProductItemComponent: React.FC = ({ const displayPrice = change.price !== undefined ? change.price : product.price; const displayMarketPrice = change.marketPrice !== undefined ? change.marketPrice : product.marketPrice; const displayFlashPrice = change.flashPrice !== undefined ? change.flashPrice : product.flashPrice; + const displayProductQuantity = change.productQuantity !== undefined ? change.productQuantity : product.productQuantity; return ( @@ -67,7 +68,7 @@ const ProductItemComponent: React.FC = ({ resizeMode="cover" /> - {/* Product name and Flash Checkbox */} +{/* Product name and Flash Checkbox */} {product.name.length > 25 ? product.name.substring(0, 25) + '...' : product.name} @@ -92,12 +93,12 @@ const ProductItemComponent: React.FC = ({ - {/* Second row: Prices */} +{/* Prices and Product Size Row */} {/* Our Price */} - + Our Price - + ₹{displayPrice} openEditDialog(product)} style={tw`ml-1`}> @@ -106,9 +107,9 @@ const ProductItemComponent: React.FC = ({ {/* Market Price */} - + Market Price - + {displayMarketPrice ? `₹${displayMarketPrice}` : "N/A"} openEditDialog(product)} style={tw`ml-1`}> @@ -117,15 +118,26 @@ const ProductItemComponent: React.FC = ({ {/* Flash Price */} - + Flash Price - + {displayFlashPrice ? `₹${displayFlashPrice}` : "N/A"} openEditDialog(product)} style={tw`ml-1`}> + + {/* Product Size */} + + Size + + {displayProductQuantity ? `${displayProductQuantity}${product.unit.shortNotation || ''}` : "N/A"} + openEditDialog(product)} style={tw`ml-1`}> + + + + ); @@ -135,6 +147,7 @@ interface PendingChange { price?: number; marketPrice?: number | null; flashPrice?: number | null; + productQuantity?: number | null; isFlashAvailable?: boolean; } @@ -144,6 +157,7 @@ interface EditDialogState { tempPrice: string; tempMarketPrice: string; tempFlashPrice: string; + tempProductQuantity: string; } export default function PricesOverview() { @@ -156,6 +170,7 @@ export default function PricesOverview() { tempPrice: "", tempMarketPrice: "", tempFlashPrice: "", + tempProductQuantity: "", }); const [showMenu, setShowMenu] = useState(false); @@ -211,6 +226,7 @@ export default function PricesOverview() { tempPrice: (change.price ?? product.price)?.toString() || "", tempMarketPrice: (change.marketPrice ?? product.marketPrice)?.toString() || "", tempFlashPrice: (change.flashPrice ?? product.flashPrice)?.toString() || "", + tempProductQuantity: (change.productQuantity ?? product.productQuantity)?.toString() || "", }); }; @@ -219,6 +235,7 @@ export default function PricesOverview() { const price = parseFloat(editDialog.tempPrice); const marketPrice = editDialog.tempMarketPrice ? parseFloat(editDialog.tempMarketPrice) : null; const flashPrice = editDialog.tempFlashPrice ? parseFloat(editDialog.tempFlashPrice) : null; + const productQuantity = editDialog.tempProductQuantity ? parseFloat(editDialog.tempProductQuantity) : null; if (isNaN(price) || price <= 0) { Alert.alert("Error", "Please enter a valid price"); @@ -235,16 +252,22 @@ export default function PricesOverview() { return; } + if (editDialog.tempProductQuantity && (isNaN(productQuantity!) || productQuantity! <= 0)) { + Alert.alert("Error", "Please enter a valid product size"); + return; + } + setPendingChanges(prev => ({ ...prev, [editDialog.product.id]: { price: price !== editDialog.product.price ? price : undefined, marketPrice: marketPrice !== editDialog.product.marketPrice ? marketPrice : undefined, flashPrice: flashPrice !== editDialog.product.flashPrice ? flashPrice : undefined, + productQuantity: productQuantity !== editDialog.product.productQuantity ? productQuantity : undefined, }, })); - setEditDialog({ open: false, product: null, tempPrice: "", tempMarketPrice: "", tempFlashPrice: "" }); + setEditDialog({ open: false, product: null, tempPrice: "", tempMarketPrice: "", tempFlashPrice: "", tempProductQuantity: "" }); }; // Handle save all changes @@ -254,6 +277,7 @@ export default function PricesOverview() { if (change.price !== undefined) update.price = change.price; if (change.marketPrice !== undefined) update.marketPrice = change.marketPrice; if (change.flashPrice !== undefined) update.flashPrice = change.flashPrice; + if (change.productQuantity !== undefined) update.productQuantity = change.productQuantity; if (change.isFlashAvailable !== undefined) update.isFlashAvailable = change.isFlashAvailable; return update; }); @@ -351,7 +375,7 @@ export default function PricesOverview() { )} {/* Edit Dialog */} - setEditDialog({ ...editDialog, open: false, tempFlashPrice: "" })}> + setEditDialog({ ...editDialog, open: false, tempFlashPrice: "", tempMarketPrice: "", tempPrice: "", tempProductQuantity: "" })}> {editDialog.product?.name} @@ -388,6 +412,17 @@ export default function PricesOverview() { /> + + Product Size + setEditDialog({ ...editDialog, tempProductQuantity: text })} + keyboardType="decimal-pad" + placeholder="Enter product size" + /> + + { - const slot = getQuickestSlot(product.id); - return slot !== null && slot !== undefined && !product.isOutOfStock; - }); + // const initialBatch = initialBatchRaw.filter(product => { + // const slot = getQuickestSlot(product.id); + // return !product.isOutOfStock; + // }); + + const initialBatch = initialBatchRaw.sort((a, b) => { + const slotA = getQuickestSlot(a.id); + const slotB = getQuickestSlot(b.id); + + if (slotA && !slotB) return -1; + if (!slotA && slotB) return 1; + + if(a.isOutOfStock && !b.isOutOfStock) return 1; + if(!a.isOutOfStock && b.isOutOfStock) return -1; + return 0; + }) setDisplayedProducts(initialBatch); setHasMore(products.length > 10); @@ -593,6 +605,9 @@ export default function Dashboard() { /> )} + initialNumToRender={4} + maxToRenderPerBatch={4} + windowSize={4} // onEndReached={() => { // if (!isLoadingMore && hasMore) { // loadMoreProducts(); diff --git a/apps/user-ui/components/SlotSpecificView.tsx b/apps/user-ui/components/SlotSpecificView.tsx index a5f7573..03639ed 100644 --- a/apps/user-ui/components/SlotSpecificView.tsx +++ b/apps/user-ui/components/SlotSpecificView.tsx @@ -350,10 +350,12 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU const productsQuery = trpc.user.product.getAllProductsSummary.useQuery(); - const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "flash") || {}; + const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "regular") || {}; const handleAddToCart = (productId: number) => { setIsLoadingDialogOpen(true); + // console.log({productId}) + addToCart(productId, 1, slotId || 0, () => setIsLoadingDialogOpen(false)); }; diff --git a/apps/user-ui/components/cart-page.tsx b/apps/user-ui/components/cart-page.tsx index 513a142..1160e9d 100644 --- a/apps/user-ui/components/cart-page.tsx +++ b/apps/user-ui/components/cart-page.tsx @@ -305,11 +305,16 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) { // Auto-select delivery slots for each cart item useEffect(() => { + const cartSlotIds = cartData?.items.reduce((acc,item) => { + acc[item.id] = item.slotId; + return acc; + }, {} as Record); if (cartItems.length > 0) { const newSelectedSlots = { ...selectedSlots }; cartItems.forEach(item => { - const existingSlotId = selectedSlots[item.id]; + // const existingSlotId = selectedSlots[item.id]; + const existingSlotId = cartSlotIds ? cartSlotIds[item.id] : undefined; if (isFlashDelivery) { newSelectedSlots[item.id] = 0; @@ -325,6 +330,8 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) { ); if (upcomingSlots.length > 0) { + console.log({upcomingSlots, existingSlotId, cartSlotIds}) + if (existingSlotId) { const slotStillValid = upcomingSlots.some(slot => slot.id === existingSlotId); if (slotStillValid) { diff --git a/apps/user-ui/hooks/cart-query-hooks.tsx b/apps/user-ui/hooks/cart-query-hooks.tsx index 5058511..b87d827 100644 --- a/apps/user-ui/hooks/cart-query-hooks.tsx +++ b/apps/user-ui/hooks/cart-query-hooks.tsx @@ -91,6 +91,8 @@ const addToLocalCart = async (productId: number, quantity: number, slotId?: numb items.push(cartItem); } + console.log({items}) + await saveLocalCart(items, cartType); return items; }; @@ -301,6 +303,8 @@ export function useAddToCart(options?: { const addToCart = (productId: number, quantity = 1, slotId?: number, onSettled?: (data: any, error: any) => void) => { + // console.log({productId, quantity, slotId}) + if (slotId == null) { throw new Error('slotId is required for adding to cart'); }