enh
This commit is contained in:
parent
1259effa5b
commit
e1f00aad99
2 changed files with 38 additions and 25 deletions
|
|
@ -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 { View, ScrollView, ActivityIndicator } from 'react-native'
|
||||||
import { useQueryClient } from '@tanstack/react-query'
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
import { useRouter, usePathname } from 'expo-router'
|
|
||||||
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
|
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 { trpc } from '@/src/trpc-client'
|
||||||
import { useAuthOptional } from '@/src/contexts/AuthContext'
|
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 { confirmRegionSwitch } from '@/src/lib/region-switch'
|
||||||
import AddressForm from '@/src/components/AddressForm'
|
import AddressForm from '@/src/components/AddressForm'
|
||||||
|
import Login from '@/app/(auth)/login'
|
||||||
|
|
||||||
type ResolvedRegion = { regionId: number; boundId: number | null }
|
type ResolvedRegion = { regionId: number; boundId: number | null }
|
||||||
|
|
||||||
|
|
@ -52,33 +50,21 @@ interface LocationFallbackFlowProps {
|
||||||
const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, notice, onOpenSettings }) => {
|
const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, notice, onOpenSettings }) => {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const utils = trpc.useUtils()
|
const utils = trpc.useUtils()
|
||||||
const router = useRouter()
|
|
||||||
const pathname = usePathname()
|
|
||||||
const auth = useAuthOptional()
|
const auth = useAuthOptional()
|
||||||
const isAuthenticated = auth?.isAuthenticated ?? false
|
const isAuthenticated = auth?.isAuthenticated ?? false
|
||||||
const isAuthLoading = auth?.isLoading ?? 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 [busy, setBusy] = useState(false)
|
||||||
const [message, setMessage] = useState<string | null>(null)
|
const [message, setMessage] = useState<string | null>(null)
|
||||||
const resolvedRef = useRef<ResolvedRegion | null>(null)
|
const resolvedRef = useRef<ResolvedRegion | null>(null)
|
||||||
|
|
||||||
// Signed out: their saved addresses live behind the account. Remember where we
|
// The gate renders outside the root navigator (see LocationTestWrapper), so we
|
||||||
// are so login returns here (same contract LoginWall / useAuthenticatedRoute
|
// cannot router.push to /login here — render the login screen in place. Once
|
||||||
// use), then the addresses load automatically.
|
// auth lands, return to the address chooser with the saved addresses loaded.
|
||||||
const handleLogin = useCallback(async () => {
|
useEffect(() => {
|
||||||
const redirectState: RedirectState = {
|
if (isAuthenticated && mode === 'login') setMode('choose')
|
||||||
targetUrl: pathname,
|
}, [isAuthenticated, mode])
|
||||||
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])
|
|
||||||
|
|
||||||
const addressesQuery = trpc.user.address.getUserAddresses.useQuery(undefined, {
|
const addressesQuery = trpc.user.address.getUserAddresses.useQuery(undefined, {
|
||||||
enabled: isAuthenticated,
|
enabled: isAuthenticated,
|
||||||
|
|
@ -171,6 +157,22 @@ const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, no
|
||||||
onClose?.()
|
onClose?.()
|
||||||
}, [activate, 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') {
|
if (mode === 'add') {
|
||||||
return (
|
return (
|
||||||
<View style={tw`flex-1 bg-white`}>
|
<View style={tw`flex-1 bg-white`}>
|
||||||
|
|
@ -293,7 +295,7 @@ const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, no
|
||||||
</MyText>
|
</MyText>
|
||||||
<MyTouchableOpacity
|
<MyTouchableOpacity
|
||||||
testID="location-login"
|
testID="location-login"
|
||||||
onPress={handleLogin}
|
onPress={() => setMode('login')}
|
||||||
activeOpacity={0.85}
|
activeOpacity={0.85}
|
||||||
style={tw`bg-brand500 py-3 rounded-xl items-center`}
|
style={tw`bg-brand500 py-3 rounded-xl items-center`}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -4154,3 +4154,14 @@ user-ui
|
||||||
button, top border); the address list ScrollView is now flex-1 so it scrolls between the header
|
button, top border); the address list ScrollView is now flex-1 so it scrolls between the header
|
||||||
and the bottom block.
|
and the bottom block.
|
||||||
No dependency added. No migration. No tests run.
|
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.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue