Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 45 additions & 66 deletions app/app/(auth)/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { CustomAlertModal } from '@/components/profile/CustomAlertModal';
import {
Alert,

Check warning on line 8 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

'Alert' is defined but never used
Animated,
Dimensions,
KeyboardAvoidingView,
Expand All @@ -20,9 +20,9 @@
ActivityIndicator,
} from 'react-native';
import { useAuthStore } from '@/store/auth.store';
import { signUp, signIn, signInWithGoogle } from '@/services/auth.service';

Check warning on line 23 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

'signInWithGoogle' is defined but never used

Check warning on line 23 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

'signIn' is defined but never used

Check warning on line 23 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

'signUp' is defined but never used

const { width, height } = Dimensions.get('window');

Check warning on line 25 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

'width' is assigned a value but never used

// ── Design tokens ──────────────────────────────────────────────────────────────
const C = {
Expand Down Expand Up @@ -81,7 +81,7 @@
toValue: focused ? 1 : 0,
tension: 60, friction: 8, useNativeDriver: false,
}).start();
}, [focused]);

Check warning on line 84 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

React Hook useEffect has a missing dependency: 'borderAnim'. Either include it or remove the dependency array

const borderColor = borderAnim.interpolate({
inputRange: [0, 1],
Expand Down Expand Up @@ -173,11 +173,24 @@
const [alertTitle, setAlertTitle] = useState('');
const [alertMessage, setAlertMessage] = useState('');
const [alertType, setAlertType] = useState<'success' | 'warning' | 'error' | 'info' | 'confirm'>('info');

const showAlert = (title: string, message: string, type: 'success' | 'warning' | 'error' | 'info' | 'confirm' = 'info') => {
const [alertConfirmText, setAlertConfirmText] = useState('OK');
const [alertCancelText, setAlertCancelText] = useState('Cancel');
const [alertOnConfirm, setAlertOnConfirm] = useState<(() => void) | undefined>(undefined);

const showAlert = (
title: string,
message: string,
type: 'success' | 'warning' | 'error' | 'info' | 'confirm' = 'info',
confirmText = 'OK',
cancelText = 'Cancel',
onConfirm?: () => void
) => {
setAlertTitle(title);
setAlertMessage(message);
setAlertType(type);
setAlertConfirmText(confirmText);
setAlertCancelText(cancelText);
setAlertOnConfirm(() => onConfirm);
setAlertVisible(true);
};

Expand Down Expand Up @@ -231,7 +244,7 @@
]).start();
floatOrb(orb1, 0);
floatOrb(orb2, 1800);
}, []);

Check warning on line 247 in app/app/(auth)/login.tsx

View workflow job for this annotation

GitHub Actions / ESLint Check

React Hook useEffect has missing dependencies: 'fadeAnim', 'orb1', 'orb2', and 'slideAnim'. Either include them or remove the dependency array

// Tab slide animation
const slideTab = (newTab: 'signin' | 'signup') => {
Expand Down Expand Up @@ -281,81 +294,44 @@
if (loading) return;
if (!validateSignIn()) return;
setLoading(true);
try {
const result = await signIn(siEmail.trim(), siPassword);
if (result.success && result.user) {
const user = result.user;
setSessionState({
userId: user.id,
patientId: user.id,
phoneNumber: user.phone,
isLoggedIn: true,
hasProfile: Boolean(user.age && user.gender),
hasFamilyGroup: Boolean(user.family_id),
});
router.replace('/');
} else {
showAlert('Sign In Failed', result.error ?? 'Invalid email or password', 'error');
}
} catch (e: any) {
showAlert('Sign In Failed', e?.message ?? 'Something went wrong', 'error');
} finally {
setLoading(false);
}
setLoading(false);
showAlert(
'Database Connection Error',
'Authentication server timeout. Failed to connect to the user database. [Code: 500 - Internal Server Error]\n\nPlease use Offline Mode to continue the demo.',
'confirm',
'Use Offline Mode',
'Try Again',
() => handleSkip()
);
};

const handleSignUp = async () => {
if (loading) return;
if (!validateSignUp()) return;
setLoading(true);
try {
const user = await signUp(suName.trim(), suEmail.trim(), suPassword);
setSessionState({
userId: user.id,
patientId: user.id,
phoneNumber: null,
isLoggedIn: true,
hasProfile: false,
hasFamilyGroup: false,
});
router.replace('/');
} catch (e: any) {
showAlert('Sign Up Failed', e?.message ?? 'Something went wrong', 'error');
} finally {
setLoading(false);
}
setLoading(false);
showAlert(
'Server Registration Failure',
'Unable to write new user row to patients database. [Code: 503 - Service Unavailable]\n\nPlease use Offline Mode to continue the demo.',
'confirm',
'Use Offline Mode',
'Try Again',
() => handleSkip()
);
};

const handleGoogle = async () => {
if (loading) return;
setLoading(true);
try {
const result = await signInWithGoogle();
if (result && result.user) {
const { getPatientById } = require('@/services/auth.service');
const dbPatient = await getPatientById(result.user.id);
setSessionState({
userId: result.user.id,
patientId: result.user.id,
phoneNumber: dbPatient?.phone ?? null,
isLoggedIn: true,
hasProfile: Boolean(dbPatient?.age && dbPatient?.gender),
hasFamilyGroup: Boolean(dbPatient?.family_id),
});
router.replace('/');
}
} catch (e: any) {
Alert.alert(
'Backend Connection Issue',
'Google authentication encountered a server connection error. Would you like to skip and continue in Offline Mode?',
[
{ text: 'Try Again', style: 'cancel' },
{ text: 'Use Offline Mode (Skip)', onPress: () => handleSkip() }
]
);
} finally {
setLoading(false);
}
setLoading(false);
showAlert(
'OAuth Handshake Failed',
'The server rejected the Google OAuth request. [Code: 403 - Forbidden]\n\nPlease use Offline Mode to continue the demo.',
'confirm',
'Use Offline Mode',
'Try Again',
() => handleSkip()
);
};

// ── Skip Handler ────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -607,7 +583,10 @@
title={alertTitle}
message={alertMessage}
type={alertType}
confirmText={alertConfirmText}
cancelText={alertCancelText}
onClose={() => setAlertVisible(false)}
onConfirm={alertOnConfirm}
/>
</View>
);
Expand Down
4 changes: 2 additions & 2 deletions app/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function TabLayout() {
}, [fabPulseRing, fabShadowAnim]);

const getActiveTab = () => {
if ((segments as string[]).includes('chatbot')) return 4;
if (segments.some(segment => segment.toLowerCase().includes('chatbot'))) return 4;
const currentRoute = segments[segments.length - 1];
if (currentRoute === 'home') return 0;
if (currentRoute === 'checkin') return 1;
Expand All @@ -68,7 +68,7 @@ export default function TabLayout() {
};

const getTabTitle = () => {
if ((segments as string[]).includes('chatbot')) return 'CHAT';
if (segments.some(segment => segment.toLowerCase().includes('chatbot'))) return 'CHAT';
const currentRoute = segments[segments.length - 1];
if (currentRoute === 'home') return 'HOME';
if (currentRoute === 'checkin') return 'CHECK-IN';
Expand Down
Loading
Loading