This commit is contained in:
shafi54 2026-10-09 01:22:26 +05:30
parent 92bf4e8b44
commit 8e4e3752a6
6 changed files with 189 additions and 37 deletions

View file

@ -1,7 +1,7 @@
import React, { useState, useEffect, useRef } from 'react';
import { View, Text, TouchableOpacity, ScrollView, Alert, NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
import { useRouter } from 'expo-router';
import { tw, BottomDialog, RawBottomDialog } from 'common-ui';
import { tw, BottomDialog, RawBottomDialog, MyText } from 'common-ui';
import { useQueryClient } from '@tanstack/react-query';
import AddressForm from '@/src/components/AddressForm';
import LocationAttacher from '@/src/components/LocationAttacher';
@ -263,15 +263,20 @@ const CheckoutAddressSelector: React.FC<AddressSelectorProps> = ({
{selectedAddress && (() => {
const selectedAddr = sortedAddresses.find(a => a.id === selectedAddress);
return selectedAddr && !selectedAddr.latitude && !selectedAddr.longitude ? (
<TouchableOpacity
onPress={() => handleAttachLocation(selectedAddr)}
disabled={locationLoading && editingLocationAddressId === selectedAddr.id}
style={tw`mt-3 py-2 px-3 bg-blue-50 rounded-lg self-start`}
>
<Text style={tw`text-blue-600 text-sm font-bold`}>
{locationLoading && editingLocationAddressId === selectedAddr.id ? 'Attaching...' : '+ Attach Current Location'}
</Text>
</TouchableOpacity>
<>
<MyText style={tw`text-gray-500 text-xs mt-3`}>
No Location is attached to address
</MyText>
<TouchableOpacity
onPress={() => handleAttachLocation(selectedAddr)}
disabled={locationLoading && editingLocationAddressId === selectedAddr.id}
style={tw`mt-2 py-2 px-3 bg-blue-50 rounded-lg self-start`}
>
<Text style={tw`text-blue-600 text-sm font-bold`}>
{locationLoading && editingLocationAddressId === selectedAddr.id ? 'Attaching...' : '+ Attach Current Location'}
</Text>
</TouchableOpacity>
</>
) : null;
})()}
</View>

View file

@ -1,12 +1,13 @@
import React, { useState, useMemo } from 'react';
import { View, Alert, Platform } from 'react-native';
import { useRouter } from 'expo-router';
import { tw, MyTextInput, LoadingDialog, MyText, MyTouchableOpacity } from 'common-ui';
import { tw, LoadingDialog, MyText, MyTouchableOpacity } from 'common-ui';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { trpc } from '@/src/trpc-client';
import { useCentralProductStore } from '@/src/store/centralProductStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
import { useRegion } from '@/src/hooks/useRegion';
import { useCheckoutStore } from '@/src/store/checkoutStore';
import { clearLocalCart } from '@/hooks/cart-query-hooks';
import { useQueryClient } from '@tanstack/react-query';
import { FontAwesome5, FontAwesome6 } from '@expo/vector-icons';
@ -48,9 +49,9 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
const router = useRouter();
const queryClient = useQueryClient();
const utils = trpc.useUtils();
const [userNotes, setUserNotes] = useState('');
const [isLoadingDialogOpen, setIsLoadingDialogOpen] = useState(false);
const [paymentMethod, setPaymentMethod] = useState<'online' | 'cod'>('cod');
const userNotes = useCheckoutStore((state) => state.userNotes);
// Helper function to clear cart and invalidate queries
const clearCartAndInvalidateQueries = async (cartType: 'regular' | 'flash' = 'regular') => {
@ -194,20 +195,6 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
</View>
)}
{/* Special Instructions */}
<View style={tw`bg-white p-5 rounded-2xl shadow-sm mb-4 border border-gray-100`}>
<MyText style={tw`text-base font-bold text-gray-900 mb-3`}>Delivery Instructions</MyText>
<MyTextInput
style={tw`border border-gray-200 rounded-xl p-3 min-h-24 text-base bg-gray-50`}
value={userNotes}
onChangeText={setUserNotes}
placeholder="Any special instructions for the delivery partner..."
multiline
numberOfLines={3}
textAlignVertical="top"
/>
</View>
{/* Payment Method */}
<View style={tw`bg-white p-5 rounded-2xl shadow-sm mb-4 border border-gray-100`}>
<MyText style={tw`text-lg font-bold text-gray-900 mb-4`}>Payment Method</MyText>
@ -357,6 +344,14 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
</MyText>
</View>
)}
<MyTouchableOpacity
testID="checkout-back-button"
style={tw`border border-gray-200 bg-white py-3.5 rounded-xl items-center mb-3`}
onPress={() => router.back()}
>
<MyText style={tw`text-gray-700 font-bold`}>Back to Cart</MyText>
</MyTouchableOpacity>
<MyTouchableOpacity
testID="place-order-button"
style={tw`bg-brand500 py-4 rounded-xl items-center shadow-md ${!selectedAddress ? 'opacity-50' : ''}`}

View file

@ -14,6 +14,7 @@ import {
AppContainer,
useMarkDataFetchers,
MyText,
MyTextInput,
MyTouchableOpacity,
BottomDropdown, BottomDialog , Quantifier } from "common-ui";
import MaterialIcons from "@expo/vector-icons/MaterialIcons";
@ -31,6 +32,7 @@ import { useRegionalConsts } from '@/src/hooks/prominent-api-hooks';
import CheckoutAddressSelector from '@/components/CheckoutAddressSelector';
import LoginWall from '@/components/LoginWall';
import { useAddressStore } from '@/src/store/addressStore';
import { useCheckoutStore } from '@/src/store/checkoutStore';
import type { FlashDeliveryProps } from '@packages/shared';
const formatDeliverySlot = (deliveryTime: string): string => {
@ -185,6 +187,8 @@ export default function CartPage({ isFlashDelivery = false }: FlashDeliveryProps
const cartType: "regular" | "flash" = isFlashDelivery ? "flash" : "regular";
const { selectedAddressId, setSelectedAddressId } = useAddressStore();
const userNotes = useCheckoutStore((state) => state.userNotes);
const setUserNotes = useCheckoutStore((state) => state.setUserNotes);
const [quantities, setQuantities] = useState<Record<number, number>>({});
const {
@ -979,10 +983,14 @@ export default function CartPage({ isFlashDelivery = false }: FlashDeliveryProps
})}
</View>
<CheckoutAddressSelector
selectedAddress={selectedAddressId}
onAddressSelect={setSelectedAddressId}
/>
{/* Delivery Slot Summary */}
{!isFlashDelivery && cartItems.length > 0 && (
<DeliverySlotSummary
groups={slotGroups}
mergeSuggestion={mergeSuggestion}
onMerge={handleMergeSlots}
/>
)}
</>
)}
@ -1113,14 +1121,23 @@ export default function CartPage({ isFlashDelivery = false }: FlashDeliveryProps
</View>
)}
{/* Delivery Slot Summary */}
{!isFlashDelivery && cartItems.length > 0 && (
<DeliverySlotSummary
groups={slotGroups}
mergeSuggestion={mergeSuggestion}
onMerge={handleMergeSlots}
{/* Delivery Instructions */}
<View style={tw`bg-white p-5 rounded-2xl shadow-sm mb-4 border border-gray-100`}>
<MyText style={tw`text-base font-bold text-gray-900 mb-3`}>Delivery Instructions</MyText>
<MyTextInput
value={userNotes}
onChangeText={setUserNotes}
placeholder="Any special instructions for the delivery partner..."
multiline
numberOfLines={3}
/>
)}
</View>
{/* Delivery Address */}
<CheckoutAddressSelector
selectedAddress={selectedAddressId}
onAddressSelect={setSelectedAddressId}
/>
{/* Bottom Checkout Bar - Now Static */}
{hasAvailableItems && (

View file

@ -1,6 +1,7 @@
import React, { useState, useMemo } from 'react';
import { View, ScrollView } from 'react-native';
import { useLocalSearchParams, useRouter } from 'expo-router';
import dayjs from 'dayjs';
import { tw, useMarkDataFetchers , BottomDialog, MyText, MyTouchableOpacity } from 'common-ui';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { useAuthenticatedRoute } from '@/hooks/useAuthenticatedRoute';
@ -89,6 +90,37 @@ const CheckoutPage: React.FC<FlashDeliveryProps> = ({ isFlashDelivery = false })
return selectedSlots[item.id];
});
// Read-only items grouped by their chosen delivery slot, sorted by slot time.
const groupedItems = useMemo(() => {
if (isFlashDelivery) {
return [
{ slotId: null as number | null, label: null as string | null, sortKey: 0, items: selectedItems },
];
}
const groups = new Map<number, typeof selectedItems>();
selectedItems.forEach((item) => {
const slotId = selectedSlots[item.id];
if (slotId == null) return;
const list = groups.get(slotId) ?? [];
list.push(item);
groups.set(slotId, list);
});
return Array.from(groups.entries())
.map(([slotId, items]) => {
const slot = slotsData?.slots?.find((candidate) => candidate.id === slotId);
const deliveryTime = slot ? dayjs(slot.deliveryTime) : null;
return {
slotId: slotId as number | null,
label: (deliveryTime
? deliveryTime.format('ddd, DD MMM h:mm A')
: `Slot #${slotId}`) as string | null,
sortKey: deliveryTime ? deliveryTime.valueOf() : Number.MAX_SAFE_INTEGER,
items,
};
})
.sort((a, b) => a.sortKey - b.sortKey);
}, [isFlashDelivery, selectedItems, selectedSlots, slotsData]);
React.useEffect(() => {
if (params.coupons) {
const couponId = Number(params.coupons as string);
@ -257,6 +289,69 @@ const CheckoutPage: React.FC<FlashDeliveryProps> = ({ isFlashDelivery = false })
contentContainerStyle={tw`p-4 pb-32`}
showsVerticalScrollIndicator={false}
>
{/* Items (grouped by delivery slot) */}
<View style={tw`bg-white p-5 rounded-2xl shadow-sm mb-4 border border-gray-100`}>
<MyText style={tw`text-base font-bold text-gray-900 mb-3`}>Items</MyText>
{groupedItems.map((group) => (
<View key={group.slotId ?? 'flash'}>
{group.label && (
<View
style={tw`flex-row items-center self-start mt-3 mb-1 rounded-full bg-gray-100 px-2.5 py-1`}
>
<MaterialIcons name="schedule" size={13} color="#1570EF" style={tw`mr-1`} />
<MyText style={tw`text-xs font-semibold text-gray-800`}>
{group.label}
</MyText>
</View>
)}
{group.items.map((item) => {
const product = productsById[item.skuId];
const price = isFlashDelivery
? (product?.flashPrice ?? product?.price ?? 0)
: (product?.price || 0);
return (
<View
key={item.id}
style={tw`flex-row items-center justify-between py-2 border-b border-gray-50`}
>
<View style={tw`flex-1 mr-3`}>
<MyText style={tw`text-sm text-gray-900`} numberOfLines={1}>
{product?.name}
</MyText>
{!!product?.unitNotation && (
<MyText style={tw`text-xs text-gray-500 mt-0.5`}>
{product.unitNotation}
</MyText>
)}
</View>
<MyText style={tw`text-xs text-gray-500 mr-3`}>x{item.quantity}</MyText>
<MyText style={tw`text-sm font-bold text-gray-900`}>
₹{Number(price) * item.quantity}
</MyText>
</View>
);
})}
</View>
))}
</View>
{/* Coupon */}
{selectedCoupons.length > 0 && (
<View style={tw`bg-white p-5 rounded-2xl shadow-sm mb-4 border border-gray-100`}>
<MyText style={tw`text-base font-bold text-gray-900 mb-3`}>Coupon</MyText>
{selectedCoupons.map((coupon) => (
<View key={coupon.id} style={tw`flex-row items-center justify-between py-2`}>
<MyText style={tw`text-sm font-medium text-gray-900`}>{coupon.code}</MyText>
<MyText style={tw`text-sm font-bold text-green-600`}>
{coupon.discountType === 'percentage'
? `${coupon.discountValue}% off`
: `₹${coupon.discountValue} off`}
</MyText>
</View>
))}
</View>
)}
<CheckoutAddressDisplay />
<PaymentAndOrderComponent

View file

@ -0,0 +1,13 @@
import { create } from 'zustand'
// Order-review state shared between the cart (editable) and checkout (read-only
// summary). Currently just the delivery instructions the user types on the cart.
interface CheckoutStore {
userNotes: string
setUserNotes: (notes: string) => void
}
export const useCheckoutStore = create<CheckoutStore>((set) => ({
userNotes: '',
setUserNotes: (userNotes) => set({ userNotes }),
}))

View file

@ -1302,3 +1302,30 @@ user-ui
[2026-10-09 12:10:00] user-ui cart: address selector moved below the items; "Go to 1 Hr Delivery" switcher
card hidden ({false && ...}). user-ui typecheck clean.
[2026-10-09 12:20:00] user-ui CheckoutAddressSelector: show "No Location is attached to address" above the
Attach Current Location button when the selected address has no coordinates.
[2026-10-09 12:30:00] user-ui cart: move the address selector to just above the Bill Details section.
[2026-10-09 12:45:00] user-ui: instructions move to the cart; checkout becomes a read-only summary.
- new src/store/checkoutStore.ts (userNotes) shared between cart + checkout.
- cart-page: "Delivery Instructions" input above the address selector (bound to checkoutStore).
- PaymentAndOrderComponent: read userNotes from the store; remove its inline instructions input.
- checkout-page: read-only summary cards for Items, Delivery Slot, Coupon (address + bill already shown).
[2026-10-09 12:55:00] done. user-ui typecheck clean.
- checkoutStore (userNotes); cart has the Delivery Instructions input above the address selector;
PaymentAndOrderComponent reads userNotes from the store (input removed) and still sends it with the order.
- checkout-page shows read-only Items / Delivery Slot / Coupon cards + address + bill.
[2026-10-09 13:05:00] user-ui cart: move the Delivery Slot Summary to right after the items (before coupons).
(Checkout page already shows Items -> Delivery Slot -> Coupon -> Address -> Bill.) typecheck clean.
[2026-10-09 13:15:00] user-ui checkout: Items section now groups by delivery slot (slot time header, then its
items), slots sorted by time; removed the separate Delivery Slot card. typecheck clean.
[2026-10-09 13:20:00] user-ui checkout: give the slot-time header a subtle spotlight (pill background,
brand icon, semibold text).
[2026-10-09 13:30:00] user-ui checkout: add a "Back to Cart" button above the Place Order button.