diff --git a/formulus/src/screens/SettingsScreen.tsx b/formulus/src/screens/SettingsScreen.tsx index 23cbe402d..a25cb2178 100644 --- a/formulus/src/screens/SettingsScreen.tsx +++ b/formulus/src/screens/SettingsScreen.tsx @@ -15,7 +15,7 @@ import {SafeAreaView} from 'react-native-safe-area-context'; import {useNavigation} from '@react-navigation/native'; import {BottomTabNavigationProp} from '@react-navigation/bottom-tabs'; import * as Keychain from 'react-native-keychain'; -import {login} from '../api/synkronus/Auth'; +import {login, getUserInfo, UserInfo} from '../api/synkronus/Auth'; import {serverConfigService} from '../services/ServerConfigService'; import QRScannerModal from '../components/QRScannerModal'; import {QRSettingsService} from '../services/QRSettingsService'; @@ -25,6 +25,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {ToastService} from '../services/ToastService'; import {serverSwitchService} from '../services/ServerSwitchService'; import {syncService} from '../services/SyncService'; +import { tokens } from '@ode/tokens/dist/react-native/tokens'; type SettingsScreenNavigationProp = BottomTabNavigationProp< MainTabParamList, @@ -40,6 +41,7 @@ const SettingsScreen = () => { const [isLoading, setIsLoading] = useState(true); const [isLoggingIn, setIsLoggingIn] = useState(false); const [showQRScanner, setShowQRScanner] = useState(false); + const [_loggedInUser, setLoggedInUser] = useState(null); useEffect(() => { loadSettings(); @@ -96,7 +98,7 @@ const SettingsScreen = () => { ? [ { text: 'Cancel', - style: 'cancel' as const, + style: 'cancel', onPress: () => { setServerUrl(initialServerUrl); resolve(false); @@ -104,7 +106,7 @@ const SettingsScreen = () => { }, { text: 'Proceed without syncing', - style: 'destructive' as const, + style: 'destructive', onPress: () => { (async () => { try { @@ -137,7 +139,7 @@ const SettingsScreen = () => { : [ { text: 'Cancel', - style: 'cancel' as const, + style: 'cancel', onPress: () => { setServerUrl(initialServerUrl); resolve(false); @@ -145,7 +147,7 @@ const SettingsScreen = () => { }, { text: 'Yes, wipe & switch', - style: 'destructive' as const, + style: 'destructive', onPress: () => { (async () => { try { @@ -187,6 +189,9 @@ const SettingsScreen = () => { setUsername(credentials.username); setPassword(credentials.password); } + + const userInfo = await getUserInfo(); + setLoggedInUser(userInfo); } catch (error) { console.error('Failed to load settings:', error); } finally { @@ -207,7 +212,8 @@ const SettingsScreen = () => { setIsLoggingIn(true); try { await Keychain.setGenericPassword(username, password); - await login(username, password); + const userInfo = await login(username, password); + setLoggedInUser(userInfo); ToastService.showShort('Successfully logged in!'); navigation.navigate('Home'); } catch (error: any) { @@ -250,7 +256,8 @@ const SettingsScreen = () => { settings.password, ); try { - await login(settings.username, settings.password); + const userInfo = await login(settings.username, settings.password); + setLoggedInUser(userInfo); ToastService.showShort('Successfully logged in!'); navigation.navigate('Home'); } catch (error: any) { @@ -350,36 +357,24 @@ const SettingsScreen = () => { /> - {(() => { - const isFieldsEmpty = - !serverUrl.trim() || !username.trim() || !password.trim(); - const isButtonDisabled = isFieldsEmpty || isLoggingIn; - - return ( - - - - {isLoggingIn ? 'Logging in...' : 'Login'} - - - ); - })()} + + + + {isLoggingIn ? 'Logging in...' : 'Login'} + +