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
|
||||
const { data: bannersData, isLoading, error } = trpc.user.banner.getBanners.useQuery();
|
||||
console.log({bannersData})
|
||||
|
||||
const banners = bannersData?.banners || [];
|
||||
|
||||
|
|
|
|||
|
|
@ -83,11 +83,11 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
|
|||
showErrorAlert: false,
|
||||
refetchCart: true,
|
||||
}, cartType);
|
||||
const { addToCart = () => { } } = useAddToCart({
|
||||
const addToCartHook = useAddToCart({
|
||||
showSuccessAlert: false,
|
||||
showErrorAlert: false,
|
||||
refetchCart: true,
|
||||
}, cartType) || {};
|
||||
}, cartType);
|
||||
|
||||
useEffect(() => {
|
||||
const initial: Record<number, number> = {};
|
||||
|
|
@ -97,22 +97,23 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
|
|||
setQuantities(initial);
|
||||
}, [cartData]);
|
||||
|
||||
useEffect(() => {
|
||||
useEffect(() => {
|
||||
if (!cartItems.length || !slotsData?.slots || !productSlotsMap) return;
|
||||
|
||||
const itemsToUpdate = cartItems.filter(item => {
|
||||
if (!item.slotId) return true; // No slotId
|
||||
const slotExists = slotsData.slots.some(slot => slot.id === item.slotId);
|
||||
return !slotExists; // Slot doesn't exist
|
||||
if (isFlashDelivery || !item.slotId) return false;
|
||||
|
||||
const availableSlots = productSlotsMap.get(item.productId) || [];
|
||||
const isSlotAvailable = availableSlots.includes(item.slotId);
|
||||
return !isSlotAvailable;
|
||||
});
|
||||
|
||||
itemsToUpdate.forEach((item) => {
|
||||
|
||||
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];
|
||||
removeFromCart.mutate({ itemId: item.id });
|
||||
addToCart(item.productId, item.quantity, nearestSlotId);
|
||||
addToCartHook.addToCart(item.productId, item.quantity, nearestSlotId);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
|
@ -274,17 +275,28 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
|
|||
<BottomDropdown
|
||||
label="Select Delivery Slot"
|
||||
value={item.slotId}
|
||||
options={(productSlotsMap.get(item.productId) || []).map(slotId => {
|
||||
options={(productSlotsMap.get(item.productId) || []).map(slotId => {
|
||||
const slot = slotsData.slots.find(s => s.id === slotId);
|
||||
return {
|
||||
label: slot ? formatTimeRange(slot.deliveryTime) : "N/A",
|
||||
value: slotId,
|
||||
};
|
||||
})}
|
||||
onValueChange={(val) => {
|
||||
const newSlot = slotsData.slots.find(s => s.id === val);
|
||||
Alert.alert("Delivery Updated", `Scheduled for ${formatTimeRange(newSlot?.deliveryTime || '')}`);
|
||||
}}
|
||||
onValueChange={async (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 || '')}`);
|
||||
});
|
||||
}}
|
||||
triggerComponent={({ onPress, displayText }) => (
|
||||
<MyTouchableOpacity
|
||||
onPress={onPress}
|
||||
|
|
|
|||
|
|
@ -91,8 +91,6 @@ const addToLocalCart = async (productId: number, quantity: number, slotId?: numb
|
|||
items.push(cartItem);
|
||||
}
|
||||
|
||||
console.log({items})
|
||||
|
||||
await saveLocalCart(items, cartType);
|
||||
return items;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue