From a09ae70b9fbc4cb244e462d4312884b1a39e8dea Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Sun, 8 Nov 2026 15:43:46 +0530 Subject: [PATCH] enh --- .../location/neo/NeoAddressFlow.tsx | 70 ++++++--- .../location/neo/NeoLocationNotice.tsx | 146 ++++++++++++++++++ apps/user-ui/src/hooks/useRegionNeo.ts | 17 +- apps/user-ui/src/store/neoRegionStore.ts | 6 + .../components/neo-address-flow.test.tsx | 66 ++++++++ apps/user-ui/tests/helpers/reset.ts | 1 + change-log.txt | 58 +++++++ packages/shared/index.ts | 1 + 8 files changed, 340 insertions(+), 25 deletions(-) create mode 100644 apps/user-ui/src/components/location/neo/NeoLocationNotice.tsx create mode 100644 apps/user-ui/tests/components/neo-address-flow.test.tsx diff --git a/apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx b/apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx index 39971e1..c09dc30 100644 --- a/apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx +++ b/apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx @@ -1,24 +1,26 @@ import React, { useEffect, useRef, useState } from 'react' import { ScrollView, View } from 'react-native' import MaterialIcons from '@expo/vector-icons/MaterialIcons' -import { MyText, MyTouchableOpacity, tw } from 'common-ui' +import { MyButton, MyText, MyTouchableOpacity, tw } from 'common-ui' import Login from '@/app/(auth)/login' import { useAuthOptional } from '@/src/contexts/AuthContext' import { useLocationStore } from '@/src/store/locationStore' import { useNeoRegionStore } from '@/src/store/neoRegionStore' import { formatNeoAddress } from '@/src/lib/neo-address' import NeoAddressForm from './NeoAddressForm' +import NeoLocationNotice, { type NeoLocationNoticeKind } from './NeoLocationNotice' interface NeoAddressFlowProps { /** Present when hosted in the location-bar sheet. */ onClose?: () => void } -const NOTICE: Partial> = { - denied: 'Location access is not granted. Allow it for accurate delivery, or add an address below.', - 'services-off': 'Your device location is turned off. Turn it on, or add an address below.', - unavailable: 'We could not get your location. Try again, or add an address below.', - error: 'We could not get your location. Try again, or add an address below.', +/** Location statuses that explain the flow in the notice card. */ +const STATUS_NOTICE_KIND: Partial> = { + denied: 'denied', + 'services-off': 'services-off', + unavailable: 'unavailable', + error: 'unavailable', } /** @@ -33,6 +35,7 @@ const NeoAddressFlow: React.FC = ({ onClose }) => { const selectedAddressId = useNeoRegionStore((state) => state.selectedAddressId) const closeAddressFlow = useNeoRegionStore((state) => state.closeAddressFlow) const selectAddress = useNeoRegionStore((state) => state.selectAddress) + const deviceOutOfService = useNeoRegionStore((state) => state.deviceOutOfService) const locationStatus = useLocationStore((state) => state.status) const [mode, setMode] = useState<'choose' | 'add' | 'login'>('choose') @@ -67,6 +70,16 @@ const NeoAddressFlow: React.FC = ({ onClose }) => { onClose?.() } + // An out-of-area device fix is worth explaining even when a cached region is + // already published (the sheet case). A live permission/services notice is + // more current, so it wins while there is no region. + let noticeKind: NeoLocationNoticeKind | null = null + if (regionId == null && STATUS_NOTICE_KIND[locationStatus] != null) { + noticeKind = STATUS_NOTICE_KIND[locationStatus] ?? null + } else if (deviceOutOfService) { + noticeKind = 'out-of-area' + } + if (mode === 'add') { return ( @@ -79,6 +92,9 @@ const NeoAddressFlow: React.FC = ({ onClose }) => { Back + {noticeKind != null && ( + + )} { closeAddressFlow() @@ -129,10 +145,8 @@ const NeoAddressFlow: React.FC = ({ onClose }) => { )} - {NOTICE[locationStatus] && regionId == null && ( - - {NOTICE[locationStatus]} - + {noticeKind != null && ( + )} @@ -179,24 +193,34 @@ const NeoAddressFlow: React.FC = ({ onClose }) => { )} - setMode('add')} - activeOpacity={0.85} - style={tw`mt-2 bg-indigo-600 py-3.5 rounded-xl items-center`} + style={tw`mt-2`} > - Add new address - + Add new address + {!isAuthenticated && ( - setMode('login')} - activeOpacity={0.85} - style={tw`mt-3 border border-gray-200 py-3.5 rounded-xl items-center`} - > - Sign in to save your address - + <> + setMode('login')} + style={tw`mt-3`} + > + Sign In + + + Sign in to use saved addresses + + )} diff --git a/apps/user-ui/src/components/location/neo/NeoLocationNotice.tsx b/apps/user-ui/src/components/location/neo/NeoLocationNotice.tsx new file mode 100644 index 0000000..97cad18 --- /dev/null +++ b/apps/user-ui/src/components/location/neo/NeoLocationNotice.tsx @@ -0,0 +1,146 @@ +import React from 'react' +import type { StyleProp, ViewStyle } from 'react-native' +import { View } from 'react-native' +import Svg, { Circle, Path } from 'react-native-svg' +import { MyText, tw } from 'common-ui' + +/** Why the address flow is asking for an address instead of using the device. */ +export type NeoLocationNoticeKind = + | 'out-of-area' + | 'denied' + | 'services-off' + | 'unavailable' + +interface NeoLocationNoticeProps { + kind: NeoLocationNoticeKind + style?: StyleProp +} + +const COPY: Record = { + 'out-of-area': { + title: 'Outside delivery area', + message: + 'Your current location is outside our delivery area. Choose a saved address, or add one inside a serviceable area.', + }, + denied: { + title: 'Location access is off', + message: + 'Location access is not granted. Allow it for accurate delivery, or add an address below.', + }, + 'services-off': { + title: 'Device location is off', + message: 'Your device location is turned off. Turn it on, or add an address below.', + }, + unavailable: { + title: 'Location unavailable', + message: 'We could not get your location. Try again, or add an address below.', + }, +} + +const AMBER_100 = '#FEF3C7' +const AMBER_300 = '#FCD34D' +const AMBER_600 = '#D97706' +const AMBER_700 = '#B45309' + +/** + * The badge on the pin carries the reason: a cross for "outside the area", a + * slash for "permission/services", an exclamation for "couldn't get a fix". + */ +function NoticeBadge({ kind }: { kind: NeoLocationNoticeKind }) { + if (kind === 'denied' || kind === 'services-off') { + return ( + + ) + } + + if (kind === 'unavailable') { + return ( + <> + + + + ) + } + + return ( + <> + + + + ) +} + +/** Inline illustration: a map pin with a dashed coverage ring and a reason badge. */ +function LocationNoticeArtwork({ kind }: { kind: NeoLocationNoticeKind }) { + return ( + + + + + {/* The pin itself: white body, amber outline, amber dot. */} + + + + {/* Reason badge, bottom-right. */} + + + + ) +} + +/** + * The reason the address flow is up, as a graphic card: an inline SVG + * illustration plus a title and the supporting sentence. + */ +const NeoLocationNotice: React.FC = ({ kind, style }) => { + const copy = COPY[kind] + + return ( + + + + + + + + {copy.title} + + {copy.message} + + + + ) +} + +export default NeoLocationNotice diff --git a/apps/user-ui/src/hooks/useRegionNeo.ts b/apps/user-ui/src/hooks/useRegionNeo.ts index 709e51b..dbb9417 100644 --- a/apps/user-ui/src/hooks/useRegionNeo.ts +++ b/apps/user-ui/src/hooks/useRegionNeo.ts @@ -179,13 +179,19 @@ export function useNeoRegionBootstrap(): void { const run = async () => { const fix = useLocationStore.getState().coords - // The snapshot read and the coordinate resolve are independent. + // The snapshot read and the coordinate resolve are independent. A network + // failure is not "out of area", so it is tracked separately: only a + // successful resolve that returns no region means the fix is unserviceable. + let resolveFailed = false const [snapshot, resolveResult] = await Promise.all([ snapshotRead ?? readNeoRegionSnapshot(), fix != null ? utils.common.resolveRegionByLocation .fetch({ lat: fix.latitude, lng: fix.longitude }) - .catch(() => null) + .catch(() => { + resolveFailed = true + return null + }) : Promise.resolve(null), ]) @@ -242,6 +248,13 @@ export function useNeoRegionBootstrap(): void { } } + // A fix that resolves to nothing is "outside the delivery area": the + // address flow says why instead of only asking for an address. A failed + // resolve (offline) leaves it unknown. + useNeoRegionStore + .getState() + .setDeviceOutOfService(fix != null && !resolveFailed && resolveResult == null) + const decision = decideNeoRegion({ cached, fix, diff --git a/apps/user-ui/src/store/neoRegionStore.ts b/apps/user-ui/src/store/neoRegionStore.ts index d633825..d710202 100644 --- a/apps/user-ui/src/store/neoRegionStore.ts +++ b/apps/user-ui/src/store/neoRegionStore.ts @@ -43,6 +43,8 @@ interface NeoRegionState { needsAddressFormFlow: boolean needsAddressConfirmation: boolean + /** A device fix exists but resolves outside every serviceable bound. */ + deviceOutOfService: boolean applyRegion: (data: ApplyRegionInput) => void setRegions: (regions: RegionSummary[]) => void @@ -51,6 +53,7 @@ interface NeoRegionState { openAddressFlow: () => void closeAddressFlow: () => void setNeedsConfirmation: (value: boolean) => void + setDeviceOutOfService: (value: boolean) => void resetForLogout: () => void changeRegion: (regionId: number, boundId?: number | null) => Promise @@ -83,6 +86,7 @@ export const useNeoRegionStore = create((set, get) => ({ needsAddressFormFlow: false, needsAddressConfirmation: false, + deviceOutOfService: false, /** * The only writer of the region fields. The selection is validated against @@ -174,6 +178,8 @@ export const useNeoRegionStore = create((set, get) => ({ ...(value ? { needsAddressFormFlow: false } : null), }), + setDeviceOutOfService: (value) => set({ deviceOutOfService: value }), + resetForLogout: () => set({ addresses: [], diff --git a/apps/user-ui/tests/components/neo-address-flow.test.tsx b/apps/user-ui/tests/components/neo-address-flow.test.tsx new file mode 100644 index 0000000..9724bce --- /dev/null +++ b/apps/user-ui/tests/components/neo-address-flow.test.tsx @@ -0,0 +1,66 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * NeoAddressFlow (`tests/components/neo-address-flow.test.tsx`). + * + * Covers the notice area above the address choices: an out-of-area device fix, + * the permission notices, and the "nothing to say" case. The chooser itself is + * the real component; the add form and the inline login screen are stubbed + * because they have their own suites and would pull in the map / auth stack. + */ +import * as React from 'react' + +import { resetAllMocks } from '../helpers/reset' +import { renderWithProviders } from '../helpers/test-utils' + +import { useLocationStore } from '@/src/store/locationStore' +import { useNeoRegionStore } from '@/src/store/neoRegionStore' + +jest.mock('@/src/components/location/neo/NeoAddressForm', () => ({ + __esModule: true, + default: () => null, +})) + +jest.mock('@/app/(auth)/login', () => ({ + __esModule: true, + default: () => null, +})) + +import NeoAddressFlow from '@/src/components/location/neo/NeoAddressFlow' + +describe('NeoAddressFlow — location notices', () => { + beforeEach(() => resetAllMocks()) + + it('NEOFLOW-01: an out-of-area fix is explained above the address choices', () => { + useNeoRegionStore.setState({ deviceOutOfService: true }) + + const { getByTestId, getByText } = renderWithProviders(, { auth: false }) + + expect(getByTestId('neo-location-notice')).toBeTruthy() + expect(getByText('Outside delivery area')).toBeTruthy() + expect(getByText(/outside our delivery area/)).toBeTruthy() + }) + + it('NEOFLOW-02: no out-of-area notice when the fix is serviceable', () => { + useNeoRegionStore.setState({ deviceOutOfService: false }) + + const { queryByText } = renderWithProviders(, { auth: false }) + + expect(queryByText(/outside our delivery area/)).toBeNull() + }) + + it('NEOFLOW-03: the permission notice still shows when there is no region', () => { + useNeoRegionStore.setState({ + regionId: null, + boundId: null, + regionName: null, + coords: null, + deviceOutOfService: false, + }) + useLocationStore.setState({ status: 'denied' }) + + const { getByText } = renderWithProviders(, { auth: false }) + + expect(getByText('Location access is off')).toBeTruthy() + expect(getByText(/Location access is not granted/)).toBeTruthy() + }) +}) diff --git a/apps/user-ui/tests/helpers/reset.ts b/apps/user-ui/tests/helpers/reset.ts index 31e8dad..5d0e657 100644 --- a/apps/user-ui/tests/helpers/reset.ts +++ b/apps/user-ui/tests/helpers/reset.ts @@ -69,6 +69,7 @@ export function resetStores() { selectedAddressId: null, needsAddressFormFlow: false, needsAddressConfirmation: false, + deviceOutOfService: false, }) useSlotStore.setState({ slotId: undefined, storeId: undefined }) useFlashNavigationStore.setState({ shouldNavigateToCart: false }) diff --git a/change-log.txt b/change-log.txt index 6cde9fe..643e649 100644 --- a/change-log.txt +++ b/change-log.txt @@ -1190,3 +1190,61 @@ race that leaves the app unresponsive on the cart page. + inline absolute-fill overlay with the same ActivityIndicator + message, inside the form's KeyboardAvoidingView; no second native modal, so nothing can be left behind when the host sheet closes. + +[2026-11-08 15:14:35 IST] add-address flow: explain when the device location is outside the delivery area. + +`resolveRegionByLocation` returning null is the only signal that the fix is +outside every serviceable bound, so the launch decision now records it. The +address flow reads that flag and shows a notice; previously the user only got +"add an address" with no reason (the location status is 'granted'). + +--- apps/user-ui/src/store/neoRegionStore.ts ++ deviceOutOfService: boolean + setDeviceOutOfService() +--- apps/user-ui/src/hooks/useRegionNeo.ts ++ distinguish a resolve failure (network) from a null resolve (out of area) ++ setDeviceOutOfService(fix != null && resolved to nothing && !resolveFailed) +--- apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx ++ "outside our delivery area" notice above the address choices and above the + add form; shown in the startup gate and in the location-bar sheet +--- apps/user-ui/tests/helpers/reset.ts ++ reset deviceOutOfService to false +--- apps/user-ui/tests/components/neo-address-flow.test.tsx (new) ++ out-of-area notice shown / not shown + +[2026-11-08 15:24:40 IST] address flow: make the location notice graphical. + +--- apps/user-ui/src/components/location/neo/NeoLocationNotice.tsx (new) ++ amber card: inline react-native-svg illustration (pin + dashed service ring + + badge) that varies by reason (out of area = x, permission = slash, no fix = !), + a bold title and the existing message copy. +--- apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx +~ replaces the plain text notice with in both the chooser + and the add form; the notice copy and precedence are unchanged. +--- apps/user-ui/tests/components/neo-address-flow.test.tsx ++ assert the notice title for the out-of-area case. + +[2026-11-08 15:31:44 IST] address flow buttons: theme-aligned Add New Address, shorter Sign In, login hint. + +--- apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx ++ use the shared MyButton for both actions (brand primary + outlined secondary) +- hand-rolled indigo TouchableOpacity for "Add new address" +~ sign-in label: "Sign in to save your address" -> "Sign In" ++ de-emphasised caption below it: "Login to use saved addresses" + +[2026-11-08 15:36:17 IST] address flow: bold the "Login to use saved addresses" hint. + +--- apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx +~ hint text: adds font-bold (stays small and gray, so it is still secondary) + +[2026-11-08 15:37:04 IST] address flow: bold the button labels (not the hint). + +--- apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx +~ Add New Address / Sign In pass a bold MyText as MyButton's child + (MyButton's textContent renders a regular-weight MyText, and labelStyle + cannot override MyText's own fontWeight) +~ the "Login to use saved addresses" hint goes back to regular weight + +[2026-11-08 15:37:21 IST] address flow: hint copy "Sign in to use saved addresses". + +--- apps/user-ui/src/components/location/neo/NeoAddressFlow.tsx +~ "Login to use saved addresses" -> "Sign in to use saved addresses" diff --git a/packages/shared/index.ts b/packages/shared/index.ts index 7a547a5..07f1184 100644 --- a/packages/shared/index.ts +++ b/packages/shared/index.ts @@ -7,6 +7,7 @@ export * from './region-cache-urls' */ export const BASE_API_URL = 'https://worker.freshyo.in' // export const BASE_API_URL = 'https://devapi.freshyo.in' +// export const BASE_API_URL = 'http://192.168.100.126:8787' // export const BASE_API_URL = 'https://devbackend.freshyo.in' // export const BASE_API_URL = 'https://192.168.100.126.nip.io:8787' // export const BASE_API_URL = 'http://192.168.1.5:8787'