-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Add edit profile photo and name functionality #1895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Isthisanmol
merged 6 commits into
development
from
copilot/fix-181429480-611845080-ff4480f5-c4d0-4cb0-8105-05dee4f3db38
Mar 20, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7aaeb42
Initial plan
Copilot 16196c6
feat: add edit profile photo and name functionality
Copilot d5d8af0
fix: address CodeRabbit review feedback on profile edit
Copilot 7ee88e9
fix: address CodeRabbit round-2 inline review comments
Copilot 876f82d
merge development
Isthisanmol 7dd1a78
correct materialcommunity icon
Isthisanmol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import type { AlertRef } from '@packrat/ui/nativewindui'; | ||
| import { | ||
| ActivityIndicator, | ||
| Alert, | ||
| Alert as AlertComponent, | ||
| Avatar, | ||
| AvatarFallback, | ||
| AvatarImage, | ||
| Button, | ||
| List, | ||
| ListItem, | ||
|
|
@@ -17,16 +18,23 @@ import TabScreen from 'expo-app/components/TabScreen'; | |
| import { withAuthWall } from 'expo-app/features/auth/hocs'; | ||
| import { useAuth } from 'expo-app/features/auth/hooks/useAuth'; | ||
| import { useUser } from 'expo-app/features/auth/hooks/useUser'; | ||
| import { useImagePicker } from 'expo-app/features/packs/hooks/useImagePicker'; | ||
| import { uploadImage } from 'expo-app/features/packs/utils/uploadImage'; | ||
| import { ProfileAuthWall } from 'expo-app/features/profile/components'; | ||
| import { useUpdateProfile } from 'expo-app/features/profile/hooks/useUpdateProfile'; | ||
| import { cn } from 'expo-app/lib/cn'; | ||
| import { hasUnsyncedChanges } from 'expo-app/lib/hasUnsyncedChanges'; | ||
| import { useTranslation } from 'expo-app/lib/hooks/useTranslation'; | ||
| import { Stack } from 'expo-router'; | ||
| import { buildPackTemplateItemImageUrl } from 'expo-app/lib/utils/buildPackTemplateItemImageUrl'; | ||
| import * as FileSystem from 'expo-file-system'; | ||
| import { router, Stack } from 'expo-router'; | ||
| import * as Updates from 'expo-updates'; | ||
| import { useRef, useState } from 'react'; | ||
| import { Platform, View } from 'react-native'; | ||
| import { Alert, Platform, TouchableOpacity, View } from 'react-native'; | ||
| import { SafeAreaView } from 'react-native-safe-area-context'; | ||
|
|
||
| const AVATAR_MAX_BYTES = 5 * 1024 * 1024; // 5 MB | ||
|
|
||
| function Profile() { | ||
| const user = useUser(); | ||
| const { t } = useTranslation(); | ||
|
|
@@ -50,6 +58,7 @@ function Profile() { | |
| { | ||
| id: 'name', | ||
| title: t('common.name'), | ||
| onPress: () => router.push('/(app)/(tabs)/profile/name'), | ||
| ...(Platform.OS === 'ios' ? { value: displayName } : { subTitle: displayName }), | ||
| }, | ||
| { | ||
|
|
@@ -89,6 +98,7 @@ function Item({ info }: { info: ListRenderItemInfo<DataItem> }) { | |
| return ( | ||
| <ListItem | ||
| titleClassName="text-lg" | ||
| onPress={info.item.onPress} | ||
| rightView={ | ||
| <View className="flex-1 flex-row items-center gap-0.5 px-2"> | ||
| {!!info.item.value && <Text className="text-muted-foreground">{info.item.value}</Text>} | ||
|
|
@@ -101,6 +111,11 @@ function Item({ info }: { info: ListRenderItemInfo<DataItem> }) { | |
|
|
||
| function ListHeaderComponent() { | ||
| const user = useUser(); | ||
| const { updateProfile } = useUpdateProfile(); | ||
| const { pickImage } = useImagePicker(); | ||
| const [isUploading, setIsUploading] = useState(false); | ||
| const { t } = useTranslation(); | ||
|
|
||
| const initials = | ||
| user?.firstName && user?.lastName | ||
| ? `${user.firstName[0]}${user.lastName[0]}` | ||
|
|
@@ -113,21 +128,66 @@ function ListHeaderComponent() { | |
|
|
||
| const username = user?.email || ''; | ||
|
|
||
| // Build the full avatar URL from the stored R2 key or an absolute URL | ||
| const avatarUri = user?.avatarUrl ? buildPackTemplateItemImageUrl(user.avatarUrl) : null; | ||
|
|
||
| async function handleAvatarPress() { | ||
| try { | ||
| const image = await pickImage(); | ||
| if (!image) return; | ||
|
|
||
| // Validate file size before uploading (5 MB limit) | ||
| const info = await FileSystem.getInfoAsync(image.uri, { size: true }); | ||
| if (info.exists && info.size > AVATAR_MAX_BYTES) { | ||
| Alert.alert(t('errors.somethingWentWrong'), t('profile.imageTooLarge')); | ||
| return; | ||
| } | ||
|
|
||
| setIsUploading(true); | ||
| const remoteFileName = await uploadImage(image.fileName, image.uri); | ||
| if (remoteFileName) { | ||
| const success = await updateProfile({ avatarUrl: remoteFileName }); | ||
| if (!success) { | ||
| Alert.alert(t('errors.somethingWentWrong'), t('errors.tryAgain')); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| if (err instanceof Error && err.message === 'Permission to access media library was denied') { | ||
| Alert.alert(t('permissions.photoLibraryTitle'), t('permissions.photoLibraryMessage'), [ | ||
| { text: t('common.cancel'), style: 'cancel' }, | ||
| { text: t('permissions.openSettings'), onPress: () => Linking.openSettings() }, | ||
| ]); | ||
| } else { | ||
| Alert.alert(t('errors.somethingWentWrong'), t('errors.tryAgain')); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } finally { | ||
| setIsUploading(false); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <SafeAreaView className="ios:pb-8 items-center pb-4 pt-8"> | ||
| <Avatar alt={`${displayName}'s Profile`} className="h-24 w-24"> | ||
| <AvatarFallback> | ||
| <Text | ||
| variant="largeTitle" | ||
| className={cn( | ||
| 'font-medium text-white dark:text-background', | ||
| Platform.OS === 'ios' && 'dark:text-foreground', | ||
| )} | ||
| > | ||
| {initials} | ||
| </Text> | ||
| </AvatarFallback> | ||
| </Avatar> | ||
| <TouchableOpacity onPress={handleAvatarPress} disabled={isUploading}> | ||
| <Avatar alt={`${displayName}'s Profile`} className="h-24 w-24"> | ||
|
Comment on lines
+170
to
+171
|
||
| {avatarUri ? <AvatarImage source={{ uri: avatarUri }} /> : null} | ||
| <AvatarFallback> | ||
| <Text | ||
| variant="largeTitle" | ||
| className={cn( | ||
| 'font-medium text-white dark:text-background', | ||
| Platform.OS === 'ios' && 'dark:text-foreground', | ||
| )} | ||
| > | ||
| {initials} | ||
| </Text> | ||
| </AvatarFallback> | ||
| </Avatar> | ||
| {isUploading && ( | ||
| <View className="absolute inset-0 items-center justify-center rounded-full bg-black/40"> | ||
| <ActivityIndicator color="white" /> | ||
| </View> | ||
| )} | ||
| </TouchableOpacity> | ||
| <View className="p-1" /> | ||
| <Text variant="title1">{displayName}</Text> | ||
| <Text className="text-muted-foreground">{username}</Text> | ||
|
|
@@ -214,7 +274,7 @@ function ListFooterComponent() { | |
| <Text className="text-destructive">{t('auth.logOut')}</Text> | ||
| )} | ||
| </Button> | ||
| <Alert title="" buttons={[]} ref={alertRef} /> | ||
| <AlertComponent title="" buttons={[]} ref={alertRef} /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { userStore } from 'expo-app/features/auth/store'; | ||
| import axiosInstance, { handleApiError } from 'expo-app/lib/api/client'; | ||
| import { useState } from 'react'; | ||
|
|
||
| export type UpdateProfilePayload = { | ||
| firstName?: string; | ||
| lastName?: string; | ||
| email?: string; | ||
| avatarUrl?: string | null; | ||
| }; | ||
|
|
||
| export function useUpdateProfile() { | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const updateProfile = async (payload: UpdateProfilePayload): Promise<boolean> => { | ||
| setIsLoading(true); | ||
| setError(null); | ||
| try { | ||
| const response = await axiosInstance.put('/api/user/profile', payload); | ||
| if (response.data?.user) { | ||
| userStore.set(response.data.user); | ||
| } | ||
| return true; | ||
| } catch (err) { | ||
| const { message } = handleApiError(err); | ||
| setError(message); | ||
| return false; | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| return { updateProfile, isLoading, error }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE "users" ADD COLUMN "avatar_url" text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the “Open Settings” action, this uses
Linking.openSettings()for all platforms. Elsewhere in the app, iOS usesLinking.openURL('app-settings:')withopenSettings()on other platforms (e.g.LocationSearchScreen). Consider matching that pattern here to avoid iOS settings-link inconsistencies.