import API from '../../API'; import React from 'react'; import { Column, Toast } from 'native-base'; import { LoadingView } from '../../components/Loading'; import ElementList from '../../components/GtkUI/ElementList'; import { translate } from '../../i18n/i18n'; import { useQuery } from '../../Queries'; import * as ImagePicker from 'expo-image-picker'; import { Google, PasswordCheck, SmsEdit, UserSquare, Verify } from 'iconsax-react-native'; import ChangeEmailForm from '../../components/forms/changeEmailForm'; import ChangePasswordForm from '../../components/forms/changePasswordForm'; import LogoutButtonCC from '../../components/UI/LogoutButtonCC'; import { Platform, ScrollView } from 'react-native'; import APKDownloadButton from '../../components/APKDownloadButton'; const handleChangeEmail = async (newEmail: string): Promise => { await API.updateUserEmail(newEmail); return translate('emailUpdated'); }; const handleChangePassword = async (oldPassword: string, newPassword: string): Promise => { await API.updateUserPassword(oldPassword, newPassword); return translate('passwordUpdated'); }; // Too painful to infer the settings-only, typed navigator. Gave up // eslint-disable-next-line @typescript-eslint/no-explicit-any const ProfileSettings = () => { const userQuery = useQuery(API.getUserInfo); if (!userQuery.data || userQuery.isLoading) { return ; } const user = userQuery.data; return ( API.fetch({ route: '/auth/reverify', method: 'PUT' }) .then(() => Toast.show({ description: translate( 'settingsProfileTabVerifiedSectionVerificationToast' ), }) ) .catch((e) => { console.error(e); Toast.show({ description: translate( 'settingsProfileTabVerifiedSectionVerificationToastError' ), }); }), }, }, { icon: UserSquare, type: 'text', title: translate('settingsProfileTabAvatarSectionTitle'), description: translate('settingsProfileTabAvatarSectionDescription'), data: { text: translate('settingsProfileTabAvatarSectionChangeItText'), onPress: () => { ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, aspect: [1, 1], quality: 1, base64: true, }).then((result) => { console.log(result); const image = result.assets?.at(0); if (!result.canceled && image) { API.updateProfileAvatar(image) .then(() => { userQuery.refetch(); Toast.show({ description: translate( 'settingsProfileTabAvatarSectionUpdateToast' ), }); }) .catch((e) => { console.error(e); Toast.show({ description: translate( 'settingsProfileTabAvatarSectionUpdateToastError' ), }); }); } }); }, }, }, { icon: SmsEdit, type: 'sectionDropdown', title: translate('settingsProfileTabChangeEmailSectionTitle'), description: translate( 'settingsProfileTabChangeEmailSectionDescription' ), data: { value: true, section: [ handleChangeEmail(newEmail) } />, ], }, }, { icon: PasswordCheck, type: 'sectionDropdown', title: translate('settingsProfileTabChangePasswordSectionTitle'), description: translate( 'settingsProfileTabChangePasswordSectionDescription' ), data: { value: true, section: [ handleChangePassword(oldPassword, newPassword) } />, ], }, }, ]} /> {Platform.OS === 'web' && } ); }; export default ProfileSettings;