import API from '../../API';
import { useDispatch } from 'react-redux';
import { unsetAccessToken } from '../../state/UserSlice';
import React from 'react';
import { Column, Text, Button, Box, Flex, Center, Heading, Popover, Toast } from 'native-base';
import TextButton from '../../components/TextButton';
import { LoadingView } from '../../components/Loading';
import ElementList from '../../components/GtkUI/ElementList';
import { translate } from '../../i18n/i18n';
import { useQuery } from '../../Queries';
import UserAvatar from '../../components/UserAvatar';
import * as ImagePicker from 'expo-image-picker';
// Too painful to infer the settings-only, typed navigator. Gave up
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ProfileSettings = ({ navigation }: { navigation: any }) => {
const userQuery = useQuery(API.getUserInfo);
const dispatch = useDispatch();
if (!userQuery.data || userQuery.isLoading) {
return ;
}
const user = userQuery.data;
return (
{
navigation.navigate('changeEmail');
},
},
},
{
type: 'text',
title: translate('verified'),
data: {
text: user.emailVerified ? 'verified' : 'not verified',
onPress: user.emailVerified
? undefined
: () =>
API.fetch({ route: '/auth/reverify', method: 'PUT' })
.then(() =>
Toast.show({
description: 'Verification mail sent',
})
)
.catch((e) => {
console.error(e);
Toast.show({
description: 'Verification mail send error',
});
}),
},
},
{
type: 'text',
title: translate('avatar'),
data: {
text: translate('changeIt'),
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: 'Update successful',
});
})
.catch((e) => {
console.error(e);
Toast.show({ description: 'Update failed' });
});
}
});
},
},
},
]}
/>
Unlink
// : ,
},
{
type: 'text',
title: translate('nbGamesPlayed'),
data: {
text: user.data.gamesPlayed.toString(),
},
},
{
type: 'text',
title: 'XP',
description: translate('XPDescription'),
data: {
text: user.data.xp.toString(),
},
},
{
type: 'text',
title: translate('userCreatedAt'),
helperText:
'La date de création est actuellement arbitraire car le serveur ne retourne pas cette information',
data: {
text: user.data.createdAt.toLocaleDateString(),
},
},
{
type: 'text',
title: translate('premiumAccount'),
data: {
text: translate(user.premium ? 'yes' : 'no'),
},
},
]}
/>
Fonctionnalités premium
{},
},
},
{
type: 'dropdown',
title: 'Thème de piano',
disabled: true,
data: {
value: 'default',
onSelect: () => {},
options: [
{
label: 'Default',
value: 'default',
},
{
label: 'Catpuccino',
value: 'catpuccino',
},
],
},
},
]}
/>
{!user.isGuest && (
dispatch(unsetAccessToken())}
translate={{
translationKey: 'signOutBtn',
}}
/>
)}
{user.isGuest && (
(
)}
>
{translate('Attention')}
{translate('YouAreCurrentlyConnectedWithAGuestAccountWarning')}
)}
);
};
export default ProfileSettings;