import React, { useEffect, useState } from 'react'; import { ScrollView, View, Text } from 'react-native'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import { Formik } from 'formik'; import * as yup from 'yup'; import { useNavigation } from '@react-navigation/native'; import { useQueryClient } from '@tanstack/react-query'; import { Image } from 'expo-image'; import { API_HOST } from '../../../../constants'; import { AvatarPicker, BigText, Header, Input, PageWrapper, Button } from '../../../../components'; import { InputDatePicker } from '../../../../components/Calendar/InputDatePicker'; import { ModalFlatList } from '../../../../components/FlatList/modal-flatlist'; import { usePostGetProfileQuery } from '../../../../modules/auth/user/queries/use-post-get-profile'; import { useGetRegionsWithFlagQuery } from '../../../../modules/auth/regions/queries/use-post-get-regions'; import { usePostSetProfileMutation } from '../../../../modules/auth/user/queries/use-post-set-profile'; import { userQueryKeys } from '../../../../modules/auth/user/user-query-keys'; import type { PostSetProfileData } from '../../../../modules/auth/user/user-api'; import { storageGet } from '../../../../storage'; import { Colors } from '../../../../theme'; import FacebookIcon from '../../../../../assets/icons/facebook.svg'; import InstagramIcon from '../../../../../assets/icons/instagram.svg'; import XIcon from '../../../../../assets/icons/x(twitter).svg'; import YoutubeIcon from '../../../../../assets/icons/youtube.svg'; import GlobeIcon from '../../../../../assets/icons/bottom-navigation/globe.svg'; import LinkIcon from '../../../../../assets/icons/link.svg'; const ProfileSchema = yup.object({ username: yup.string().optional(), email: yup.string().email().optional(), first_name: yup.string().optional(), last_name: yup.string().optional(), date_of_birth: yup.string().optional(), homebase: yup.number().optional(), homebase2: yup.number().nullable().optional(), bio: yup.string().optional(), f: yup.string().optional(), t: yup.string().optional(), i: yup.string().optional(), y: yup.string().optional(), www: yup.string().optional(), other: yup.string().optional() }); export const EditPersonalInfo = () => { const [token, setToken] = useState(''); const { mutate: updateProfile, data: updateResponse, reset } = usePostSetProfileMutation(); useEffect(() => { async function getToken() { setToken((await storageGet('token')) as unknown as string); } reset(); getToken(); }, []); const navigation = useNavigation(); const queryClient = useQueryClient(); const { data, error } = usePostGetProfileQuery(token!, true); const regions = useGetRegionsWithFlagQuery(true); if (!data) return Loading; const originRegion = regions.data?.data.find((region) => region.id === data.homebase); const secondOrigin = regions.data?.data.find((region) => region.id === data.homebase2); return (
{ const profileData: PostSetProfileData = { token: token, user: { username: values.username, email: values.email, first_name: values.first_name, last_name: values.last_name, date_of_birth: values.date_of_birth, homebase: values.homebase, bio: values.bio, f: values.f, i: values.i, t: values.t, y: values.y, www: values.www, other: values.other } }; if (values.homebase2) { profileData.user!.homebase2 = values.homebase2; } if (values.photo.uri) { profileData.photo = { type: values.photo.type, uri: values.photo.uri, name: values.photo.uri.split('/').pop()! }; } updateProfile(profileData, { onSuccess: () => { queryClient.invalidateQueries({ queryKey: userQueryKeys.getProfileData(), refetchType: 'all' }); Image.clearDiskCache(); Image.clearMemoryCache(); navigation.goBack(); } }); }} > {(props) => ( props.setFieldValue('photo', asset)} /> Account General Info props.setFieldValue('date_of_birth', date)} formikError={props.touched.date_of_birth && props.errors.date_of_birth} /> props.setFieldValue('homebase', data.id)} /> props.setFieldValue('homebase2', data.id)} /> Links } placeholder={'https://www.facebook.com'} inputMode={'text'} onChange={props.handleChange('f')} value={props.values.f as unknown as string} onBlur={props.handleBlur('f')} formikError={props.touched.f && props.errors.f} /> } placeholder={'https://www.instagram.com'} inputMode={'text'} onChange={props.handleChange('i')} value={props.values.i as unknown as string} onBlur={props.handleBlur('i')} formikError={props.touched.i && props.errors.i} /> } placeholder={'https://www.twitter.com'} inputMode={'text'} onChange={props.handleChange('t')} value={props.values.t as unknown as string} onBlur={props.handleBlur('t')} formikError={props.touched.t && props.errors.t} /> } placeholder={'https://www.youtube.com'} inputMode={'text'} onChange={props.handleChange('y')} value={props.values.y as unknown as string} onBlur={props.handleBlur('y')} formikError={props.touched.y && props.errors.y} /> } placeholder={'My Website'} inputMode={'text'} onChange={props.handleChange('www')} value={props.values.www as unknown as string} onBlur={props.handleBlur('www')} formikError={props.touched.www && props.errors.www} /> } placeholder={'Other link'} inputMode={'text'} onChange={props.handleChange('other')} value={props.values.other as unknown as string} onBlur={props.handleBlur('other')} formikError={props.touched.other && props.errors.other} /> )} ); };