|
@@ -1,5 +1,5 @@
|
|
|
import React, { useState } from 'react';
|
|
|
-import { ScrollView, View } from 'react-native';
|
|
|
+import { ScrollView, View, Text, Linking, StyleSheet } from 'react-native';
|
|
|
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
|
|
import { Formik } from 'formik';
|
|
|
import * as yup from 'yup';
|
|
@@ -10,6 +10,7 @@ import { Image } from 'expo-image';
|
|
|
import {
|
|
|
usePostGetProfileQuery,
|
|
|
usePostSetProfileMutation,
|
|
|
+ usePostUpdateEmailMutation,
|
|
|
userQueryKeys,
|
|
|
type PostSetProfileData
|
|
|
} from '@api/user';
|
|
@@ -46,6 +47,7 @@ import { useDeleteUserMutation } from '@api/app';
|
|
|
import { useMessagesStore } from 'src/stores/unreadMessagesStore';
|
|
|
import { useAvatarStore } from 'src/stores/avatarVersionStore';
|
|
|
import { useFriendsNotificationsStore } from 'src/stores/friendsNotificationsStore';
|
|
|
+import { getFontSize } from 'src/utils';
|
|
|
|
|
|
const ProfileSchema = yup.object({
|
|
|
username: yup.string().optional(),
|
|
@@ -61,7 +63,8 @@ const ProfileSchema = yup.object({
|
|
|
i: yup.string().optional(),
|
|
|
y: yup.string().optional(),
|
|
|
www: yup.string().optional(),
|
|
|
- other: yup.string().optional()
|
|
|
+ other: yup.string().optional(),
|
|
|
+ new_email: yup.string().email().optional()
|
|
|
});
|
|
|
|
|
|
export const EditPersonalInfo = () => {
|
|
@@ -70,6 +73,7 @@ export const EditPersonalInfo = () => {
|
|
|
const { mutate: deleteUser } = useDeleteUserMutation();
|
|
|
|
|
|
const { mutate: updateProfile, data: updateResponse, reset } = usePostSetProfileMutation();
|
|
|
+ const { mutate: updateEmail } = usePostUpdateEmailMutation();
|
|
|
|
|
|
const navigation = useNavigation();
|
|
|
const queryClient = useQueryClient();
|
|
@@ -80,6 +84,7 @@ export const EditPersonalInfo = () => {
|
|
|
);
|
|
|
const updateUnreadMessagesCount = useMessagesStore((state) => state.updateUnreadMessagesCount);
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
|
+ const [isNewEmailSubmitted, setIsNewEmailSubmitted] = useState(false);
|
|
|
const { incrementAvatarVersion } = useAvatarStore();
|
|
|
|
|
|
const regions = useGetRegionsWithFlagQuery(true);
|
|
@@ -128,10 +133,26 @@ export const EditPersonalInfo = () => {
|
|
|
deleteUser({ token }, { onSuccess: handleLogout });
|
|
|
};
|
|
|
|
|
|
+ const handleVerifyEmailChange = async (newEmail: string) => {
|
|
|
+ setIsSubmitting(true);
|
|
|
+ await updateEmail(
|
|
|
+ { token, email: newEmail },
|
|
|
+ {
|
|
|
+ onSuccess: () => {
|
|
|
+ setIsSubmitting(false);
|
|
|
+ setIsNewEmailSubmitted(true);
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ setIsSubmitting(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<PageWrapper>
|
|
|
+ <Header label={'Edit Personal Info'} />
|
|
|
<ScrollView showsVerticalScrollIndicator={false}>
|
|
|
- <Header label={'Edit Personal Info'} />
|
|
|
<KeyboardAwareScrollView>
|
|
|
<Formik
|
|
|
validationSchema={ProfileSchema}
|
|
@@ -154,7 +175,8 @@ export const EditPersonalInfo = () => {
|
|
|
type: '',
|
|
|
uri: '',
|
|
|
name: ''
|
|
|
- }
|
|
|
+ },
|
|
|
+ new_email: ''
|
|
|
}}
|
|
|
onSubmit={async (values) => {
|
|
|
setIsSubmitting(true);
|
|
@@ -244,6 +266,51 @@ export const EditPersonalInfo = () => {
|
|
|
onBlur={props.handleBlur('email')}
|
|
|
formikError={props.touched.email && props.errors.email}
|
|
|
/>
|
|
|
+ <Input
|
|
|
+ editable={!isNewEmailSubmitted}
|
|
|
+ header={'Change email address'}
|
|
|
+ placeholder={'new_email@address.com'}
|
|
|
+ inputMode={'email'}
|
|
|
+ onChange={props.handleChange('new_email')}
|
|
|
+ value={props.values.new_email}
|
|
|
+ onBlur={props.handleBlur('new_email')}
|
|
|
+ formikError={props.touched.new_email && props.errors.new_email}
|
|
|
+ />
|
|
|
+ {!props.errors.new_email && props.values.new_email && !isNewEmailSubmitted ? (
|
|
|
+ <Button
|
|
|
+ onPress={() => handleVerifyEmailChange(props.values.new_email)}
|
|
|
+ disabled={isSubmitting}
|
|
|
+ variant={ButtonVariants.FILL}
|
|
|
+ >
|
|
|
+ Verify email change
|
|
|
+ </Button>
|
|
|
+ ) : (
|
|
|
+ <Button onPress={() => {}} disabled={true} variant={ButtonVariants.OPACITY}>
|
|
|
+ Verify email change
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {isNewEmailSubmitted ? (
|
|
|
+ <Text style={styles.text}>
|
|
|
+ Confirmation message sent. Please check your old email inbox.
|
|
|
+ </Text>
|
|
|
+ ) : (
|
|
|
+ <Text style={styles.text}>
|
|
|
+ We will send a confirmation message to your old email address. Once you click
|
|
|
+ the link in that message, your new email will become active. If you don't have
|
|
|
+ access to your old email mailbox, please contact us{' '}
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ color: Colors.ORANGE
|
|
|
+ }}
|
|
|
+ onPress={() => Linking.openURL('https://nomadmania.com/contact/')}
|
|
|
+ >
|
|
|
+ here
|
|
|
+ </Text>
|
|
|
+ .
|
|
|
+ </Text>
|
|
|
+ )}
|
|
|
+
|
|
|
<BigText>General Info</BigText>
|
|
|
<Input
|
|
|
header={'First name'}
|
|
@@ -390,3 +457,11 @@ export const EditPersonalInfo = () => {
|
|
|
</PageWrapper>
|
|
|
);
|
|
|
};
|
|
|
+
|
|
|
+const styles = StyleSheet.create({
|
|
|
+ text: {
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
+ fontSize: getFontSize(12),
|
|
|
+ fontFamily: 'redhat-600'
|
|
|
+ }
|
|
|
+});
|