Fix navigation: add isNavigatingAway flag to prevent redirect conflicts
- Added isNavigatingAway state to block auto-redirects when user clicks back - Both header back button and main button now set this flag before navigating - Prevents loadBeneficiary from triggering competing redirects 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c2c6a52b31
commit
62f70853cb
@ -91,9 +91,10 @@ export default function EquipmentStatusScreen() {
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isConfirming, setIsConfirming] = useState(false);
|
||||
const [isNavigatingAway, setIsNavigatingAway] = useState(false);
|
||||
|
||||
const loadBeneficiary = useCallback(async () => {
|
||||
if (!id) return;
|
||||
if (!id || isNavigatingAway) return;
|
||||
|
||||
if (!isRefreshing) {
|
||||
setIsLoading(true);
|
||||
@ -105,6 +106,9 @@ export default function EquipmentStatusScreen() {
|
||||
if (response.ok && response.data) {
|
||||
setBeneficiary(response.data);
|
||||
|
||||
// Skip auto-redirects if user is navigating away
|
||||
if (isNavigatingAway) return;
|
||||
|
||||
// Self-guard: Redirect if user has devices - shouldn't be on this page
|
||||
if (hasBeneficiaryDevices(response.data)) {
|
||||
router.replace(`/(tabs)/beneficiaries/${id}`);
|
||||
@ -126,7 +130,7 @@ export default function EquipmentStatusScreen() {
|
||||
setIsLoading(false);
|
||||
setIsRefreshing(false);
|
||||
}
|
||||
}, [id, isRefreshing]);
|
||||
}, [id, isRefreshing, isNavigatingAway]);
|
||||
|
||||
useEffect(() => {
|
||||
loadBeneficiary();
|
||||
@ -193,7 +197,10 @@ export default function EquipmentStatusScreen() {
|
||||
<SafeAreaView style={styles.container} edges={['top', 'bottom']}>
|
||||
{/* Header */}
|
||||
<View style={styles.header}>
|
||||
<TouchableOpacity style={styles.backButton} onPress={() => router.push('/(tabs)/beneficiaries')}>
|
||||
<TouchableOpacity style={styles.backButton} onPress={() => {
|
||||
setIsNavigatingAway(true);
|
||||
router.replace('/(tabs)/beneficiaries');
|
||||
}}>
|
||||
<Ionicons name="arrow-back" size={24} color={AppColors.textPrimary} />
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.headerTitle}>{beneficiary.name}</Text>
|
||||
@ -285,7 +292,10 @@ export default function EquipmentStatusScreen() {
|
||||
styles.backToLovedOnesButton,
|
||||
pressed && { opacity: 0.7 }
|
||||
]}
|
||||
onPress={() => router.dismissAll()}
|
||||
onPress={() => {
|
||||
setIsNavigatingAway(true);
|
||||
router.replace('/(tabs)/beneficiaries');
|
||||
}}
|
||||
>
|
||||
<Ionicons name="people" size={20} color={AppColors.white} />
|
||||
<Text style={styles.backToLovedOnesText}>Back to My Loved Ones</Text>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user