This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/mobile/app/(modals)/edit-profile.tsx
caelum0x 64fbe9f474 feat: round-3 deep product build-out (69 gaps closed, all 7 products green)
Deep-audit + build-out across all products to fully-usable state; all typecheck clean.

- gitgram-web (99): wire Store feature to real endpoints, close 9 gaps
- gitgram-backend (100): close 8 flow gaps, document infra-provisioning items
- gitgram-mobile (90): fix API base-URL/path mismatch (404s) + copy proximity
  components into components/proximity wired to real screens; 15 gaps, +react-native-svg
- aitm-core (95): wire natural-language CLI flow end-to-end; 11 gaps
- aitm-api (97): fix teams metadata runtime bug; copy a2a-js server/client/grpc
  into src/a2a and wire A2A route; crates.io package search; 8 gaps
- aitm-mcp (100): fix A2A client/server card mismatch; 9 gaps
- aitm-website (95): build missing docs routes; 9 gaps

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 13:54:57 +03:00

240 lines
6.0 KiB
TypeScript

import React, { useState } from 'react';
import {
View,
Text,
StyleSheet,
TextInput,
TouchableOpacity,
ScrollView,
Alert,
} from 'react-native';
import { useRouter } from 'expo-router';
import { Image } from 'expo-image';
import * as ImagePicker from 'expo-image-picker';
import { Colors } from '../../constants/Colors';
import { useAuthStore } from '../../store/authStore';
import { userService } from '../../services/userService';
import LoadingSpinner from '../../components/common/LoadingSpinner';
import { useToast } from '../../hooks/useToast';
import { logger } from '../../utils/logger';
export default function EditProfileScreen() {
const router = useRouter();
const { user, setUser } = useAuthStore();
const [username, setUsername] = useState(user?.username || '');
const [bio, setBio] = useState(user?.bio || '');
const [avatar, setAvatar] = useState<string | null>(user?.avatar || null);
const [loading, setLoading] = useState(false);
const { showToast, ToastComponent } = useToast();
const pickImage = async () => {
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Permission needed', 'Please grant camera roll permissions');
return;
}
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [1, 1],
quality: 0.8,
});
if (!result.canceled && result.assets[0]) {
setAvatar(result.assets[0].uri);
}
};
const handleSave = async () => {
if (!username.trim()) {
Alert.alert('Error', 'Username is required');
return;
}
setLoading(true);
try {
const formData = new FormData();
formData.append('username', username);
if (bio) {
formData.append('bio', bio);
}
if (avatar && avatar !== user?.avatar) {
formData.append('avatar', {
uri: avatar,
type: 'image/jpeg',
name: 'avatar.jpg',
} as any);
}
const response = await userService.updateUser(formData);
setUser(response.user);
showToast('Profile updated successfully!', 'success');
router.back();
} catch (error: any) {
logger.error('Update profile error:', error);
showToast(error.response?.data?.error || 'Failed to update profile', 'error');
} finally {
setLoading(false);
}
};
if (loading) {
return (
<View style={styles.container}>
<LoadingSpinner fullScreen />
</View>
);
}
return (
<View style={styles.container}>
{ToastComponent}
<View style={styles.header}>
<TouchableOpacity onPress={() => router.back()}>
<Text style={styles.cancelButton}>Cancel</Text>
</TouchableOpacity>
<Text style={styles.title}>Edit Profile</Text>
<TouchableOpacity onPress={handleSave}>
<Text style={styles.saveButton}>Save</Text>
</TouchableOpacity>
</View>
<ScrollView style={styles.content}>
<View style={styles.avatarSection}>
<TouchableOpacity onPress={pickImage}>
{avatar ? (
<View style={styles.avatarContainer}>
<Image source={{ uri: avatar }} style={styles.avatar} />
</View>
) : (
<View style={styles.avatarPlaceholder}>
<Text style={styles.avatarText}>
{username.charAt(0).toUpperCase()}
</Text>
</View>
)}
</TouchableOpacity>
<TouchableOpacity onPress={pickImage}>
<Text style={styles.changePhotoText}>Change Photo</Text>
</TouchableOpacity>
</View>
<View style={styles.form}>
<Text style={styles.label}>Username</Text>
<TextInput
style={styles.input}
placeholder="Username"
placeholderTextColor={Colors.textSecondary}
value={username}
onChangeText={setUsername}
autoCapitalize="none"
maxLength={30}
/>
<Text style={styles.label}>Bio</Text>
<TextInput
style={[styles.input, styles.bioInput]}
placeholder="Tell us about yourself..."
placeholderTextColor={Colors.textSecondary}
value={bio}
onChangeText={setBio}
multiline
maxLength={150}
/>
</View>
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.background,
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
borderBottomWidth: 1,
borderBottomColor: Colors.border,
},
cancelButton: {
color: Colors.text,
fontSize: 16,
},
title: {
color: Colors.text,
fontSize: 18,
fontWeight: '600',
},
saveButton: {
color: Colors.accent,
fontSize: 16,
fontWeight: '600',
},
content: {
flex: 1,
padding: 16,
},
avatarSection: {
alignItems: 'center',
marginBottom: 32,
},
avatarContainer: {
width: 100,
height: 100,
borderRadius: 50,
overflow: 'hidden',
marginBottom: 12,
},
avatar: {
width: '100%',
height: '100%',
},
avatarPlaceholder: {
width: 100,
height: 100,
borderRadius: 50,
backgroundColor: Colors.accent,
justifyContent: 'center',
alignItems: 'center',
marginBottom: 12,
},
avatarText: {
color: Colors.text,
fontSize: 40,
fontWeight: 'bold',
},
changePhotoText: {
color: Colors.accent,
fontSize: 16,
fontWeight: '600',
},
form: {
gap: 16,
},
label: {
color: Colors.text,
fontSize: 14,
fontWeight: '600',
marginBottom: 8,
},
input: {
backgroundColor: Colors.surface,
borderRadius: 8,
padding: 12,
color: Colors.text,
fontSize: 16,
borderWidth: 1,
borderColor: Colors.border,
},
bioInput: {
minHeight: 100,
textAlignVertical: 'top',
},
});