From a9c88e9ad7d2f1e11566f15d193879dfb010346a Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Sat, 24 Oct 2026 19:31:30 +0530 Subject: [PATCH] enh --- apps/user-ui/app/(drawer)/(tabs)/me/index.tsx | 41 ++++++- apps/user-ui/tests/pages/me-hub.test.tsx | 52 ++++++++- apps/web-ui/src/components/QrDownloadPage.tsx | 108 ++++++++++++++++++ apps/web-ui/src/routeTree.gen.ts | 42 +++++++ apps/web-ui/src/routes/me.tsx | 98 +++++++++++++--- apps/web-ui/src/routes/qr-based-download.tsx | 9 ++ apps/web-ui/src/routes/qr-download.tsx | 9 ++ change-log.txt | 65 +++++++++++ 8 files changed, 402 insertions(+), 22 deletions(-) create mode 100644 apps/web-ui/src/components/QrDownloadPage.tsx create mode 100644 apps/web-ui/src/routes/qr-based-download.tsx create mode 100644 apps/web-ui/src/routes/qr-download.tsx diff --git a/apps/user-ui/app/(drawer)/(tabs)/me/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/me/index.tsx index 8223d71..ef3713f 100644 --- a/apps/user-ui/app/(drawer)/(tabs)/me/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/me/index.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { View, ScrollView } from 'react-native'; +import { View, ScrollView, Linking } from 'react-native'; import { useRouter } from 'expo-router'; import { useFocusEffect } from '@react-navigation/native'; import { AppContainer, MyText, tw, MyTouchableOpacity, ProfileImage, colors } from 'common-ui'; @@ -11,6 +11,11 @@ import AddressSwitcherSheet from '@/src/components/location/AddressSwitcherSheet import { useRegion } from '@/src/hooks/useRegion'; import { useAuth } from '@/src/contexts/AuthContext'; import { useNavigationTarget } from 'common-ui/hooks/useNavigationTarget'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; +import { isInNextOrderGlimpseWindow } from '@packages/shared'; +import { trpc } from '@/src/trpc-client'; +import { useUserDetails } from '@/src/contexts/AuthContext'; +import type { Order } from '@/src/types/orders'; export default function Me() { const router = useRouter(); @@ -18,6 +23,33 @@ export default function Me() { const { getNavigationTarget } = useNavigationTarget(); const [regionDialogOpen, setRegionDialogOpen] = useState(false); const { region: selectedRegion } = useRegion(); + // Same number the NextOrderGlimpse dials via tel: — Live Support opens it in WhatsApp. + const { data: essentialConsts } = useGetEssentialConsts(); + const supportMobile = essentialConsts?.supportMobile ?? null; + const waDigits = (supportMobile ?? '').replace(/\D/g, ''); + const waPhone = waDigits.length === 10 ? `91${waDigits}` : waDigits; + // Same upcoming orders the glimpse above shows; their ids prefill the message. + const userDetails = useUserDetails(); + const { data: ordersData } = trpc.user.order.getOrders.useQuery( + { page: 1, pageSize: 50 }, + { enabled: !!userDetails }, + ); + const upcomingIds = ((ordersData?.data as Order[] | undefined) ?? []) + .filter((order) => { + if (order.orderStatus.toLowerCase() === 'cancelled') return false; + if (order.deliveryStatus.toLowerCase() === 'success') return false; + return isInNextOrderGlimpseWindow(order); + }) + .map((order) => order.orderId) + .filter(Boolean); + const waText = upcomingIds.length > 0 ? `Hi, my orders are ${upcomingIds.join(', ')}` : null; + const openWhatsApp = () => { + if (!waPhone) return; + const url = waText + ? `whatsapp://send?phone=${waPhone}&text=${encodeURIComponent(waText)}` + : `whatsapp://send?phone=${waPhone}`; + Linking.openURL(url); + }; useFocusEffect(() => { const target = getNavigationTarget(); @@ -52,6 +84,13 @@ export default function Me() { onPress: () => router.push('/(drawer)/(tabs)/me/coupons'), subtitle: 'View active offers & rewards' }, + { + title: 'Live Support', + icon: 'logo-whatsapp', + color: '#25D366', + onPress: openWhatsApp, + subtitle: supportMobile ? `Chat on WhatsApp • ${supportMobile}` : 'Chat with us on WhatsApp' + }, ] }, { diff --git a/apps/user-ui/tests/pages/me-hub.test.tsx b/apps/user-ui/tests/pages/me-hub.test.tsx index 1d7f19b..16a57db 100644 --- a/apps/user-ui/tests/pages/me-hub.test.tsx +++ b/apps/user-ui/tests/pages/me-hub.test.tsx @@ -10,7 +10,7 @@ * `common-ui/hooks/useNavigationTarget` singleton. */ import React from 'react' -import { Modal } from 'react-native' +import { Linking, Modal } from 'react-native' import { act, fireEvent, render, waitFor } from '@testing-library/react-native' import { useNavigationTarget } from 'common-ui/hooks/useNavigationTarget' @@ -18,9 +18,10 @@ import Me from '@/app/(drawer)/(tabs)/me/index' import { flush, renderWithProviders, seedRegion } from '../helpers/test-utils' import { resetAllMocks } from '../helpers/reset' +import { setProcedure } from '../mocks/trpc-client' import { router } from '../mocks/expo-router-mock' import { __snapshot } from '../mocks/secure-store-mock' -import { REGION_1 } from '../fixtures' +import { CONSTS, REGION_1 } from '../fixtures' async function renderHub() { const view = renderWithProviders(, { auth: 'in' }) @@ -69,6 +70,7 @@ describe('Me hub (ME-01..ME-19)', () => { 'me-menu-addresses', 'me-menu-delivery-address', 'me-menu-profile-settings', + 'me-menu-live-support', 'me-menu-help-complaints', 'me-menu-terms-conditions', ] @@ -239,4 +241,50 @@ describe('Me hub (ME-01..ME-19)', () => { expect(view.getByTestId('me-version')).toBeTruthy() expect(view.getByText('Version 1.2.0 • Freshyo App')).toBeTruthy() }) + + it('ME-20: Live Support opens WhatsApp to the essential-consts support mobile', async () => { + seedRegion(REGION_1, 7) + const openURL = jest.spyOn(Linking, 'openURL').mockResolvedValue(true as any) + const view = await renderHub() + + expect(await view.findByText('Chat on WhatsApp • 8688182552')).toBeTruthy() + fireEvent.press(view.getByTestId('me-menu-live-support')) + + // Default fixtures leave O1/O2/O5/O6 upcoming (O3 cancelled, O4 delivered). + expect(openURL).toHaveBeenCalledWith( + 'whatsapp://send?phone=918688182552&text=Hi%2C%20my%20orders%20are%20ORD-1001%2C%20ORD-1002%2C%20ORD-1005%2C%20ORD-1006' + ) + + // Placed directly below the Coupons entry. + const tree = JSON.stringify(view.toJSON()) + expect(tree.indexOf('me-menu-live-support')).toBeGreaterThan(tree.indexOf('me-menu-coupons')) + }) + + it('ME-21: Live Support is a no-op when the support mobile is missing', async () => { + seedRegion(REGION_1, 7) + setProcedure('common.essentialConsts', { + data: { ...CONSTS, supportMobile: null }, + }) + const openURL = jest.spyOn(Linking, 'openURL').mockResolvedValue(true as any) + const view = await renderHub() + + expect(view.getByText('Chat with us on WhatsApp')).toBeTruthy() + fireEvent.press(view.getByTestId('me-menu-live-support')) + + expect(openURL).not.toHaveBeenCalled() + }) + + it('ME-22: with no upcoming orders Live Support opens WhatsApp without a message', async () => { + seedRegion(REGION_1, 7) + setProcedure('user.order.getOrders', { + data: { data: [], pagination: { totalPages: 1, total: 0, page: 1, pageSize: 50 } }, + }) + const openURL = jest.spyOn(Linking, 'openURL').mockResolvedValue(true as any) + const view = await renderHub() + + expect(await view.findByText('Chat on WhatsApp • 8688182552')).toBeTruthy() + fireEvent.press(view.getByTestId('me-menu-live-support')) + + expect(openURL).toHaveBeenCalledWith('whatsapp://send?phone=918688182552') + }) }) diff --git a/apps/web-ui/src/components/QrDownloadPage.tsx b/apps/web-ui/src/components/QrDownloadPage.tsx new file mode 100644 index 0000000..2a514a5 --- /dev/null +++ b/apps/web-ui/src/components/QrDownloadPage.tsx @@ -0,0 +1,108 @@ +import React, { useEffect } from 'react' +import { Link } from '@tanstack/react-router' + +/** + * Port of apps/info-site/views/qr-download.pug: the QR-based download page. + * Same store URLs, same user-agent auto-redirect, same three option cards + * with the same glyphs and click handlers that assign window.location.href. + */ + +export const ANDROID_URL = + 'intent://play.google.com/store/apps/details?id=in.freshyo.app#Intent;scheme=https;package=com.android.vending;end;' +export const IOS_URL = 'https://apps.apple.com/in/app/freshyo/id6756889077' +export const BROWSER_URL = 'https://app.freshyo.in' + +function detectOS(): 'android' | 'ios' | 'unknown' { + if (typeof navigator === 'undefined') return 'unknown' + const userAgent = navigator.userAgent || (navigator as any).vendor || (window as any).opera + if (/android/i.test(userAgent)) return 'android' + if (/iPad|iPhone|iPod/.test(userAgent) && !(window as any).MSStream) return 'ios' + return 'unknown' +} + +export function QrDownloadPage() { + // Same as the info-site's window-load redirect: android/ios go straight to + // their store; anything else stays so the user can pick. + useEffect(() => { + const os = detectOS() + if (os === 'android') window.location.href = ANDROID_URL + else if (os === 'ios') window.location.href = IOS_URL + }, []) + + const go = (url: string) => (e: React.MouseEvent) => { + e.preventDefault() + window.location.href = url + } + + return ( +
+
+ + ← Back to Home + + + Freshyo +

Download Freshyo

+

Freshness Delivered, Smiles Picked Up

+

Choose your platform to get started

+ +
+ + + + + + + + Android + Google Play Store + + + + + + + + + + + iOS + Apple App Store + + + + + + + + + + + + + Use in Browser + No download required + + +
+ +

Not redirected? Tap an option above

+
+
+ ) +} diff --git a/apps/web-ui/src/routeTree.gen.ts b/apps/web-ui/src/routeTree.gen.ts index 7111a30..a2b5f89 100644 --- a/apps/web-ui/src/routeTree.gen.ts +++ b/apps/web-ui/src/routeTree.gen.ts @@ -12,6 +12,8 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as StoresRouteImport } from './routes/stores' import { Route as SlotViewRouteImport } from './routes/slot-view' import { Route as RegisterRouteImport } from './routes/register' +import { Route as QrDownloadRouteImport } from './routes/qr-download' +import { Route as QrBasedDownloadRouteImport } from './routes/qr-based-download' import { Route as OffersRouteImport } from './routes/offers' import { Route as MeRouteImport } from './routes/me' import { Route as LoginRouteImport } from './routes/login' @@ -57,6 +59,16 @@ const RegisterRoute = RegisterRouteImport.update({ path: '/register', getParentRoute: () => rootRouteImport, } as any) +const QrDownloadRoute = QrDownloadRouteImport.update({ + id: '/qr-download', + path: '/qr-download', + getParentRoute: () => rootRouteImport, +} as any) +const QrBasedDownloadRoute = QrBasedDownloadRouteImport.update({ + id: '/qr-based-download', + path: '/qr-based-download', + getParentRoute: () => rootRouteImport, +} as any) const OffersRoute = OffersRouteImport.update({ id: '/offers', path: '/offers', @@ -214,6 +226,8 @@ export interface FileRoutesByFullPath { '/login': typeof LoginRoute '/me': typeof MeRouteWithChildren '/offers': typeof OffersRoute + '/qr-based-download': typeof QrBasedDownloadRoute + '/qr-download': typeof QrDownloadRoute '/register': typeof RegisterRoute '/slot-view': typeof SlotViewRoute '/stores': typeof StoresRouteWithChildren @@ -247,6 +261,8 @@ export interface FileRoutesByTo { '/login': typeof LoginRoute '/me': typeof MeRouteWithChildren '/offers': typeof OffersRoute + '/qr-based-download': typeof QrBasedDownloadRoute + '/qr-download': typeof QrDownloadRoute '/register': typeof RegisterRoute '/slot-view': typeof SlotViewRoute '/stores': typeof StoresRouteWithChildren @@ -282,6 +298,8 @@ export interface FileRoutesById { '/login': typeof LoginRoute '/me': typeof MeRouteWithChildren '/offers': typeof OffersRoute + '/qr-based-download': typeof QrBasedDownloadRoute + '/qr-download': typeof QrDownloadRoute '/register': typeof RegisterRoute '/slot-view': typeof SlotViewRoute '/stores': typeof StoresRouteWithChildren @@ -318,6 +336,8 @@ export interface FileRouteTypes { | '/login' | '/me' | '/offers' + | '/qr-based-download' + | '/qr-download' | '/register' | '/slot-view' | '/stores' @@ -351,6 +371,8 @@ export interface FileRouteTypes { | '/login' | '/me' | '/offers' + | '/qr-based-download' + | '/qr-download' | '/register' | '/slot-view' | '/stores' @@ -385,6 +407,8 @@ export interface FileRouteTypes { | '/login' | '/me' | '/offers' + | '/qr-based-download' + | '/qr-download' | '/register' | '/slot-view' | '/stores' @@ -420,6 +444,8 @@ export interface RootRouteChildren { LoginRoute: typeof LoginRoute MeRoute: typeof MeRouteWithChildren OffersRoute: typeof OffersRoute + QrBasedDownloadRoute: typeof QrBasedDownloadRoute + QrDownloadRoute: typeof QrDownloadRoute RegisterRoute: typeof RegisterRoute SlotViewRoute: typeof SlotViewRoute StoresRoute: typeof StoresRouteWithChildren @@ -448,6 +474,20 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof RegisterRouteImport parentRoute: typeof rootRouteImport } + '/qr-download': { + id: '/qr-download' + path: '/qr-download' + fullPath: '/qr-download' + preLoaderRoute: typeof QrDownloadRouteImport + parentRoute: typeof rootRouteImport + } + '/qr-based-download': { + id: '/qr-based-download' + path: '/qr-based-download' + fullPath: '/qr-based-download' + preLoaderRoute: typeof QrBasedDownloadRouteImport + parentRoute: typeof rootRouteImport + } '/offers': { id: '/offers' path: '/offers' @@ -757,6 +797,8 @@ const rootRouteChildren: RootRouteChildren = { LoginRoute: LoginRoute, MeRoute: MeRouteWithChildren, OffersRoute: OffersRoute, + QrBasedDownloadRoute: QrBasedDownloadRoute, + QrDownloadRoute: QrDownloadRoute, RegisterRoute: RegisterRoute, SlotViewRoute: SlotViewRoute, StoresRoute: StoresRouteWithChildren, diff --git a/apps/web-ui/src/routes/me.tsx b/apps/web-ui/src/routes/me.tsx index 5115b78..8ad4b7b 100644 --- a/apps/web-ui/src/routes/me.tsx +++ b/apps/web-ui/src/routes/me.tsx @@ -14,12 +14,16 @@ import { Globe, User, MessageSquare, + MessageCircle, FileText, LogOut, ChevronRight, Settings, } from 'lucide-react' import React, { useState } from 'react' +import { useGetEssentialConsts } from '../hooks/prominent-api-hooks' +import { isInNextOrderGlimpseWindow } from '@packages/shared' +import { trpc } from '../lib/trpc-client' export const Route = createFileRoute('/me')({ component: MePage }) @@ -27,7 +31,8 @@ interface MenuItem { title: string icon: React.ComponentType<{ size?: number | string; color?: string }> color: string - to: string + to?: string + href?: string subtitle: string } @@ -54,6 +59,30 @@ function MePage() { const [regionDialogOpen, setRegionDialogOpen] = useState(false) const selectedRegion = useRegionStore((state) => state.selectedRegion) const selectedRegionId = useRegionStore((state) => state.selectedRegionId) + // Same number the NextOrderGlimpse dials via tel: — Live Support opens it in WhatsApp. + const { data: essentialConsts } = useGetEssentialConsts() + const supportMobile = (essentialConsts as any)?.supportMobile ?? null + const waDigits = String(supportMobile ?? '').replace(/\D/g, '') + const waPhone = waDigits.length === 10 ? `91${waDigits}` : waDigits + // Same upcoming orders the glimpse above shows; their ids prefill the message. + const { data: ordersData } = trpc.user.order.getOrders.useQuery( + { page: 1, pageSize: 50 }, + { enabled: !!user } + ) + const upcomingIds: string[] = ((ordersData as any)?.data ?? []) + .filter((order: any) => { + if (String(order.orderStatus).toLowerCase() === 'cancelled') return false + if (String(order.deliveryStatus).toLowerCase() === 'success') return false + return isInNextOrderGlimpseWindow(order) + }) + .map((order: any) => order.orderId) + .filter(Boolean) + const waText = upcomingIds.length > 0 ? `Hi, my orders are ${upcomingIds.join(', ')}` : null + const waHref = waPhone + ? waText + ? `https://wa.me/${waPhone}?text=${encodeURIComponent(waText)}` + : `https://wa.me/${waPhone}` + : undefined // Check if we're on the exact /me path (not a child route like /me/orders) const isExactMePath = location.pathname === '/me' @@ -98,6 +127,19 @@ function MePage() { to: '/me/coupons', subtitle: 'View active offers & rewards', }, + ...(waHref + ? [ + { + title: 'Live Support', + icon: MessageCircle, + color: '#25D366', + href: waHref, + subtitle: supportMobile + ? `Chat on WhatsApp • ${supportMobile}` + : 'Chat with us on WhatsApp', + } as MenuItem, + ] + : []), ], }, { @@ -168,24 +210,42 @@ function MePage() { {section.title}

- {section.items.map((item, iIndex) => ( - - ))} + {section.items.map((item, iIndex) => { + const rowClass = `flex w-full flex-row items-center p-4 text-left transition-colors hover:bg-gray-50 ${ + iIndex !== section.items.length - 1 ? 'border-b border-gray-50' : '' + }` + const rowContent = ( + <> + +
+

{item.title}

+

{item.subtitle}

+
+
+ +
+ + ) + return item.href ? ( + + {rowContent} + + ) : ( + + ) + })}
))} diff --git a/apps/web-ui/src/routes/qr-based-download.tsx b/apps/web-ui/src/routes/qr-based-download.tsx new file mode 100644 index 0000000..987a431 --- /dev/null +++ b/apps/web-ui/src/routes/qr-based-download.tsx @@ -0,0 +1,9 @@ +import { createFileRoute } from '@tanstack/react-router' +import { QrDownloadPage } from '../components/QrDownloadPage' + +export const Route = createFileRoute('/qr-based-download')({ + head: () => ({ + meta: [{ title: 'Freshyo - Download App' }], + }), + component: QrDownloadPage, +}) diff --git a/apps/web-ui/src/routes/qr-download.tsx b/apps/web-ui/src/routes/qr-download.tsx new file mode 100644 index 0000000..46863b5 --- /dev/null +++ b/apps/web-ui/src/routes/qr-download.tsx @@ -0,0 +1,9 @@ +import { createFileRoute } from '@tanstack/react-router' +import { QrDownloadPage } from '../components/QrDownloadPage' + +export const Route = createFileRoute('/qr-download')({ + head: () => ({ + meta: [{ title: 'Freshyo - Download App' }], + }), + component: QrDownloadPage, +}) diff --git a/change-log.txt b/change-log.txt index 7071194..c0928bc 100644 --- a/change-log.txt +++ b/change-log.txt @@ -9431,3 +9431,68 @@ No migration needed; the rows and defaults are unchanged. + it('SREG-11b (regression): a region with 17 bounds creates and seeds every bound', ...) + // 6 bounds overflowed the old 120-param settings insert; 17 also splits the + // region_bounds insert. Asserts 17 bounds and 5 settings on each. + +[2026-10-24 19:05 IST] user-ui + web-ui: Me hub "Live Support" WhatsApp entry (same supportMobile as NextOrderGlimpse). +Same number the glimpse dials via tel: now also opens WhatsApp: RN Linking.openURL +whatsapp://send?phone=; web opens https://wa.me/. +Ionicons logo-whatsapp (#25D366) on native, MessageCircle (#25D366) on web (no brand +glyph in lucide). Guarded no-op when supportMobile is missing. + +--- a/apps/user-ui/app/(drawer)/(tabs)/me/index.tsx ++++ b/apps/user-ui/app/(drawer)/(tabs)/me/index.tsx +@@ imports ++import { Linking } from 'react-native' ++import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks' +@@ component ++ const { data: essentialConsts } = useGetEssentialConsts() ++ const supportMobile = essentialConsts?.supportMobile ?? null ++ const digits = (supportMobile ?? '').replace(/\D/g, '') ++ const waPhone = digits.length === 10 ? `91${digits}` : digits ++ const openWhatsApp = () => { if (waPhone) Linking.openURL(`whatsapp://send?phone=${waPhone}`) } +@@ Support section items ++ { title: 'Live Support', icon: 'logo-whatsapp', color: '#25D366', ++ onPress: openWhatsApp, ++ subtitle: supportMobile ? `Chat on WhatsApp • ${supportMobile}` : 'Chat with us on WhatsApp' }, + +--- a/apps/web-ui/src/routes/me.tsx ++++ b/apps/web-ui/src/routes/me.tsx +@@ imports ++import { MessageCircle } from 'lucide-react' ++import { useGetEssentialConsts } from '../hooks/prominent-api-hooks' +@@ MenuItem type +- to: string ++ to?: string; href?: string +@@ render ++ {item.href ? … : } +@@ Support section items ++ { title: 'Live Support', icon: MessageCircle, color: '#25D366', ++ href: https://wa.me/, subtitle: same as native }, + +--- a/apps/user-ui/tests/pages/me-hub.test.tsx ++++ b/apps/user-ui/tests/pages/me-hub.test.tsx +@@ ME-01 entries ++ 'me-menu-live-support', +@@ new rows ++ ME-20: Live Support opens WhatsApp to the essential-consts support mobile ++ (whatsapp://send?phone=918688182552; no-op when missing). + +[2026-10-24 19:12 IST] web-ui: add /qr-based-download and /qr-download routes (port of info-site qr-download page). +Same URLs, same UA-sniff auto-redirect on mount (android -> intent://, ios -> App Store, +otherwise stay), same three option cards with the same SVG glyphs and click handlers that +assign window.location.href. Shared component so both paths render identically; standalone +page (no AppLayout shell). No user-ui counterpart (new web surface, no RN equivalent); +no tests (web-ui has no test runner). + +[2026-10-24 19:18 IST] Me hub: move Live Support directly below the Coupons entry +(user-ui + web-ui). Same WhatsApp handler, icon and subtitle; only the position changed +(Shopping & Activity section, after Coupons) instead of first in Support. + +[2026-10-24 19:20 IST] Me hub Live Support prefills the WhatsApp message with the glimpse's +upcoming order ids ("Hi, my orders are , \n", URL-encoded as &text=). Same +upcoming filter as NextOrderGlimpse (not cancelled/success, in glimpse window); no ids -> +opens WhatsApp without text. user-ui uses whatsapp://send, web uses https://wa.me/. + +[2026-10-24 19:26 IST] Drop the trailing newline from the Live Support prefill (message now +ends with the last order id). WhatsApp exposes no caret parameter; the trailing newline +was the likely cause of the caret landing at position 0 after its whitespace +normalization. user-ui + web-ui + ME-20 expectation updated.