enh
This commit is contained in:
parent
d8271dd502
commit
cd5905d40f
3 changed files with 26 additions and 17 deletions
|
|
@ -26,7 +26,6 @@ export default function BannerCarousel() {
|
||||||
|
|
||||||
// Fetch banners data
|
// Fetch banners data
|
||||||
const { data: bannersData, isLoading, error } = trpc.user.banner.getBanners.useQuery();
|
const { data: bannersData, isLoading, error } = trpc.user.banner.getBanners.useQuery();
|
||||||
console.log({bannersData})
|
|
||||||
|
|
||||||
const banners = bannersData?.banners || [];
|
const banners = bannersData?.banners || [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,11 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
|
||||||
showErrorAlert: false,
|
showErrorAlert: false,
|
||||||
refetchCart: true,
|
refetchCart: true,
|
||||||
}, cartType);
|
}, cartType);
|
||||||
const { addToCart = () => { } } = useAddToCart({
|
const addToCartHook = useAddToCart({
|
||||||
showSuccessAlert: false,
|
showSuccessAlert: false,
|
||||||
showErrorAlert: false,
|
showErrorAlert: false,
|
||||||
refetchCart: true,
|
refetchCart: true,
|
||||||
}, cartType) || {};
|
}, cartType);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initial: Record<number, number> = {};
|
const initial: Record<number, number> = {};
|
||||||
|
|
@ -101,18 +101,19 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
|
||||||
if (!cartItems.length || !slotsData?.slots || !productSlotsMap) return;
|
if (!cartItems.length || !slotsData?.slots || !productSlotsMap) return;
|
||||||
|
|
||||||
const itemsToUpdate = cartItems.filter(item => {
|
const itemsToUpdate = cartItems.filter(item => {
|
||||||
if (!item.slotId) return true; // No slotId
|
if (isFlashDelivery || !item.slotId) return false;
|
||||||
const slotExists = slotsData.slots.some(slot => slot.id === item.slotId);
|
|
||||||
return !slotExists; // Slot doesn't exist
|
const availableSlots = productSlotsMap.get(item.productId) || [];
|
||||||
|
const isSlotAvailable = availableSlots.includes(item.slotId);
|
||||||
|
return !isSlotAvailable;
|
||||||
});
|
});
|
||||||
|
|
||||||
itemsToUpdate.forEach((item) => {
|
itemsToUpdate.forEach((item) => {
|
||||||
|
|
||||||
const availableSlots = productSlotsMap.get(item.productId) || [];
|
const availableSlots = productSlotsMap.get(item.productId) || [];
|
||||||
if (availableSlots.length > 0 && !isFlashDelivery) { // don't bother updating slot for flash delivery
|
if (availableSlots.length > 0 && !isFlashDelivery) {
|
||||||
const nearestSlotId = availableSlots[0];
|
const nearestSlotId = availableSlots[0];
|
||||||
removeFromCart.mutate({ itemId: item.id });
|
removeFromCart.mutate({ itemId: item.id });
|
||||||
addToCart(item.productId, item.quantity, nearestSlotId);
|
addToCartHook.addToCart(item.productId, item.quantity, nearestSlotId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -281,9 +282,20 @@ options={(productSlotsMap.get(item.productId) || []).map(slotId => {
|
||||||
value: slotId,
|
value: slotId,
|
||||||
};
|
};
|
||||||
})}
|
})}
|
||||||
onValueChange={(val) => {
|
onValueChange={async (val) => {
|
||||||
const newSlot = slotsData.slots.find(s => s.id === val);
|
const newSlot = slotsData.slots.find(s => s.id === val);
|
||||||
|
if (!newSlot) return;
|
||||||
|
|
||||||
|
const productId = item.productId;
|
||||||
|
const quantity = item.quantity;
|
||||||
|
const itemId = item.id;
|
||||||
|
const slotId = typeof val === 'number' ? val : Number(val);
|
||||||
|
|
||||||
|
// await removeFromCart.mutateAsync(itemId);
|
||||||
|
addToCartHook.addToCart(productId, 0, slotId, () => {
|
||||||
|
refetchCart();
|
||||||
Alert.alert("Delivery Updated", `Scheduled for ${formatTimeRange(newSlot?.deliveryTime || '')}`);
|
Alert.alert("Delivery Updated", `Scheduled for ${formatTimeRange(newSlot?.deliveryTime || '')}`);
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
triggerComponent={({ onPress, displayText }) => (
|
triggerComponent={({ onPress, displayText }) => (
|
||||||
<MyTouchableOpacity
|
<MyTouchableOpacity
|
||||||
|
|
|
||||||
|
|
@ -91,8 +91,6 @@ const addToLocalCart = async (productId: number, quantity: number, slotId?: numb
|
||||||
items.push(cartItem);
|
items.push(cartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log({items})
|
|
||||||
|
|
||||||
await saveLocalCart(items, cartType);
|
await saveLocalCart(items, cartType);
|
||||||
return items;
|
return items;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue