This commit is contained in:
shafi54 2026-01-27 23:53:21 +05:30
parent 419fa83b8c
commit 0382b03ad8
5 changed files with 35 additions and 51 deletions

View file

@ -428,7 +428,7 @@ export default function OrderDetails() {
{item.name} {item.name}
</MyText> </MyText>
<MyText style={tw`text-xs text-gray-500`}> <MyText style={tw`text-xs text-gray-500`}>
{item.quantity} {item.unit} × {item.price} {Number(item.quantity) * item.productSize} {item.unit} × {item.price}
</MyText> </MyText>
<View style={tw`flex-row items-center mt-2 gap-3`}> <View style={tw`flex-row items-center mt-2 gap-3`}>
<TouchableOpacity <TouchableOpacity

View file

@ -154,17 +154,6 @@ const OrderItem = ({ order, refetch }: { order: OrderType; refetch: () => 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 ( return (
<> <>

View file

@ -333,6 +333,7 @@ export const orderRouter = router({
id: item.id, id: item.id,
name: item.product.name, name: item.product.name,
quantity: item.quantity, quantity: item.quantity,
productSize: item.product.productQuantity,
price: item.price, price: item.price,
unit: item.product.unit?.shortNotation, unit: item.product.unit?.shortNotation,
amount: amount:

View file

@ -131,10 +131,8 @@ export default function Dashboard() {
const { data: essentialConsts, isLoading: isLoadingConsts, error: constsError } = useGetEssentialConsts(); 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: storesData } = trpc.user.stores.getStores.useQuery();
const { data: defaultAddressResponse } =
trpc.user.address.getDefaultAddress.useQuery();
const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery(); const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
const products = productsData?.products || []; const products = productsData?.products || [];
@ -192,10 +190,8 @@ export default function Dashboard() {
if (!popularItems) return []; if (!popularItems) return [];
if (Array.isArray(popularItems)) { if (Array.isArray(popularItems)) {
// Already an array of IDs
return popularItems.map((id: any) => parseInt(id)).filter((id: number) => !isNaN(id)); return popularItems.map((id: any) => parseInt(id)).filter((id: number) => !isNaN(id));
} else if (typeof popularItems === 'string') { } else if (typeof popularItems === 'string') {
// Comma-separated string
return popularItems return popularItems
.split(',') .split(',')
.map((id: string) => parseInt(id.trim())) .map((id: string) => parseInt(id.trim()))
@ -204,6 +200,15 @@ export default function Dashboard() {
return []; 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 // Filter products to only include those whose ID exists in popularItemIds, preserving order
// Only filter when both products and essentialConsts are loaded // Only filter when both products and essentialConsts are loaded
const popularProducts = popularItemIds const popularProducts = popularItemIds
@ -417,7 +422,7 @@ export default function Dashboard() {
</View> </View>
{/* Upcoming Deliveries Section */} {/* Upcoming Deliveries Section */}
{slotsData?.slots && slotsData.slots.length > 0 && ( {sortedSlots.length > 0 && (
<View style={tw`mt-2 mb-4`}> <View style={tw`mt-2 mb-4`}>
<View style={tw`flex-row items-center justify-between px-1 mb-6`}> <View style={tw`flex-row items-center justify-between px-1 mb-6`}>
<View> <View>
@ -437,9 +442,9 @@ export default function Dashboard() {
showsHorizontalScrollIndicator={false} showsHorizontalScrollIndicator={false}
contentContainerStyle={tw` pb-6`} contentContainerStyle={tw` pb-6`}
decelerationRate="fast" 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 now = dayjs();
const freezeTime = dayjs(slot.freezeTime); const freezeTime = dayjs(slot.freezeTime);
const isClosingSoon = const isClosingSoon =

View file

@ -26,21 +26,6 @@ import { trpc } from "@/src/trpc-client";
import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; 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 { interface CartPageProps {
isFlashDelivery?: boolean; isFlashDelivery?: boolean;
} }
@ -62,14 +47,14 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
// Extract product IDs from cart items // Extract product IDs from cart items
const productIds = cartData?.items.map(item => item.productId) || []; const productIds = cartData?.items.map(item => item.productId) || [];
// Get cart slots for the products in cart // Get cart slots for the products in cart
const { data: slotsData, refetch: refetchSlots, error: slotsError } = trpc.user.cart.getCartSlots.useQuery( const { data: slotsData, refetch: refetchSlots, isLoading: isSlotsLoading } = trpc.user.cart.getCartSlots.useQuery(
{ productIds }, { productIds },
{ {
enabled: productIds.length > 0, enabled: productIds.length > 0,
refetchOnWindowFocus: false refetchOnWindowFocus: false
} }
); );
const generateCouponDescription = (coupon: any): string => { const generateCouponDescription = (coupon: any): string => {
let desc = ""; let desc = "";
@ -324,14 +309,11 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
const newSelectedSlots = { ...selectedSlots }; const newSelectedSlots = { ...selectedSlots };
cartItems.forEach(item => { cartItems.forEach(item => {
// Skip if already has a selected slot const existingSlotId = selectedSlots[item.id];
if (selectedSlots[item.id]) return;
if (isFlashDelivery) { if (isFlashDelivery) {
// For flash delivery, always use slot 0
newSelectedSlots[item.id] = 0; newSelectedSlots[item.id] = 0;
} else { } else {
// For regular delivery, find earliest available slot
const productSlots = slotsData?.[item.productId]; const productSlots = slotsData?.[item.productId];
if (!productSlots || productSlots.length === 0) return; if (!productSlots || productSlots.length === 0) return;
@ -343,9 +325,16 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
); );
if (upcomingSlots.length > 0) { if (upcomingSlots.length > 0) {
// Select the earliest available slot for this product if (existingSlotId) {
const earliestSlot = upcomingSlots[0]; const slotStillValid = upcomingSlots.some(slot => slot.id === existingSlotId);
newSelectedSlots[item.id] = earliestSlot.id; 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 ( return (
<View style={tw`flex-1 justify-center items-center bg-gray-50`}> <View style={tw`flex-1 justify-center items-center bg-gray-50`}>
<MyText style={tw`text-gray-500 font-medium`}>Loading cart...</MyText> <MyText style={tw`text-gray-500 font-medium`}>Loading cart...</MyText>