This commit is contained in:
shafi54 2026-10-14 01:03:51 +05:30
parent 1259effa5b
commit e1f00aad99
2 changed files with 38 additions and 25 deletions

View file

@ -1,15 +1,13 @@
import React, { useCallback, useRef, useState } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { View, ScrollView, ActivityIndicator } from 'react-native'
import { useQueryClient } from '@tanstack/react-query'
import { useRouter, usePathname } from 'expo-router'
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
import { MyText, MyTouchableOpacity, tw, theme, StorageServiceCasual } from 'common-ui'
import { MyText, MyTouchableOpacity, tw, theme } from 'common-ui'
import { trpc } from '@/src/trpc-client'
import { useAuthOptional } from '@/src/contexts/AuthContext'
import type { RedirectState } from '@/src/contexts/AuthContext'
import constants from '@/src/constants'
import { confirmRegionSwitch } from '@/src/lib/region-switch'
import AddressForm from '@/src/components/AddressForm'
import Login from '@/app/(auth)/login'
type ResolvedRegion = { regionId: number; boundId: number | null }
@ -52,33 +50,21 @@ interface LocationFallbackFlowProps {
const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, notice, onOpenSettings }) => {
const queryClient = useQueryClient()
const utils = trpc.useUtils()
const router = useRouter()
const pathname = usePathname()
const auth = useAuthOptional()
const isAuthenticated = auth?.isAuthenticated ?? false
const isAuthLoading = auth?.isLoading ?? false
const [mode, setMode] = useState<'choose' | 'add'>('choose')
const [mode, setMode] = useState<'choose' | 'add' | 'login'>('choose')
const [busy, setBusy] = useState(false)
const [message, setMessage] = useState<string | null>(null)
const resolvedRef = useRef<ResolvedRegion | null>(null)
// Signed out: their saved addresses live behind the account. Remember where we
// are so login returns here (same contract LoginWall / useAuthenticatedRoute
// use), then the addresses load automatically.
const handleLogin = useCallback(async () => {
const redirectState: RedirectState = {
targetUrl: pathname,
queryParams: {},
timestamp: Date.now(),
}
try {
await StorageServiceCasual.setItem(constants.AUTH_REDIRECT_KEY, JSON.stringify(redirectState))
} catch {
// ignore storage failure — still navigate to login
}
router.push('/(auth)/login')
}, [pathname, router])
// The gate renders outside the root navigator (see LocationTestWrapper), so we
// cannot router.push to /login here — render the login screen in place. Once
// auth lands, return to the address chooser with the saved addresses loaded.
useEffect(() => {
if (isAuthenticated && mode === 'login') setMode('choose')
}, [isAuthenticated, mode])
const addressesQuery = trpc.user.address.getUserAddresses.useQuery(undefined, {
enabled: isAuthenticated,
@ -171,6 +157,22 @@ const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, no
onClose?.()
}, [activate, onClose])
if (mode === 'login') {
return (
<View style={tw`flex-1 bg-white`}>
<Login />
<MyTouchableOpacity
testID="location-login-back"
onPress={() => setMode('choose')}
activeOpacity={0.7}
style={tw`absolute left-4 top-14 w-10 h-10 rounded-full bg-white/90 items-center justify-center shadow`}
>
<MaterialIcons name="arrow-back" size={22} color="#374151" />
</MyTouchableOpacity>
</View>
)
}
if (mode === 'add') {
return (
<View style={tw`flex-1 bg-white`}>
@ -293,7 +295,7 @@ const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, no
</MyText>
<MyTouchableOpacity
testID="location-login"
onPress={handleLogin}
onPress={() => setMode('login')}
activeOpacity={0.85}
style={tw`bg-brand500 py-3 rounded-xl items-center`}
>

View file

@ -4154,3 +4154,14 @@ user-ui
button, top border); the address list ScrollView is now flex-1 so it scrolls between the header
and the bottom block.
No dependency added. No migration. No tests run.
2026-10-14 00:58:32 Fix: the gate's Login button did nothing.
Root cause: LocationTestWrapper renders the gate INSTEAD of its children, so while the gate is up
the root <Stack /> (the expo-router navigator) is unmounted and router.push is a no-op (the error
is hidden by LogBox.ignoreAllLogs). Same reason FirstUserWrapper only uses local state.
apps/user-ui/src/components/location/LocationFallbackFlow.tsx:
+ added a 'login' mode that renders the (router-free) login screen inline, with a back button
+ the Login button now switches mode instead of calling router.push; when auth flips to
authenticated the flow returns to the choose view and the saved addresses load
+ dropped the now-unused router/pathname/redirect-state imports
No dependency added. No migration. No tests run.