diff --git a/AGENTS.md b/AGENTS.md index 312b63e..349183f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ ## Important instructions - Don't run any drizzle migrations. User will handle it. -- don't try to run any test unless user explicitly asks for +- don't try to run any test from the suite unless user explicitly asks for ## Code Style Guidelines diff --git a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx index 2548cc4..5002a5a 100755 --- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx @@ -391,6 +391,9 @@ const ListHeader = memo(({ return ( <> + + + {dashboardTags.length > 0 && ( )} - - - - {sortedSlots.length > 0 && ( diff --git a/apps/user-ui/app/(drawer)/(tabs)/me/my-orders/[id].tsx b/apps/user-ui/app/(drawer)/(tabs)/me/my-orders/[id].tsx index dc5aa42..7c290ba 100644 --- a/apps/user-ui/app/(drawer)/(tabs)/me/my-orders/[id].tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/me/my-orders/[id].tsx @@ -9,6 +9,7 @@ import Ionicons from '@expo/vector-icons/Ionicons'; import dayjs from "dayjs"; import ComplaintForm from "@/components/ComplaintForm"; import { orderStatusManipulator } from "@/src/lib/string-manipulators"; +import OrderStatusTracker from "@/components/OrderStatusTracker"; export default function OrderDetails() { const { id } = useLocalSearchParams<{ id: string }>(); @@ -176,6 +177,12 @@ export default function OrderDetails() { )} + {/* Order Status Tracker */} + + Order Status + + + {/* Main Info Card */} diff --git a/apps/user-ui/components/NextOrderGlimpse.tsx b/apps/user-ui/components/NextOrderGlimpse.tsx index c459f4a..2069779 100644 --- a/apps/user-ui/components/NextOrderGlimpse.tsx +++ b/apps/user-ui/components/NextOrderGlimpse.tsx @@ -4,11 +4,11 @@ import { View, TouchableOpacity, ActivityIndicator, Linking, ScrollView, Dimensi import { useRouter } from 'expo-router'; import { tw, MyText } from 'common-ui'; import { useNavigationTarget } from 'common-ui/hooks/useNavigationTarget'; -import { MaterialIcons, Ionicons } from '@expo/vector-icons'; +import { MaterialIcons } from '@expo/vector-icons'; import dayjs from 'dayjs'; import { trpc } from '@/src/trpc-client'; -import { Image } from 'expo-image'; import { orderStatusManipulator } from '@/src/lib/string-manipulators'; +import OrderStatusTracker from './OrderStatusTracker'; import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useUserDetails } from '@/src/contexts/AuthContext'; import type { Order, OrderItem } from '@/src/types/orders'; @@ -22,6 +22,22 @@ interface OrderCardProps extends OrderCardActionProps { } function OrderCard({ order, onPress, supportMobile }: OrderCardProps) { + const statusLabel = orderStatusManipulator(order.deliveryStatus); + const hideStatus = ['confirmed', 'packaged'].includes(statusLabel.toLowerCase()); + const deliveryPrimaryLabel = order.isFlashDelivery + ? "30-Min" + : (() => { + const startTime = dayjs(order.deliveryDate); + const endTime = startTime.add(1, 'hour'); + const startPeriod = startTime.format("A"); + const endPeriod = endTime.format("A"); + return startPeriod === endPeriod + ? `${startTime.format("hh:mm")} - ${endTime.format("hh:mm")} ${startPeriod}` + : `${startTime.format("hh:mm A")} - ${endTime.format("hh:mm A")}`; + })(); + const deliverySecondaryLabel = order.isFlashDelivery + ? "Delivery" + : dayjs(order.deliveryDate).format("DD MMM"); return ( Upcoming Order - {order.isFlashDelivery && ( - - - FLASH - - )} + + {order.isFlashDelivery && ( + + + FLASH + + )} + + @@ -49,57 +68,34 @@ function OrderCard({ order, onPress, supportMobile }: OrderCardProps) { {order.items.length} {order.items.length === 1 ? 'item' : 'items'} • ₹{order.totalAmount} - - {orderStatusManipulator(order.deliveryStatus)} - - - - - - - {order.isFlashDelivery - ? "30-Min Delivery" - : (() => { - const startTime = dayjs(order.deliveryDate); - const endTime = startTime.add(1, 'hour'); - return `${startTime.format("DD MMM, hh:mm A")} - ${endTime.format("hh:mm A")}`; - })() - } - - - - {order.items.length > 0 && ( - - - {order.items.slice(0, 3).map((item, idx) => ( - 0 ? -8 : 0 } - ]} - > - - - ))} - {order.items.length > 3 && ( - - +{order.items.length - 3} - - )} + + + + + {deliveryPrimaryLabel} + + {deliverySecondaryLabel} - Track Order - + {!hideStatus && ( + + {statusLabel} + + )} - )} + + + + + {/* Support Mobile Number */} {supportMobile && ( diff --git a/apps/user-ui/components/OrderStatusTracker.tsx b/apps/user-ui/components/OrderStatusTracker.tsx new file mode 100644 index 0000000..cbd81e1 --- /dev/null +++ b/apps/user-ui/components/OrderStatusTracker.tsx @@ -0,0 +1,72 @@ +import { View } from 'react-native'; +import { tw, MyText } from 'common-ui'; + +const STAGES = ['Placed', 'Packed', 'Delivered'] as const; + +export type OrderStage = (typeof STAGES)[number]; + +/** + * Maps a backend deliveryStatus to the furthest stage reached: + * pending / processing -> 0 (Placed) + * packaged -> 1 (Packed) + * success / delivered -> 2 (Delivered) + * Anything else (incl. cancelled) falls back to 0. + */ +export function deliveryStageIndex(deliveryStatus?: string | null): number { + switch ((deliveryStatus || '').toLowerCase()) { + case 'packaged': + return 1; + case 'success': + case 'delivered': + return 2; + default: + return 0; + } +} + +interface OrderStatusTrackerProps { + deliveryStatus?: string | null; + activeColor?: string; + inactiveColor?: string; +} + +export default function OrderStatusTracker({ + deliveryStatus, + activeColor = '#10B981', + inactiveColor = '#E2E8F0', +}: OrderStatusTrackerProps) { + const cancelled = (deliveryStatus || '').toLowerCase() === 'cancelled'; + const currentIndex = cancelled ? -1 : deliveryStageIndex(deliveryStatus); + + return ( + + {STAGES.map((label, i) => { + const reached = i <= currentIndex; + const dotColor = reached ? activeColor : inactiveColor; + const leftLine = i > 0 && i <= currentIndex ? activeColor : inactiveColor; + const rightLine = i < STAGES.length - 1 && i < currentIndex ? activeColor : inactiveColor; + + return ( + + + + + + + + {label} + + + ); + })} + + ); +} diff --git a/apps/user-ui/components/cart-page.tsx b/apps/user-ui/components/cart-page.tsx index 7d205e2..72fdafe 100644 --- a/apps/user-ui/components/cart-page.tsx +++ b/apps/user-ui/components/cart-page.tsx @@ -30,6 +30,167 @@ import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-q import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import type { FlashDeliveryProps } from '@packages/shared'; +const formatDeliverySlot = (deliveryTime: string): string => { + const time = dayjs(deliveryTime); + const endTime = time.add(1, 'hour'); + const startPeriod = time.format('A'); + const endPeriod = endTime.format('A'); + + const range = startPeriod === endPeriod + ? `${time.format('h')}-${endTime.format('h')} ${startPeriod}` + : `${time.format('h:mm')} ${startPeriod} - ${endTime.format('h:mm')} ${endPeriod}`; + + return `${time.format('ddd, DD MMM ')}${range}`; +}; + +interface DeliverySlotGroupItem { + id: number; + name: string; + quantity: number; + unitNotation?: string; + image?: string; +} + +interface DeliverySlotGroup { + slotId: number; + label: string; + items: DeliverySlotGroupItem[]; +} + +interface DeliverySlotMergeSuggestion { + slotId: number; + label: string; + feasible: boolean; +} + +function DeliverySlotSummary({ + groups, + mergeSuggestion, + onMerge, +}: { + groups: DeliverySlotGroup[]; + mergeSuggestion?: DeliverySlotMergeSuggestion | null; + onMerge?: () => void; +}) { + const [openGroup, setOpenGroup] = useState(null); + + if (groups.length === 0) return null; + + return ( + + + Delivery Slot + + + + {groups.map((group, index) => ( + 0 ? tw`border-t border-gray-100` : {}, + ]} + > + + + {group.label} + + setOpenGroup(group)} + activeOpacity={0.7} + > + + {group.items.length} {group.items.length === 1 ? 'item' : 'items'} + + + + + ))} + + {!!mergeSuggestion && ( + + + + + Deliver All items at {mergeSuggestion.label} + + + {mergeSuggestion.feasible && ( + + + + )} + + )} + + + setOpenGroup(null)}> + + + + Items + {openGroup?.label} + + setOpenGroup(null)} style={tw`p-1`}> + + + + + {openGroup?.items.map((item) => ( + + + + + {item.name} + + {!!item.unitNotation && ( + + {item.unitNotation} + + )} + + x{item.quantity} + + ))} + + + + ); +} + export default function CartPage({ isFlashDelivery = false }: FlashDeliveryProps) { // Hide tabs when cart page is active useHideTabNav(); @@ -297,6 +458,82 @@ export default function CartPage({ isFlashDelivery = false }: FlashDeliveryProps const hasAvailableItems = cartItems.some(item => !productSlotsMap[item.skuId]?.isOutOfStock); + const slotGroups = useMemo(() => { + if (isFlashDelivery || cartItems.length === 0) return []; + + const groupMap = new Map(); + + cartItems.forEach((item) => { + const slotId = selectedSlots[item.id]; + if (slotId === undefined || slotId === null) return; + + if (!groupMap.has(slotId)) { + let label = ''; + if (slotsData) { + for (const productId of Object.keys(slotsData)) { + const slot = slotsData[Number(productId)]?.find((s) => s.id === slotId); + if (slot) { + label = formatDeliverySlot(slot.deliveryTime); + break; + } + } + } + groupMap.set(slotId, { slotId, label, items: [] }); + } + + const product = productsById[item.skuId]; + groupMap.get(slotId)!.items.push({ + id: item.id, + name: product?.name || 'Item', + quantity: quantities[item.id] || item.quantity, + unitNotation: product?.unitNotation, + image: product?.images?.[0], + }); + }); + + return Array.from(groupMap.values()).sort((a, b) => a.slotId - b.slotId); + }, [isFlashDelivery, cartItems, selectedSlots, slotsData, productsById, quantities]); + + const mergeSuggestion = useMemo(() => { + if (isFlashDelivery || slotGroups.length === 0) return null; + + // slotGroups is sorted by slot id, so ties keep the lowest id. + const majority = slotGroups.reduce((best, group) => + group.items.length > best.items.length ? group : best + ); + + const inStockItems = cartItems.filter( + (item) => !productSlotsMap[item.skuId]?.isOutOfStock + ); + + const now = dayjs(); + const feasible = + slotGroups.length > 1 && + inStockItems.length > 0 && + inStockItems.every((item) => + (slotsData?.[item.skuId] || []).some( + (slot) => + slot.id === majority.slotId && + dayjs(slot.deliveryTime).isAfter(now) + ) + ); + + return { slotId: majority.slotId, label: majority.label, feasible }; + }, [isFlashDelivery, slotGroups, cartItems, productSlotsMap, slotsData]); + + const handleMergeSlots = () => { + if (!mergeSuggestion) return; + setSelectedSlots((prev) => { + const next = { ...prev }; + cartItems.forEach((item) => { + if (!productSlotsMap[item.skuId]?.isOutOfStock) { + next[item.id] = mergeSuggestion.slotId; + } + }); + return next; + }); + }; + useEffect(() => { const initial: Record = {}; cartItems.forEach((item) => { @@ -863,6 +1100,15 @@ export default function CartPage({ isFlashDelivery = false }: FlashDeliveryProps )} + {/* Delivery Slot Summary */} + {!isFlashDelivery && cartItems.length > 0 && ( + + )} + {/* Bottom Checkout Bar - Now Static */} {hasAvailableItems && ( diff --git a/apps/user-ui/tests/home-page/next-order-glimpse.test.tsx b/apps/user-ui/tests/home-page/next-order-glimpse.test.tsx index 45df0aa..6aada1d 100644 --- a/apps/user-ui/tests/home-page/next-order-glimpse.test.tsx +++ b/apps/user-ui/tests/home-page/next-order-glimpse.test.tsx @@ -90,8 +90,10 @@ describe('NextOrderGlimpse', () => { expect(screen.getByText('#ORD-1001')).toBeVisible() expect(screen.getByText('2 items • ₹500')).toBeVisible() - // deliveryStatus 'pending' is shown user-facing as "Confirmed". - expect(screen.getByText('Confirmed')).toBeVisible() + // The status pill is hidden for Confirmed/Packaged; the tracker shows the stage. + expect(screen.getByTestId('order-status-tracker')).toBeVisible() + expect(screen.getByText('Placed')).toBeVisible() + expect(screen.queryByText('Confirmed')).toBeNull() }) it('flags a flash order', async () => { @@ -100,7 +102,8 @@ describe('NextOrderGlimpse', () => { await renderLoadedHome() await waitFor(() => expect(screen.getByText('FLASH')).toBeVisible()) - expect(screen.getByText('30-Min Delivery')).toBeVisible() + expect(screen.getByText('30-Min')).toBeVisible() + expect(screen.getByText('Delivery')).toBeVisible() }) it('ignores cancelled and completed orders', async () => { diff --git a/apps/user-ui/tests/screens/cart-screen.test.tsx b/apps/user-ui/tests/screens/cart-screen.test.tsx index b9ed3a7..0ee5b08 100644 --- a/apps/user-ui/tests/screens/cart-screen.test.tsx +++ b/apps/user-ui/tests/screens/cart-screen.test.tsx @@ -21,7 +21,9 @@ import { routerMock } from '../mocks/router' import { renderWithProviders } from '../helpers/render' const PRODUCT_ID = 2 // Chicken Breast 500 g, price 215 (in stock, in a slot) +const OTHER_PRODUCT_ID = 40 // Chicken regular cut Large pieces (in stock) const SLOT_ID = 1849 +const OTHER_SLOT_ID = 1850 const futureSlot = () => ({ id: SLOT_ID, @@ -29,6 +31,12 @@ const futureSlot = () => ({ freezeTime: dayjs().add(2, 'hour').toISOString(), }) +const otherFutureSlot = () => ({ + id: OTHER_SLOT_ID, + deliveryTime: dayjs().add(5, 'hour').toISOString(), + freezeTime: dayjs().add(4, 'hour').toISOString(), +}) + async function seedCart(items: unknown[]) { await StorageServiceCasual.setItem('cart_items', JSON.stringify(items)) } @@ -117,6 +125,70 @@ describe('Cart screen', () => { ) }) + it('shows a pressable merge banner when every item can use the majority slot', async () => { + setupApiMocks({ + procedures: { + 'user.cart.getCartSlots': { + [PRODUCT_ID]: [futureSlot(), otherFutureSlot()], + }, + }, + }) + await seedCart([ + cartItem({ id: 1, slotId: SLOT_ID }), + cartItem({ id: 2, slotId: OTHER_SLOT_ID }), + ]) + + renderWithProviders() + await waitFor(() => + expect(screen.getAllByText('Chicken Breast 500 g').length).toBeGreaterThan(0) + ) + + await waitFor(() => expect(screen.getByTestId('delivery-slot-merge')).toBeVisible()) + expect(screen.getByText(/Deliver All items at/)).toBeVisible() + expect(screen.getByTestId('delivery-slot-merge-apply')).toBeVisible() + + fireEvent.press(screen.getByTestId('delivery-slot-merge-apply')) + + // Merging onto one slot keeps the banner but removes the apply button. + await waitFor(() => expect(screen.queryByTestId('delivery-slot-merge-apply')).toBeNull()) + expect(screen.getByTestId('delivery-slot-merge')).toBeVisible() + }) + + it('shows the merge banner without the apply button when one item cannot use the majority slot', async () => { + setupApiMocks({ + procedures: { + 'user.cart.getCartSlots': { + [PRODUCT_ID]: [futureSlot(), otherFutureSlot()], + [OTHER_PRODUCT_ID]: [otherFutureSlot()], + }, + }, + }) + // Majority (lowest id) is SLOT_ID, which OTHER_PRODUCT_ID cannot use. + await seedCart([ + cartItem({ id: 1, slotId: SLOT_ID }), + cartItem({ id: 2, skuId: OTHER_PRODUCT_ID, slotId: OTHER_SLOT_ID }), + ]) + + renderWithProviders() + await waitFor(() => expect(screen.getByTestId('delivery-slot-merge')).toBeVisible()) + expect(screen.getByText(/Deliver All items at/)).toBeVisible() + expect(screen.queryByTestId('delivery-slot-merge-apply')).toBeNull() + }) + + it('shows the merge banner without the apply button when only one slot is selected', async () => { + setupApiMocks({ + procedures: { 'user.cart.getCartSlots': { [PRODUCT_ID]: [futureSlot()] } }, + }) + await seedCart([cartItem()]) + + renderWithProviders() + await waitFor(() => expect(screen.getByText('Chicken Breast 500 g')).toBeVisible()) + + await waitFor(() => expect(screen.getByTestId('delivery-slot-merge')).toBeVisible()) + expect(screen.getByText(/Deliver All items at/)).toBeVisible() + expect(screen.queryByTestId('delivery-slot-merge-apply')).toBeNull() + }) + it('renders the flash cart variant without slot selection', async () => { setupApiMocks() await StorageServiceCasual.setItem( diff --git a/change-log.txt b/change-log.txt index 4cdd24a..587717b 100644 --- a/change-log.txt +++ b/change-log.txt @@ -3610,3 +3610,114 @@ longer exports it. Pre-existing regression surfaced while running the suite after the BASE_API_URL move; the dashboard-hub tests expect 'Manage Orders'. Unrelated to the URL change. + +[2026-10-02 00:28:44] user-ui: floating cart bar 'Go to Cart' button -> stacked 'Go to' / 'Cart'. + +apps/user-ui/components/floating-cart-bar.tsx, collapsed-view button only: + -Go to Cart + + + + Go to + + Cart + + + +[2026-10-02 00:31:53] user-ui: add WhatsApp contact button beside the floating cart bar. + +apps/user-ui/components/floating-cart-bar.tsx + - wrap the collapsed bar in a flex-row; cart bar becomes flex-1 and a compact + green WhatsApp button sits to its right (ml-2), splitting the width. + - the button opens whatsapp://send?phone=, + normalising to a 10-digit number + '91' country code. Hidden when supportMobile + is empty or while the bar is expanded. + - imports: MaterialCommunityIcons (whatsapp glyph), expo-linking (openURL). + +[2026-10-02 00:33:24] user-ui: floating cart bar WhatsApp button -> icon only (drop 'Chat' label). + +[2026-10-02 00:36:40] user-ui: remove the WhatsApp support button from floating-cart-bar. + +Reverts the split-row addition: cart bar back to full width; drops the +expo-linking / MaterialCommunityIcons imports, supportMobile handler and flex wrapper. + +[2026-10-02 01:08:09] user-ui: NextOrderGlimpse - hide the status badge for Confirmed/Packaged. + +OrderCard now computes statusLabel = orderStatusManipulator(deliveryStatus) and +omits the white status pill when the label is 'confirmed' or 'packaged'. + +[2026-10-02 01:09:18] user-ui: NextOrderGlimpse - move delivery time into the top-right (status spot). + +OrderCard: hoisted the delivery-time string into `deliveryTimeText`; the top row's +right column now shows the schedule/bolt + time (status pill, when visible, sits +under it). Removed the standalone delivery-time row below the header. + +[2026-10-02 01:10:07] user-ui: NextOrderGlimpse - restyle the top-right delivery time as a 2-row pill. + +Split deliveryTimeText into deliveryDateLabel (row 1: 'DD MMM' / '30-Min') and +deliveryTimeLabel (row 2: 'hh:mm A - hh:mm A' / 'Delivery'); wrapped in a white +rounded-2xl amber-border pill with the schedule/bolt icon. + +[2026-10-02 01:12:05] user-ui: home - move NextOrderGlimpse above the tag tab strip. + +app/(drawer)/(tabs)/home/index.tsx ListHeader: NextOrderGlimpse removed from the +white stores/slots section and rendered first, before . + +[2026-10-02 01:13:17] user-ui: NextOrderGlimpse - give the delivery TIME more emphasis than the date. + +Swapped the pill labels so the primary line is the time range ('hh:mm A - hh:mm A', +or '30-Min' for flash) and the secondary line is the date ('DD MMM', or 'Delivery'). +Primary: text-[13px] font-black text-amber-900; secondary: text-[9px] font-semibold text-amber-500. + +[2026-10-02 01:14:27] user-ui: NextOrderGlimpse - don't repeat AM/PM when both times share the period. + +Time range now renders '06:00 - 07:00 PM' when start/end period match, and +'11:00 AM - 12:00 PM' when they differ. + +[2026-10-02 01:15:44] user-ui: NextOrderGlimpse - remove the 'Track Order' row; whole card already navigates. + +Dropped the bordered item-thumbnails / 'Track Order' / chevron block. The card's +outer TouchableOpacity (onPress -> order detail) already covers the entire card. +Removed now-unused Ionicons and expo-image Image imports. + +[2026-10-02 01:18:56] user-ui: add OrderStatusTracker (3 dots: Placed / Packed / Delivered). + +New components/OrderStatusTracker.tsx: + - export deliveryStageIndex(deliveryStatus): pending/processing->0, packaged->1, + success/delivered->2, else 0. + - default export OrderStatusTracker { deliveryStatus, activeColor='#10B981', inactiveColor='#E2E8F0' }; + renders 3 dots joined by lines with labels; reached stages filled (activeColor), + later stages muted; cancelled -> all muted. +Rendered in: + - components/NextOrderGlimpse.tsx (OrderCard, amber palette) + - app/(drawer)/(tabs)/me/my-orders/[id].tsx (new 'Order Status' card) +Tests: updated stale next-order-glimpse assertions (status pill hidden; flash label split). + +[2026-10-02 01:21:25] user-ui: NextOrderGlimpse - add a top-right chevron indicating the card opens details. + +Header row right side now holds the FLASH badge (when present) plus a +chevron-right (MaterialIcons, #B45309) as the tap affordance. + +[2026-10-02 01:26:11] user-ui: cart-page - add a DeliverySlotSummary card before the checkout bar. + +components/cart-page.tsx: + - new in-file component DeliverySlotSummary { groups }: 'Delivery Slot' card + listing each selected slot with its time label and a clickable 'n items'; + tapping opens a BottomDialog listing that slot's items (image, name, unit, qty). + - formatDeliverySlot() helper; slotGroups useMemo groups cart lines by + selectedSlots[item.id] (non-flash only). + - rendered above the Bottom Checkout Bar (which holds Shop More / Checkout). + +[2026-10-02 01:33:44] user-ui: cart-page - 'Deliver All items at ' merge suggestion. + +components/cart-page.tsx: + - DeliverySlotSummary gains mergeSuggestion + onMerge props; below the rows it + always shows 'Deliver All items at