11import React , { useState , useContext } from 'react' ;
2- import { TextInput , Text , StyleSheet } from 'react-native' ;
2+ import { TextInput , Text , StyleSheet , Modal , Alert , Pressable , View } from 'react-native' ;
33import { Context as AuthContext } from 'src/components/context/AuthContext' ;
44import tw from 'twrnc' ;
55
66import Button from './Button' ;
7+ import CheckBox from './CheckBox' ;
78
89interface LoginFieldProps {
910 errorMessage : string ;
1011 submitButtonText : string ;
11- onSubmit : ( { email, password } ) => void ;
12+ onSubmit : ( { email, password} ) => void ;
1213 style ?: StyleSheet . NamedStyles < any > ;
1314}
1415
@@ -20,6 +21,8 @@ const AuthForm: React.FC<LoginFieldProps> = ({
2021} ) => {
2122 const [ email , setEmail ] = useState < string > ( '' ) ;
2223 const [ password , setPassword ] = useState < string > ( '' ) ;
24+ const [ staySignedIn , setStaySignedIn ] = useState < boolean > ( false )
25+ const [ modalVisible , setModalVisible ] = useState < boolean > ( false ) ;
2326
2427 const { signin } = useContext ( AuthContext ) ;
2528
@@ -31,6 +34,11 @@ const AuthForm: React.FC<LoginFieldProps> = ({
3134 }
3235 } ;
3336
37+ const handleStaySignInToggle = ( ) => {
38+ setStaySignedIn ( ! staySignedIn ) ;
39+ if ( ! staySignedIn ) setModalVisible ( true ) ;
40+ } ;
41+
3442 return (
3543 < >
3644 < TextInput
@@ -50,13 +58,36 @@ const AuthForm: React.FC<LoginFieldProps> = ({
5058 autoCorrect = { false }
5159 onChangeText = { setPassword }
5260 />
61+ < CheckBox
62+ onPress = { handleStaySignInToggle }
63+ title = "Stay Logged In"
64+ isChecked = { staySignedIn }
65+ />
5366 { errorMessage && < Text className = "pl-4 text-red-500" > { errorMessage } </ Text > }
5467 < Button
5568 buttonStyle = { tw `flex bg-[#ea5a4e] rounded-3xl w-40 h-10 flex justify-center items-center` }
5669 textStyle = { tw `text-xl font-bold text-white` }
5770 title = "Sign In"
5871 onPress = { handleSignIn }
5972 />
73+ < Modal
74+ animationType = "slide"
75+ transparent = { true }
76+ visible = { modalVisible }
77+ onRequestClose = { ( ) => {
78+ setModalVisible ( ! modalVisible ) ;
79+ } } >
80+ < View style = { tw `flex-1 justify-center items-center` } >
81+ < View style = { tw `m-5 bg-white rounded-2xl p-9 items-center shadow-lg` } >
82+ < Text style = { tw `mb-4 text-center` } > Your session will stay active until you sign out.</ Text >
83+ < Pressable
84+ style = { tw `rounded-2xl px-4 py-2 bg-[#345073]` }
85+ onPress = { ( ) => setModalVisible ( ! modalVisible ) } >
86+ < Text style = { tw `text-white font-bold text-center` } > OK</ Text >
87+ </ Pressable >
88+ </ View >
89+ </ View >
90+ </ Modal >
6091 </ >
6192 ) ;
6293} ;
0 commit comments