diff --git a/app/(modals)/profile.tsx b/app/(modals)/profile.tsx index 67d73520a..1ab2f42fd 100644 --- a/app/(modals)/profile.tsx +++ b/app/(modals)/profile.tsx @@ -3,7 +3,6 @@ import { MenuView, NativeActionEvent } from "@react-native-menu/menu"; import { useHeaderHeight } from "@react-navigation/elements"; import { useTheme } from "@react-navigation/native"; import * as ImagePicker from "expo-image-picker" -import { router } from "expo-router"; import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { @@ -19,13 +18,13 @@ import OnboardingInput from "@/components/onboarding/OnboardingInput"; import { useAccountStore } from "@/stores/account"; import Avatar from "@/ui/components/Avatar"; import Button from "@/ui/components/Button"; -import Icon from "@/ui/components/Icon"; -import { NativeHeaderPressable, NativeHeaderSide } from "@/ui/components/NativeHeader"; import Typography from "@/ui/components/Typography"; import { getInitials } from "@/utils/chats/initials"; +import { useNavigation } from "expo-router"; export default function CustomProfileScreen() { const { t } = useTranslation(); + const navigation = useNavigation(); const store = useAccountStore.getState(); const accounts = useAccountStore((state) => state.accounts); const lastUsedAccount = useAccountStore((state) => state.lastUsedAccount); @@ -44,13 +43,22 @@ export default function CustomProfileScreen() { } }, [account]); + // Automatic save + useEffect(() => { + const unsubscribe = navigation.addListener('beforeRemove', () => { + updateAccountName(); + }); + + return unsubscribe; + }, [navigation, firstName, lastName]); + const insets = useSafeAreaInsets() const updateProfilePictureFromLibrary = async () => { const result = await ImagePicker.launchImageLibraryAsync({ - mediaTypes: ['images', 'videos'], + mediaTypes: "images", allowsEditing: true, - aspect: [4, 3], + aspect: [1, 1], quality: 1, base64: true }); @@ -64,27 +72,37 @@ export default function CustomProfileScreen() { const updateProfilePictureFromService = async () => { Alert.alert( t("Feature_Soon"), - "Cette fonctionnalité n'est pas encore disponible, mais elle le sera dans une prochaine mise à jour.", + t("Feature_Soon_Notification"), [{ text: "OK" }] ); } + const updateAccountName = () => { + const trimmedFirstName = firstName.trim(); + const trimmedLastName = lastName.trim(); + + if (!trimmedFirstName || !trimmedLastName) return; + + useAccountStore.getState().setAccountName(lastUsedAccount, trimmedFirstName, trimmedLastName); + } + const { colors } = useTheme(); const height = useHeaderHeight(); return ( - + @@ -145,17 +163,18 @@ export default function CustomProfileScreen() { - Prénom + {t("Label_FirstName")} - Nom + + {t("Label_LastName")} - - { - useAccountStore.getState().setAccountName(lastUsedAccount, firstName, lastName); - router.back(); - }} - > - - - - - - + ); } \ No newline at end of file diff --git a/app/(tabs)/index/atoms/UserProfile.tsx b/app/(tabs)/index/atoms/UserProfile.tsx index a0ebbe7f2..b282da38e 100644 --- a/app/(tabs)/index/atoms/UserProfile.tsx +++ b/app/(tabs)/index/atoms/UserProfile.tsx @@ -23,7 +23,7 @@ const UserProfile = ({ subtitle, chevron, onPress }: { subtitle?: string, chevro > { - router.push("/(modals)/profile"); + router.navigate("/(modals)/profile"); }} >