import { ButtonContainer, TextContainer, WrapperContainer } from "@components/atoms"; import { AuthHeader, CustomTextInput, RememberMe } from "@components/molecules"; import fontFamily from "@constants/fontFamily"; import imagePath from "@constants/imagePath"; import { useCustomPost } from "@hooks/useMutationQuery"; import type { AuthStackParamList } from "@navigations/AuthStack"; import type { NavigationProp } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native"; import { useDispatch } from "@redux/hooks"; import { saveUserData } from "@redux/reducers/auth"; import { moderateScale, verticalScale } from "@utils/scaling"; import validate from "@utils/validations"; import React, { useState } from "react"; import { Alert, Keyboard, TouchableWithoutFeedback, View } from "react-native"; import { createStyleSheet, useStyles } from "react-native-unistyles"; import LoginResponse, { LoginRequestData } from "./types"; const stylesheet = createStyleSheet(() => ({ container: { flex: 1, marginHorizontal: moderateScale(16), justifyContent: "space-between", }, bottomView: { flexDirection: "row", alignItems: "center", alignSelf: "center", }, })); const alertFunction = (title: string, message: string) => { Alert.alert( title, message, [ { text: "Cancel", onPress: () => {}, style: "cancel", }, { text: "OK", onPress: () => {} }, ], { cancelable: false }, ); }; const Login = (): React.JSX.Element => { const navigation = useNavigation>(); const [username, setUsername] = useState("kminchelle"); const [password, setPassword] = useState("0lelplR"); const { styles } = useStyles(stylesheet); const dispatch = useDispatch(); const { mutate, isPending } = useCustomPost( "/auth/login", { onSuccess: ({ data }) => { // @ts-expect-error : will fix later dispatch(saveUserData(data)); }, onError: () => { alertFunction("Error", "An error occurred"); }, }, ); const onLogin = async () => { const isValid = validate({ name: username, password, }); if (isValid === true) { mutate({ username, password }); } }; return ( alertFunction("Password", "Forgot Password")} /> navigation.navigate("Signup", { username })} text="SIGNUP" style={{ marginLeft: moderateScale(4), fontFamily: fontFamily.semiBold, }} /> ); }; export default Login;