Commit e9fa692c by G

user can login with valid credentials and be redirected to the home screen

parent c43baa54
import { useUserAuthenticationContext } from "@/contexts/UserAuthenticationContext";
import type { UnloggedUserStackScreenComponentProps } from "@/navigations/Types"; import type { UnloggedUserStackScreenComponentProps } from "@/navigations/Types";
import authenticateUser from "@/utils/requests/authenticateUser";
import Button from "@components/Button"; import Button from "@components/Button";
import ContainerBorderTopCurved from "@components/ContainerBorderTopCurved"; import ContainerBorderTopCurved from "@components/ContainerBorderTopCurved";
import Input from "@components/Input"; import Input from "@components/Input";
...@@ -7,6 +9,8 @@ import Box from "@components/bases/Box"; ...@@ -7,6 +9,8 @@ import Box from "@components/bases/Box";
import Text from "@components/bases/Text"; import Text from "@components/bases/Text";
import { Fontisto } from "@expo/vector-icons"; import { Fontisto } from "@expo/vector-icons";
import { containers } from "@styles/Commons"; import { containers } from "@styles/Commons";
import { useMutation } from "@tanstack/react-query";
import { useCallback, useState } from "react";
import { KeyboardAvoidingView, Platform, TouchableOpacity, View } from "react-native"; import { KeyboardAvoidingView, Platform, TouchableOpacity, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useSafeAreaInsets } from "react-native-safe-area-context";
...@@ -14,12 +18,34 @@ const UserLoginScreen: UnloggedUserStackScreenComponentProps<"userLoginScreen"> ...@@ -14,12 +18,34 @@ const UserLoginScreen: UnloggedUserStackScreenComponentProps<"userLoginScreen">
navigation, navigation,
}) => { }) => {
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const { setAuthenticationData } = useUserAuthenticationContext();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const authenticationMutation = useMutation({
mutationFn: authenticateUser,
onSuccess: (data) => {
setAuthenticationData(data);
navigation.navigate("bottomTabs");
},
onError: (error) => {
console.error("error :: ", error);
},
});
const submit = useCallback(() => {
authenticationMutation.mutate({
username: email,
password: password,
});
}, [email, password, authenticationMutation]);
return ( return (
<BackgroundDefault> <BackgroundDefault>
<View style={[containers.containerFull, { paddingTop: insets.top }]}> <View style={[containers.containerFull, { paddingTop: insets.top }]}>
<KeyboardAvoidingView <KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "height" : "height"} behavior={Platform.OS === "ios" ? "padding" : "position"}
style={{ flex: 1 }} style={{ flex: 1 }}
> >
<Box style={{ height: "20%" }} px={"l"}> <Box style={{ height: "20%" }} px={"l"}>
...@@ -48,8 +74,19 @@ const UserLoginScreen: UnloggedUserStackScreenComponentProps<"userLoginScreen"> ...@@ -48,8 +74,19 @@ const UserLoginScreen: UnloggedUserStackScreenComponentProps<"userLoginScreen">
</Box> </Box>
<Box gap={"m"}> <Box gap={"m"}>
<Input label="Email" /> <Input
<Input label="Mot de passe" secureTextEntry={true} /> label="Email"
// value={email}
textContentType="emailAddress"
onChangeText={setEmail}
/>
<Input
label="Mot de passe"
secureTextEntry={true}
textContentType="oneTimeCode"
// value={password}
onChangeText={setPassword}
/>
</Box> </Box>
</Box> </Box>
<Box p={"s"}> <Box p={"s"}>
...@@ -57,7 +94,10 @@ const UserLoginScreen: UnloggedUserStackScreenComponentProps<"userLoginScreen"> ...@@ -57,7 +94,10 @@ const UserLoginScreen: UnloggedUserStackScreenComponentProps<"userLoginScreen">
variant={"full"} variant={"full"}
textVariants={"primary"} textVariants={"primary"}
label="Se connecter" label="Se connecter"
onPress={() => navigation.navigate("bottomTabs")} onPress={() => {
// navigation.navigate("bottomTabs");
submit();
}}
/> />
<Button <Button
variant={"lightGray"} variant={"lightGray"}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment