enh
This commit is contained in:
parent
78e90fd398
commit
d1d7db55a0
3 changed files with 41 additions and 9 deletions
|
|
@ -88,6 +88,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|||
const slotId = getQuickestSlot(item.id);
|
||||
const displayIsOutOfStock = item.isOutOfStock || !slotId;
|
||||
|
||||
// if(item.name.startsWith('Mutton Curry Cut')) {
|
||||
// console.log({slotId, displayIsOutOfStock})
|
||||
// }
|
||||
|
||||
// Return null if nullIfNotAvailable is true and the product is out of stock
|
||||
if (nullIfNotAvailable && displayIsOutOfStock) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -397,7 +397,14 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
|
|||
);
|
||||
}
|
||||
|
||||
const filteredProducts: any[] = storeIdNum ? productsQuery?.data?.filter(p => p.store?.id === storeIdNum) || [] : slotQuery.data.products;
|
||||
// Create a Set of product IDs from slot data for O(1) lookup
|
||||
const slotProductIds = new Set(slotQuery.data.products?.map((p: any) => p.id) || []);
|
||||
|
||||
const filteredProducts: any[] = storeIdNum
|
||||
? productsQuery?.data?.filter(p =>
|
||||
p.store?.id === storeIdNum && slotProductIds.has(p.id)
|
||||
) || []
|
||||
: slotQuery.data.products;
|
||||
|
||||
return (
|
||||
<View style={tw`flex-1`}>
|
||||
|
|
@ -481,11 +488,18 @@ export function FlashDeliveryProducts({ storeId:storeIdParent, baseUrl, onProduc
|
|||
// Filter products to only include those eligible for flash delivery
|
||||
let flashProducts: any[] = [];
|
||||
if (storeIdNum) {
|
||||
// Filter by store and flash availability
|
||||
flashProducts = productsQuery?.data?.filter(p => p.store?.id === storeIdNum && p.isFlashAvailable) || [];
|
||||
// Filter by store, flash availability, and stock status
|
||||
flashProducts = productsQuery?.data?.filter(p =>
|
||||
p.store?.id === storeIdNum &&
|
||||
p.isFlashAvailable &&
|
||||
!p.isOutOfStock
|
||||
) || [];
|
||||
} else {
|
||||
// Show all flash-available products (no slot filtering)
|
||||
flashProducts = productsQuery?.data?.filter(p => p.isFlashAvailable) || [];
|
||||
// Show all flash-available products that are in stock
|
||||
flashProducts = productsQuery?.data?.filter(p =>
|
||||
p.isFlashAvailable &&
|
||||
!p.isOutOfStock
|
||||
) || [];
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
import { trpc } from '@/src/trpc-client';
|
||||
import dayjs from 'dayjs';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
let isPrinted = false;
|
||||
export function useProductSlotIdentifier() {
|
||||
// Fetch all slots with products
|
||||
const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
|
||||
const { data: slotsData, isLoading: isProductsLoading } = trpc.user.slots.getSlotsWithProducts.useQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if(!isProductsLoading && !isPrinted) {
|
||||
isPrinted = true;
|
||||
const slotInfo = slotsData?.slots.map(slot => ({...slot, products: slot.products.map(item => ({id: item.id, name: item.name}))}))
|
||||
console.log(JSON.stringify(slotInfo))
|
||||
}
|
||||
|
||||
},[slotsData])
|
||||
|
||||
|
||||
const productSlotsMap = new Map<number, number[]>();
|
||||
|
||||
|
|
@ -24,6 +36,7 @@ export function useProductSlotIdentifier() {
|
|||
}
|
||||
|
||||
const getQuickestSlot = (productId: number): number | null => {
|
||||
|
||||
if (!slotsData?.slots) return null;
|
||||
|
||||
const now = dayjs();
|
||||
|
|
@ -33,7 +46,8 @@ export function useProductSlotIdentifier() {
|
|||
slot.products.some(product => product.id === productId) &&
|
||||
dayjs(slot.deliveryTime).isAfter(now)
|
||||
);
|
||||
|
||||
// if(productId === 98)
|
||||
// console.log(JSON.stringify(slotsData))
|
||||
if (availableSlots.length === 0) return null;
|
||||
|
||||
// Return earliest slot ID (sorted by delivery time)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue