enh
This commit is contained in:
parent
419fa83b8c
commit
0382b03ad8
5 changed files with 35 additions and 51 deletions
|
|
@ -428,7 +428,7 @@ export default function OrderDetails() {
|
|||
{item.name}
|
||||
</MyText>
|
||||
<MyText style={tw`text-xs text-gray-500`}>
|
||||
{item.quantity} {item.unit} × ₹{item.price}
|
||||
{Number(item.quantity) * item.productSize} {item.unit} × ₹{item.price}
|
||||
</MyText>
|
||||
<View style={tw`flex-row items-center mt-2 gap-3`}>
|
||||
<TouchableOpacity
|
||||
|
|
|
|||
|
|
@ -155,17 +155,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 (
|
||||
<>
|
||||
<TouchableOpacity
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
</View>
|
||||
|
||||
{/* Upcoming Deliveries Section */}
|
||||
{slotsData?.slots && slotsData.slots.length > 0 && (
|
||||
{sortedSlots.length > 0 && (
|
||||
<View style={tw`mt-2 mb-4`}>
|
||||
<View style={tw`flex-row items-center justify-between px-1 mb-6`}>
|
||||
<View>
|
||||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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,8 +47,8 @@ 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(
|
||||
// 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,
|
||||
|
|
@ -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 (
|
||||
<View style={tw`flex-1 justify-center items-center bg-gray-50`}>
|
||||
<MyText style={tw`text-gray-500 font-medium`}>Loading cart...</MyText>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue