Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add credential AddEdit page scaffolding to app (#771)
Leendert de Borstc0e1c75a1b50
diff --git a/mobile-app/app/(tabs)/(credentials)/_layout.tsx b/mobile-app/app/(tabs)/(credentials)/_layout.tsxindex a851b2c78..cbf2a6742 100644--- a/mobile-app/app/(tabs)/(credentials)/_layout.tsx+++ b/mobile-app/app/(tabs)/(credentials)/_layout.tsx@@ -12,6 +12,16 @@ export default function CredentialsLayout() {headerShown: false,}}/>+ <Stack.Screen+ name="add-edit"+ options={{+ title: 'Add Credential',+ headerShown: true,+ headerStyle: {+ backgroundColor: colors.headerBackground,+ },+ }}+ /><Stack.Screenname="[id]"options={{diff --git a/mobile-app/app/(tabs)/(credentials)/add-edit.tsx b/mobile-app/app/(tabs)/(credentials)/add-edit.tsxnew file mode 100644index 000000000..1ceae4b9c--- /dev/null+++ b/mobile-app/app/(tabs)/(credentials)/add-edit.tsx@@ -0,0 +1,343 @@+import { StyleSheet, View, TextInput, TouchableOpacity, ScrollView, Platform, Animated } from 'react-native';+import { useState, useEffect, useRef } from 'react';+import { useLocalSearchParams, useRouter } from 'expo-router';+import { ThemedText } from '@/components/ThemedText';+import { ThemedView } from '@/components/ThemedView';+import { ThemedSafeAreaView } from '@/components/ThemedSafeAreaView';+import { useColors } from '@/hooks/useColorScheme';+import { useDb } from '@/context/DbContext';+import { Credential } from '@/utils/types/Credential';+import { TitleContainer } from '@/components/TitleContainer';+import { CollapsibleHeader } from '@/components/CollapsibleHeader';+import MaterialIcons from '@expo/vector-icons/MaterialIcons';+import Toast from 'react-native-toast-message';+import { Gender } from "../../../utils/generators/Identity/types/Gender";++type CredentialMode = 'random' | 'manual';++export default function AddEditCredentialScreen() {+ const { id } = useLocalSearchParams<{ id: string }>();+ const router = useRouter();+ const colors = useColors();+ const dbContext = useDb();+ const [mode, setMode] = useState<CredentialMode>('random');+ const [isLoading, setIsLoading] = useState(false);+ const scrollY = useRef(new Animated.Value(0)).current;+ const [credential, setCredential] = useState<Partial<Credential>>({+ Id: "",+ Username: "",+ Password: "",+ ServiceName: "",+ ServiceUrl: "",+ Notes: "",+ Alias: {+ FirstName: "",+ LastName: "",+ NickName: "",+ BirthDate: "0001-01-01",+ Gender: Gender.Other,+ Email: ""+ }+ });++ const isEditMode = !!id;++ useEffect(() => {+ if (isEditMode) {+ loadExistingCredential();+ }+ }, [id]);++ const loadExistingCredential = async () => {+ try {+ setIsLoading(true);+ const existingCredential = await dbContext.sqliteClient!.getCredentialById(id);+ if (existingCredential) {+ setCredential(existingCredential);+ // If credential has custom values, switch to manual mode+ if (existingCredential.Alias?.FirstName || existingCredential.Alias?.LastName) {+ setMode('manual');+ }+ }+ } catch (err) {+ console.error('Error loading credential:', err);+ Toast.show({+ type: 'error',+ text1: 'Failed to load credential',+ text2: 'Please try again'+ });+ } finally {+ setIsLoading(false);+ }+ };++ const generateRandomValues = () => {+ // Placeholder for random generation - will be replaced with actual generators+ const randomString = (length: number) => Math.random().toString(36).substring(2, length + 2);++ setCredential(prev => ({+ ...prev,+ Username: randomString(8),+ Password: randomString(12),+ Alias: {+ ...prev.Alias,+ Email: `${randomString(8)}@example.com`,+ FirstName: randomString(6),+ LastName: randomString(6),+ NickName: randomString(6),+ Gender: Math.random() > 0.5 ? Gender.Male : Gender.Female,+ BirthDate: '0001-01-01 00:00:00'+ }+ }));+ };++ const handleSave = async () => {+ try {+ setIsLoading(true);+ // Always use createCredential since updateCredentialById doesn't exist+ await dbContext.sqliteClient!.createCredential(credential as Credential);+ Toast.show({+ type: 'success',+ text1: 'Credential saved successfully',+ position: 'bottom'+ });+ router.back();+ } catch (error) {+ console.error('Error saving credential:', error);+ Toast.show({+ type: 'error',+ text1: 'Failed to save credential',+ text2: error instanceof Error ? error.message : 'Unknown error',+ position: 'bottom'+ });+ } finally {+ setIsLoading(false);+ }+ };++ const handleAliasChange = (field: keyof Credential['Alias'], value: string | Gender) => {+ setCredential(prev => ({+ ...prev,+ Alias: {+ ...prev.Alias,+ [field]: value,+ BirthDate: prev.Alias?.BirthDate || "0001-01-01" // Ensure BirthDate is always set+ }+ }));+ };++ const headerButtons = [{+ icon: 'save' as const,+ position: 'right' as const,+ onPress: handleSave+ }];++ const styles = StyleSheet.create({+ container: {+ flex: 1,+ },+ content: {+ flex: 1,+ padding: 16,+ paddingTop: 0,+ marginTop: 36,+ },+ modeSelector: {+ flexDirection: 'row',+ marginBottom: 16,+ backgroundColor: colors.accentBackground,+ borderRadius: 8,+ padding: 4,+ },+ modeButton: {+ flex: 1,+ padding: 12,+ alignItems: 'center',+ borderRadius: 6,+ },+ modeButtonActive: {+ backgroundColor: colors.primary,+ },+ modeButtonText: {+ color: colors.text,+ fontWeight: '600',+ },+ modeButtonTextActive: {+ color: '#fff',+ },+ section: {+ marginBottom: 24,+ backgroundColor: colors.accentBackground,+ borderRadius: 8,+ padding: 16,+ },+ sectionTitle: {+ fontSize: 18,+ fontWeight: '600',+ marginBottom: 16,+ color: colors.text,+ },+ input: {+ backgroundColor: colors.background,+ color: colors.text,+ padding: 12,+ borderRadius: 8,+ marginBottom: 12,+ fontSize: 16,+ },+ generateButton: {+ backgroundColor: colors.primary,+ padding: 12,+ borderRadius: 8,+ alignItems: 'center',+ marginBottom: 16,+ },+ generateButtonText: {+ color: '#fff',+ fontWeight: '600',+ },+ notesInput: {+ backgroundColor: colors.background,+ color: colors.text,+ padding: 12,+ borderRadius: 8,+ marginBottom: 12,+ fontSize: 16,+ height: 100,+ textAlignVertical: 'top',+ },+ });++ return (+ <ThemedSafeAreaView style={styles.container}>+ <ThemedView style={styles.content}>+ <ScrollView>+ {!isEditMode && (+ <View style={styles.modeSelector}>+ <TouchableOpacity+ style={[styles.modeButton, mode === 'random' && styles.modeButtonActive]}+ onPress={() => setMode('random')}+ >+ <ThemedText style={[styles.modeButtonText, mode === 'random' && styles.modeButtonTextActive]}>+ Random Alias+ </ThemedText>+ </TouchableOpacity>+ <TouchableOpacity+ style={[styles.modeButton, mode === 'manual' && styles.modeButtonActive]}+ onPress={() => setMode('manual')}+ >+ <ThemedText style={[styles.modeButtonText, mode === 'manual' && styles.modeButtonTextActive]}>+ Manual+ </ThemedText>+ </TouchableOpacity>+ </View>+ )}++ <View style={styles.section}>+ <ThemedText style={styles.sectionTitle}>Service Information</ThemedText>+ <TextInput+ style={styles.input}+ placeholder="Service Name"+ placeholderTextColor={colors.textMuted}+ value={credential.ServiceName}+ onChangeText={(text) => setCredential(prev => ({ ...prev, ServiceName: text }))}+ />+ <TextInput+ style={styles.input}+ placeholder="Service URL"+ placeholderTextColor={colors.textMuted}+ value={credential.ServiceUrl}+ onChangeText={(text) => setCredential(prev => ({ ...prev, ServiceUrl: text }))}+ />+ </View>++ {(mode === 'manual' || isEditMode) && (+ <>+ <View style={styles.section}>+ <ThemedText style={styles.sectionTitle}>Login Credentials</ThemedText>+ {!isEditMode && (+ <TouchableOpacity style={styles.generateButton} onPress={generateRandomValues}>+ <ThemedText style={styles.generateButtonText}>Generate Random Values</ThemedText>+ </TouchableOpacity>+ )}+ <TextInput+ style={styles.input}+ placeholder="Email"+ placeholderTextColor={colors.textMuted}+ value={credential.Alias?.Email}+ onChangeText={(text) => handleAliasChange('Email', text)}+ />+ <TextInput+ style={styles.input}+ placeholder="Username"+ placeholderTextColor={colors.textMuted}+ value={credential.Username}+ onChangeText={(text) => setCredential(prev => ({ ...prev, Username: text }))}+ />+ <TextInput+ style={styles.input}+ placeholder="Password"+ placeholderTextColor={colors.textMuted}+ value={credential.Password}+ onChangeText={(text) => setCredential(prev => ({ ...prev, Password: text }))}+ secureTextEntry+ />+ </View>++ <View style={styles.section}>+ <ThemedText style={styles.sectionTitle}>Alias Information</ThemedText>+ <TextInput+ style={styles.input}+ placeholder="First Name"+ placeholderTextColor={colors.textMuted}+ value={credential.Alias?.FirstName}+ onChangeText={(text) => handleAliasChange('FirstName', text)}+ />+ <TextInput+ style={styles.input}+ placeholder="Last Name"+ placeholderTextColor={colors.textMuted}+ value={credential.Alias?.LastName}+ onChangeText={(text) => handleAliasChange('LastName', text)}+ />+ <TextInput+ style={styles.input}+ placeholder="Nick Name"+ placeholderTextColor={colors.textMuted}+ value={credential.Alias?.NickName}+ onChangeText={(text) => handleAliasChange('NickName', text)}+ />+ <TextInput+ style={styles.input}+ placeholder="Gender"+ placeholderTextColor={colors.textMuted}+ value={credential.Alias?.Gender}+ onChangeText={(text) => handleAliasChange('Gender', text === 'Male' ? Gender.Male : Gender.Female)}+ />+ <TextInput+ style={styles.input}+ placeholder="Birth Date (YYYY-MM-DD)"+ placeholderTextColor={colors.textMuted}+ value={credential.Alias?.BirthDate?.split(' ')[0]}+ onChangeText={(text) => handleAliasChange('BirthDate', text + ' 00:00:00')}+ />+ </View>+ <View style={styles.section}>+ <ThemedText style={styles.sectionTitle}>Metadata</ThemedText>+ <TextInput+ style={styles.notesInput}+ placeholder="Notes"+ placeholderTextColor={colors.textMuted}+ value={credential.Notes}+ onChangeText={(text) => setCredential(prev => ({ ...prev, Notes: text }))}+ multiline+ />+ {/* TODO: Add TOTP management */}+ </View>+ </>+ )}+ </ScrollView>+ </ThemedView>+ </ThemedSafeAreaView>+ );+}\ No newline at end of filediff --git a/mobile-app/app/(tabs)/(credentials)/index.tsx b/mobile-app/app/(tabs)/(credentials)/index.tsxindex 06907a254..a38b4d6ac 100644--- a/mobile-app/app/(tabs)/(credentials)/index.tsx+++ b/mobile-app/app/(tabs)/(credentials)/index.tsx@@ -31,7 +31,7 @@ export default function CredentialsScreen() {const headerButtons = [{icon: 'add' as const,position: 'right' as const,- onPress: () => router.push('/(modals)/add-credential')+ onPress: () => router.push('/(tabs)/(credentials)/add-edit')}];useEffect(() => {