From 0382b03ad8bdf3451c685bc0be29c7c4516285e9 Mon Sep 17 00:00:00 2001
From: shafi54 <108669266+shafi-aviz@users.noreply.github.com>
Date: Tue, 27 Jan 2026 23:53:21 +0530
Subject: [PATCH] enh
---
.../app/(drawer)/order-details/[id].tsx | 2 +-
apps/admin-ui/app/(drawer)/orders/index.tsx | 11 ----
apps/backend/src/trpc/admin-apis/order.ts | 1 +
.../app/(drawer)/(tabs)/home/index.tsx | 21 +++++---
apps/user-ui/components/cart-page.tsx | 51 ++++++++-----------
5 files changed, 35 insertions(+), 51 deletions(-)
diff --git a/apps/admin-ui/app/(drawer)/order-details/[id].tsx b/apps/admin-ui/app/(drawer)/order-details/[id].tsx
index 266365a..98abd26 100644
--- a/apps/admin-ui/app/(drawer)/order-details/[id].tsx
+++ b/apps/admin-ui/app/(drawer)/order-details/[id].tsx
@@ -428,7 +428,7 @@ export default function OrderDetails() {
{item.name}
- {item.quantity} {item.unit} × ₹{item.price}
+ {Number(item.quantity) * item.productSize} {item.unit} × ₹{item.price}
void }
}
);
};
-
- const getStatusColor = (status: string) => {
- switch (status) {
- case 'delivered': return 'bg-green-100 text-green-800';
- case 'cancelled': return 'bg-red-100 text-red-800';
- default: return 'bg-yellow-100 text-yellow-800';
- }
- };
-
- if(order.id === 162)
- console.log({order})
return (
<>
diff --git a/apps/backend/src/trpc/admin-apis/order.ts b/apps/backend/src/trpc/admin-apis/order.ts
index a41ed23..84a81ad 100644
--- a/apps/backend/src/trpc/admin-apis/order.ts
+++ b/apps/backend/src/trpc/admin-apis/order.ts
@@ -333,6 +333,7 @@ export const orderRouter = router({
id: item.id,
name: item.product.name,
quantity: item.quantity,
+ productSize: item.product.productQuantity,
price: item.price,
unit: item.product.unit?.shortNotation,
amount:
diff --git a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx
index 0deab9e..ca59fa5 100755
--- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx
+++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx
@@ -131,10 +131,8 @@ export default function Dashboard() {
const { data: essentialConsts, isLoading: isLoadingConsts, error: constsError } = useGetEssentialConsts();
- const { data: tagsData } = trpc.common.product.getDashboardTags.useQuery();
+
const { data: storesData } = trpc.user.stores.getStores.useQuery();
- const { data: defaultAddressResponse } =
- trpc.user.address.getDefaultAddress.useQuery();
const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
const products = productsData?.products || [];
@@ -192,10 +190,8 @@ export default function Dashboard() {
if (!popularItems) return [];
if (Array.isArray(popularItems)) {
- // Already an array of IDs
return popularItems.map((id: any) => parseInt(id)).filter((id: number) => !isNaN(id));
} else if (typeof popularItems === 'string') {
- // Comma-separated string
return popularItems
.split(',')
.map((id: string) => parseInt(id.trim()))
@@ -204,6 +200,15 @@ export default function Dashboard() {
return [];
})();
+ const sortedSlots = React.useMemo(() => {
+ if (!slotsData?.slots) return [];
+ return slotsData.slots.sort((a, b) => {
+ const deliveryDiff = dayjs(a.deliveryTime).diff(dayjs(b.deliveryTime));
+ if (deliveryDiff !== 0) return deliveryDiff;
+ return dayjs(a.freezeTime).diff(dayjs(b.freezeTime));
+ });
+ }, [slotsData]);
+
// Filter products to only include those whose ID exists in popularItemIds, preserving order
// Only filter when both products and essentialConsts are loaded
const popularProducts = popularItemIds
@@ -417,7 +422,7 @@ export default function Dashboard() {
{/* Upcoming Deliveries Section */}
- {slotsData?.slots && slotsData.slots.length > 0 && (
+ {sortedSlots.length > 0 && (
@@ -437,9 +442,9 @@ export default function Dashboard() {
showsHorizontalScrollIndicator={false}
contentContainerStyle={tw` pb-6`}
decelerationRate="fast"
- snapToInterval={280 + 16} // card width + margin
+ snapToInterval={280 + 16}
>
- {slotsData.slots.slice(0, 5).map((slot) => {
+ {sortedSlots.slice(0, 5).map((slot) => {
const now = dayjs();
const freezeTime = dayjs(slot.freezeTime);
const isClosingSoon =
diff --git a/apps/user-ui/components/cart-page.tsx b/apps/user-ui/components/cart-page.tsx
index 591042c..513a142 100644
--- a/apps/user-ui/components/cart-page.tsx
+++ b/apps/user-ui/components/cart-page.tsx
@@ -26,21 +26,6 @@ import { trpc } from "@/src/trpc-client";
import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
-interface CartItem {
- id: number;
- productId: number;
- quantity: number;
- product: {
- price: number;
- isOutOfStock: boolean;
- name: string;
- images: string[];
- unit?: string;
- incrementStep?: number;
- productQuantity?: number;
- } | null;
-}
-
interface CartPageProps {
isFlashDelivery?: boolean;
}
@@ -62,14 +47,14 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
// Extract product IDs from cart items
const productIds = cartData?.items.map(item => item.productId) || [];
- // Get cart slots for the products in cart
- const { data: slotsData, refetch: refetchSlots, error: slotsError } = trpc.user.cart.getCartSlots.useQuery(
- { productIds },
- {
- enabled: productIds.length > 0,
- refetchOnWindowFocus: false
- }
- );
+// Get cart slots for the products in cart
+ const { data: slotsData, refetch: refetchSlots, isLoading: isSlotsLoading } = trpc.user.cart.getCartSlots.useQuery(
+ { productIds },
+ {
+ enabled: productIds.length > 0,
+ refetchOnWindowFocus: false
+ }
+ );
const generateCouponDescription = (coupon: any): string => {
let desc = "";
@@ -324,14 +309,11 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
const newSelectedSlots = { ...selectedSlots };
cartItems.forEach(item => {
- // Skip if already has a selected slot
- if (selectedSlots[item.id]) return;
+ const existingSlotId = selectedSlots[item.id];
if (isFlashDelivery) {
- // For flash delivery, always use slot 0
newSelectedSlots[item.id] = 0;
} else {
- // For regular delivery, find earliest available slot
const productSlots = slotsData?.[item.productId];
if (!productSlots || productSlots.length === 0) return;
@@ -343,9 +325,16 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
);
if (upcomingSlots.length > 0) {
- // Select the earliest available slot for this product
- const earliestSlot = upcomingSlots[0];
- newSelectedSlots[item.id] = earliestSlot.id;
+ if (existingSlotId) {
+ const slotStillValid = upcomingSlots.some(slot => slot.id === existingSlotId);
+ if (slotStillValid) {
+ newSelectedSlots[item.id] = existingSlotId;
+ } else {
+ newSelectedSlots[item.id] = upcomingSlots[0].id;
+ }
+ } else {
+ newSelectedSlots[item.id] = upcomingSlots[0].id;
+ }
}
}
});
@@ -356,7 +345,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
- if (isLoading) {
+ if (isLoading || (isSlotsLoading && !isFlashDelivery)) {
return (
Loading cart...