handlers
This commit is contained in:
@@ -416,4 +416,14 @@ export default class API {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
static async updateUserCredentials(dataKey: string, value: any): Promise<string> {
|
||||
let validDataKeys: string = "password email";
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (!validDataKeys.includes(dataKey))
|
||||
return resolve("giga chad");
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import React from "react";
|
||||
import { translate } from "../../i18n/i18n";
|
||||
import { string } from "yup";
|
||||
import {
|
||||
FormControl,
|
||||
Input,
|
||||
Stack,
|
||||
WarningOutlineIcon,
|
||||
Box,
|
||||
Button,
|
||||
useToast,
|
||||
} from "native-base";
|
||||
|
||||
interface ChangeEmailFormProps {
|
||||
onSubmit: (newEmail: string) => Promise<string>;
|
||||
}
|
||||
|
||||
|
||||
const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => {
|
||||
const [formData, setFormData] = React.useState({
|
||||
newEmail: {
|
||||
value: "",
|
||||
error: null as string | null,
|
||||
}
|
||||
});
|
||||
|
||||
const [submittingForm, setSubmittingForm] = React.useState(false);
|
||||
const toast = useToast();
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack mx="4" style={{ width: '80%', maxWidth: 400 }}>
|
||||
<FormControl>
|
||||
<FormControl.Label>Test</FormControl.Label>
|
||||
<Input
|
||||
// type="text"
|
||||
// placeholder="Current Email address"
|
||||
// value={formData.newEmail.value}
|
||||
// onChangeText={(t) => {
|
||||
// let error: null | string = null;
|
||||
// setFormData({ ...formData, newEmail: { value: t, error } });
|
||||
// }
|
||||
// }
|
||||
/>
|
||||
</FormControl>
|
||||
<Button
|
||||
style={{ marginTop: 10 }}
|
||||
// isLoading={submittingForm}
|
||||
// isDisabled={
|
||||
// formData.newEmail.error !== null
|
||||
// }
|
||||
// onPress={async () => {
|
||||
// setSubmittingForm(true);
|
||||
// try {
|
||||
// const resp = await onSubmit(
|
||||
// formData.newEmail.value
|
||||
// );
|
||||
// toast.show({ description: resp });
|
||||
// } catch (e) {
|
||||
// toast.show({ description: e as string });
|
||||
// } finally {
|
||||
// setSubmittingForm(false);
|
||||
// }
|
||||
// }}
|
||||
>
|
||||
Bite
|
||||
</Button>
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default ChangeEmailForm
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from "react";
|
||||
import { translate } from "../../i18n/i18n";
|
||||
import { string } from "yup";
|
||||
import {
|
||||
FormControl,
|
||||
Input,
|
||||
Stack,
|
||||
WarningOutlineIcon,
|
||||
Box,
|
||||
Button,
|
||||
useToast,
|
||||
} from "native-base";
|
||||
|
||||
|
||||
interface ChangePasswordFormProps {
|
||||
onSubmit: (oldPassword: string, newPassword: string) => Promise<string>;
|
||||
}
|
||||
|
||||
|
||||
const ChangePasswordForm = ({ onSubmit }: ChangePasswordFormProps) => {
|
||||
const [formData, setFormData] = React.useState({
|
||||
username: {
|
||||
value: "",
|
||||
error: null as string | null,
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack mx="4" style={{ width: '80%', maxWidth: 400 }}>
|
||||
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default ChangePasswordForm
|
||||
@@ -10,9 +10,30 @@ import { SettingsState, updateSettings } from '../state/SettingsSlice';
|
||||
import { AvailableLanguages, translate, Translate } from "../i18n/i18n";
|
||||
import TextButton from '../components/TextButton';
|
||||
|
||||
import API from '../API';
|
||||
|
||||
|
||||
const SettingsStack = createNativeStackNavigator();
|
||||
|
||||
export const MainView = ({navigation}) => {
|
||||
const handleChangeEmail = async (newEmail: string): Promise<string> => {
|
||||
try {
|
||||
let response = await API.updateUserCredentials("email", newEmail);
|
||||
return response as string;
|
||||
} catch (error) {
|
||||
return ("error: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
const handleChangePassword = async (oldPassword: string, newPassword: string): Promise<string> => {
|
||||
try {
|
||||
let response = await API.updateUserCredentials("password", newPassword);
|
||||
return response as string;
|
||||
} catch (error) {
|
||||
return ("error: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
const MainView = ({navigation}) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return (
|
||||
@@ -218,7 +239,7 @@ export const ChangeEmailView = ({navigation}) => {
|
||||
return (
|
||||
<Center style={{ flex: 1}}>
|
||||
<Button onPress={() => navigation.navigate('Main')}>Back</Button>
|
||||
<Text>ChangeEmail</Text>
|
||||
<ChangeEmailView></ChangeEmailView>
|
||||
</Center>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user