This commit is contained in:
shafi54 2026-11-08 15:43:46 +05:30
parent 7a5fc0ff67
commit a09ae70b9f
8 changed files with 340 additions and 25 deletions

View file

@ -1,24 +1,26 @@
import React, { useEffect, useRef, useState } from 'react' import React, { useEffect, useRef, useState } from 'react'
import { ScrollView, View } from 'react-native' import { ScrollView, View } from 'react-native'
import MaterialIcons from '@expo/vector-icons/MaterialIcons' 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 Login from '@/app/(auth)/login'
import { useAuthOptional } from '@/src/contexts/AuthContext' import { useAuthOptional } from '@/src/contexts/AuthContext'
import { useLocationStore } from '@/src/store/locationStore' import { useLocationStore } from '@/src/store/locationStore'
import { useNeoRegionStore } from '@/src/store/neoRegionStore' import { useNeoRegionStore } from '@/src/store/neoRegionStore'
import { formatNeoAddress } from '@/src/lib/neo-address' import { formatNeoAddress } from '@/src/lib/neo-address'
import NeoAddressForm from './NeoAddressForm' import NeoAddressForm from './NeoAddressForm'
import NeoLocationNotice, { type NeoLocationNoticeKind } from './NeoLocationNotice'
interface NeoAddressFlowProps { interface NeoAddressFlowProps {
/** Present when hosted in the location-bar sheet. */ /** Present when hosted in the location-bar sheet. */
onClose?: () => void onClose?: () => void
} }
const NOTICE: Partial<Record<string, string>> = { /** Location statuses that explain the flow in the notice card. */
denied: 'Location access is not granted. Allow it for accurate delivery, or add an address below.', const STATUS_NOTICE_KIND: Partial<Record<string, NeoLocationNoticeKind>> = {
'services-off': 'Your device location is turned off. Turn it on, or add an address below.', denied: 'denied',
unavailable: 'We could not get your location. Try again, or add an address below.', 'services-off': 'services-off',
error: 'We could not get your location. Try again, or add an address below.', unavailable: 'unavailable',
error: 'unavailable',
} }
/** /**
@ -33,6 +35,7 @@ const NeoAddressFlow: React.FC<NeoAddressFlowProps> = ({ onClose }) => {
const selectedAddressId = useNeoRegionStore((state) => state.selectedAddressId) const selectedAddressId = useNeoRegionStore((state) => state.selectedAddressId)
const closeAddressFlow = useNeoRegionStore((state) => state.closeAddressFlow) const closeAddressFlow = useNeoRegionStore((state) => state.closeAddressFlow)
const selectAddress = useNeoRegionStore((state) => state.selectAddress) const selectAddress = useNeoRegionStore((state) => state.selectAddress)
const deviceOutOfService = useNeoRegionStore((state) => state.deviceOutOfService)
const locationStatus = useLocationStore((state) => state.status) const locationStatus = useLocationStore((state) => state.status)
const [mode, setMode] = useState<'choose' | 'add' | 'login'>('choose') const [mode, setMode] = useState<'choose' | 'add' | 'login'>('choose')
@ -67,6 +70,16 @@ const NeoAddressFlow: React.FC<NeoAddressFlowProps> = ({ onClose }) => {
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') { if (mode === 'add') {
return ( return (
<View style={tw`flex-1 bg-white`}> <View style={tw`flex-1 bg-white`}>
@ -79,6 +92,9 @@ const NeoAddressFlow: React.FC<NeoAddressFlowProps> = ({ onClose }) => {
<MaterialIcons name="arrow-back" size={22} color="#4B5563" /> <MaterialIcons name="arrow-back" size={22} color="#4B5563" />
<MyText style={tw`text-gray-600 ml-1`}>Back</MyText> <MyText style={tw`text-gray-600 ml-1`}>Back</MyText>
</MyTouchableOpacity> </MyTouchableOpacity>
{noticeKind != null && (
<NeoLocationNotice kind={noticeKind} style={tw`mx-5 mb-2`} />
)}
<NeoAddressForm <NeoAddressForm
onDone={() => { onDone={() => {
closeAddressFlow() closeAddressFlow()
@ -129,10 +145,8 @@ const NeoAddressFlow: React.FC<NeoAddressFlowProps> = ({ onClose }) => {
)} )}
</View> </View>
{NOTICE[locationStatus] && regionId == null && ( {noticeKind != null && (
<View style={tw`mt-4 bg-amber-50 border border-amber-200 rounded-xl p-3`}> <NeoLocationNotice kind={noticeKind} style={tw`mt-4`} />
<MyText style={tw`text-amber-800 text-sm`}>{NOTICE[locationStatus]}</MyText>
</View>
)} )}
<View style={tw`mt-6`}> <View style={tw`mt-6`}>
@ -179,24 +193,34 @@ const NeoAddressFlow: React.FC<NeoAddressFlowProps> = ({ onClose }) => {
)} )}
</View> </View>
<MyTouchableOpacity <MyButton
testID="neo-add-address" testID="neo-add-address"
fillColor="brand500"
textColor="white1"
fullWidth
onPress={() => setMode('add')} onPress={() => setMode('add')}
activeOpacity={0.85} style={tw`mt-2`}
style={tw`mt-2 bg-indigo-600 py-3.5 rounded-xl items-center`}
> >
<MyText style={tw`text-white font-bold`}>Add new address</MyText> <MyText weight="bold" color="white1">Add new address</MyText>
</MyTouchableOpacity> </MyButton>
{!isAuthenticated && ( {!isAuthenticated && (
<MyTouchableOpacity <>
testID="neo-location-login" <MyButton
onPress={() => setMode('login')} testID="neo-location-login"
activeOpacity={0.85} fillColor="white1"
style={tw`mt-3 border border-gray-200 py-3.5 rounded-xl items-center`} textColor="brand600"
> borderColor="brand200"
<MyText style={tw`text-gray-700 font-bold`}>Sign in to save your address</MyText> fullWidth
</MyTouchableOpacity> onPress={() => setMode('login')}
style={tw`mt-3`}
>
<MyText weight="bold" color="brand600">Sign In</MyText>
</MyButton>
<MyText style={tw`mt-2 text-center text-xs text-gray-400`}>
Sign in to use saved addresses
</MyText>
</>
)} )}
</ScrollView> </ScrollView>
</View> </View>

View file

@ -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<ViewStyle>
}
const COPY: Record<NeoLocationNoticeKind, { title: string; message: string }> = {
'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 (
<Path
d="M46.6 54.4 55.4 41.6"
stroke={AMBER_700}
strokeWidth={2.2}
strokeLinecap="round"
/>
)
}
if (kind === 'unavailable') {
return (
<>
<Path d="M51 43.5v6" stroke={AMBER_700} strokeWidth={2.2} strokeLinecap="round" />
<Circle cx={51} cy={53} r={1.4} fill={AMBER_700} />
</>
)
}
return (
<>
<Path
d="M48 45l6 6"
stroke={AMBER_700}
strokeWidth={2.2}
strokeLinecap="round"
/>
<Path
d="M54 45l-6 6"
stroke={AMBER_700}
strokeWidth={2.2}
strokeLinecap="round"
/>
</>
)
}
/** Inline illustration: a map pin with a dashed coverage ring and a reason badge. */
function LocationNoticeArtwork({ kind }: { kind: NeoLocationNoticeKind }) {
return (
<Svg width={64} height={64} viewBox="0 0 72 72" fill="none">
<Circle cx={36} cy={33} r={30} fill={AMBER_100} />
<Circle
cx={36}
cy={33}
r={24}
stroke={AMBER_300}
strokeWidth={1.5}
strokeDasharray="3 5"
/>
{/* The pin itself: white body, amber outline, amber dot. */}
<Path
d="M36 13.5c-7.9 0-14.3 6.3-14.3 14.1 0 10 11.2 20.4 13.4 22.3a1.4 1.4 0 0 0 1.8 0c2.2-1.9 13.4-12.3 13.4-22.3 0-7.8-6.4-14.1-14.3-14.1Z"
fill="#FFFFFF"
stroke={AMBER_600}
strokeWidth={2.2}
/>
<Circle cx={36} cy={27.6} r={4.6} fill={AMBER_600} />
{/* Reason badge, bottom-right. */}
<Circle cx={51} cy={48} r={9.5} fill="#FFFFFF" stroke={AMBER_600} strokeWidth={1.8} />
<NoticeBadge kind={kind} />
</Svg>
)
}
/**
* 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<NeoLocationNoticeProps> = ({ kind, style }) => {
const copy = COPY[kind]
return (
<View
testID="neo-location-notice"
accessibilityRole="alert"
style={[tw`bg-amber-50 border border-amber-200 rounded-2xl p-4`, style]}
>
<View style={tw`flex-row items-center`}>
<View style={tw`-ml-1`}>
<LocationNoticeArtwork kind={kind} />
</View>
<View style={tw`flex-1 ml-2`}>
<MyText weight="bold" style={tw`text-amber-900 text-base`}>
{copy.title}
</MyText>
<MyText style={tw`text-amber-800 text-sm mt-1 leading-5`}>{copy.message}</MyText>
</View>
</View>
</View>
)
}
export default NeoLocationNotice

View file

@ -179,13 +179,19 @@ export function useNeoRegionBootstrap(): void {
const run = async () => { const run = async () => {
const fix = useLocationStore.getState().coords 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([ const [snapshot, resolveResult] = await Promise.all([
snapshotRead ?? readNeoRegionSnapshot(), snapshotRead ?? readNeoRegionSnapshot(),
fix != null fix != null
? utils.common.resolveRegionByLocation ? utils.common.resolveRegionByLocation
.fetch({ lat: fix.latitude, lng: fix.longitude }) .fetch({ lat: fix.latitude, lng: fix.longitude })
.catch(() => null) .catch(() => {
resolveFailed = true
return null
})
: Promise.resolve(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({ const decision = decideNeoRegion({
cached, cached,
fix, fix,

View file

@ -43,6 +43,8 @@ interface NeoRegionState {
needsAddressFormFlow: boolean needsAddressFormFlow: boolean
needsAddressConfirmation: boolean needsAddressConfirmation: boolean
/** A device fix exists but resolves outside every serviceable bound. */
deviceOutOfService: boolean
applyRegion: (data: ApplyRegionInput) => void applyRegion: (data: ApplyRegionInput) => void
setRegions: (regions: RegionSummary[]) => void setRegions: (regions: RegionSummary[]) => void
@ -51,6 +53,7 @@ interface NeoRegionState {
openAddressFlow: () => void openAddressFlow: () => void
closeAddressFlow: () => void closeAddressFlow: () => void
setNeedsConfirmation: (value: boolean) => void setNeedsConfirmation: (value: boolean) => void
setDeviceOutOfService: (value: boolean) => void
resetForLogout: () => void resetForLogout: () => void
changeRegion: (regionId: number, boundId?: number | null) => Promise<void> changeRegion: (regionId: number, boundId?: number | null) => Promise<void>
@ -83,6 +86,7 @@ export const useNeoRegionStore = create<NeoRegionState>((set, get) => ({
needsAddressFormFlow: false, needsAddressFormFlow: false,
needsAddressConfirmation: false, needsAddressConfirmation: false,
deviceOutOfService: false,
/** /**
* The only writer of the region fields. The selection is validated against * The only writer of the region fields. The selection is validated against
@ -174,6 +178,8 @@ export const useNeoRegionStore = create<NeoRegionState>((set, get) => ({
...(value ? { needsAddressFormFlow: false } : null), ...(value ? { needsAddressFormFlow: false } : null),
}), }),
setDeviceOutOfService: (value) => set({ deviceOutOfService: value }),
resetForLogout: () => resetForLogout: () =>
set({ set({
addresses: [], addresses: [],

View file

@ -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(<NeoAddressFlow />, { 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(<NeoAddressFlow />, { 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(<NeoAddressFlow />, { auth: false })
expect(getByText('Location access is off')).toBeTruthy()
expect(getByText(/Location access is not granted/)).toBeTruthy()
})
})

View file

@ -69,6 +69,7 @@ export function resetStores() {
selectedAddressId: null, selectedAddressId: null,
needsAddressFormFlow: false, needsAddressFormFlow: false,
needsAddressConfirmation: false, needsAddressConfirmation: false,
deviceOutOfService: false,
}) })
useSlotStore.setState({ slotId: undefined, storeId: undefined }) useSlotStore.setState({ slotId: undefined, storeId: undefined })
useFlashNavigationStore.setState({ shouldNavigateToCart: false }) useFlashNavigationStore.setState({ shouldNavigateToCart: false })

View file

@ -1190,3 +1190,61 @@ race that leaves the app unresponsive on the cart page.
+ inline absolute-fill overlay with the same ActivityIndicator + message, inside + inline absolute-fill overlay with the same ActivityIndicator + message, inside
the form's KeyboardAvoidingView; no second native modal, so nothing can be left the form's KeyboardAvoidingView; no second native modal, so nothing can be left
behind when the host sheet closes. 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 <NeoLocationNotice /> 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"

View file

@ -7,6 +7,7 @@ export * from './region-cache-urls'
*/ */
export const BASE_API_URL = 'https://worker.freshyo.in' export const BASE_API_URL = 'https://worker.freshyo.in'
// export const BASE_API_URL = 'https://devapi.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://devbackend.freshyo.in'
// export const BASE_API_URL = 'https://192.168.100.126.nip.io:8787' // export const BASE_API_URL = 'https://192.168.100.126.nip.io:8787'
// export const BASE_API_URL = 'http://192.168.1.5:8787' // export const BASE_API_URL = 'http://192.168.1.5:8787'