Skip to content

Commit 7a88f21

Browse files
authored
Merge pull request #84 from JustinTan-1/main
Stay Logged in Checkbox
2 parents 073fa4f + fcd717e commit 7a88f21

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

src/components/AuthForm.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import 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';
33
import { Context as AuthContext } from 'src/components/context/AuthContext';
44
import tw from 'twrnc';
55

66
import Button from './Button';
7+
import CheckBox from './CheckBox';
78

89
interface 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
};

src/components/CheckBox.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Pressable, StyleSheet, Text, View } from "react-native";
2+
import React from "react";
3+
import { MaterialCommunityIcons } from "@expo/vector-icons";
4+
import tw from 'twrnc';
5+
6+
const CheckBox = (props) => {
7+
const iconName = props.isChecked ?
8+
"checkbox-marked" : "checkbox-blank-outline";
9+
10+
return (
11+
<View style={tw`flex-row items-center w-36 mt-1 mx-1`}>
12+
<Pressable onPress={props.onPress}>
13+
<MaterialCommunityIcons
14+
name={iconName} size={24} color="#FFFFFF" />
15+
</Pressable>
16+
<Text style={tw`text-white text-sm font-semibold ml-1`}>{props.title}</Text>
17+
</View>
18+
);
19+
};
20+
21+
export default CheckBox;

src/components/context/AuthContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ export const { Provider, Context } = createDataContext(
7474
authReducer,
7575
{ signin, signout, updateUser, tryLocalSignin },
7676
{ isSignedIn: false, token: null, user: null }
77-
);
77+
);

src/screens/CaseContactListScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const CaseContactListScreen = ({ navigation }) => {
2727
/>
2828
</View>
2929
</View>
30-
</View>
30+
</View>
3131
);
3232
};
3333

0 commit comments

Comments
 (0)