Skip to content

Commit

Permalink
feat: add modal for "incorrect password"
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Oct 15, 2020
1 parent 159a9ab commit 792251b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 74 deletions.
26 changes: 0 additions & 26 deletions domains/Auth/SignIn/SignInFailedModal/index.js

This file was deleted.

74 changes: 30 additions & 44 deletions domains/Auth/SignIn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ import {
import {
Checkbox, Button,
} from 'react-native-paper';

import * as Network from 'expo-network';

import { Formik } from 'formik';
import * as yup from 'yup';
import * as Network from 'expo-network';

import { retrieveSignInFunction, retrieveCurrentUserFunction } from '../../../services/parse/auth';
import FormInput from '../../../components/FormikFields/FormInput';
import LanguagePicker from '../../../components/LanguagePicker';
import CredentialsModal from './CredentialsModal';
import { storeData, getData, deleteData } from '../../../modules/async-storage';
import SignInFailedModal from './SignInFailedModal';

import { storeData, getData, deleteData } from '../../../modules/async-storage';
import I18n from '../../../modules/i18n';

// STYLING
import { theme } from '../../../modules/theme';

import FormInput from '../../../components/FormikFields/FormInput';
import LanguagePicker from '../../../components/LanguagePicker';
import CredentialsModal from './CredentialsModal';

const validationSchema = yup.object().shape({
username: yup
.string()
Expand All @@ -42,26 +43,13 @@ const validationSchema = yup.object().shape({
});

const SignIn = ({ navigation }) => {
const [checked, setChecked] = React.useState(false);
const [checked, setChecked] = useState(false);
const [modalVisible, setModalVisible] = useState(false);
const [user, setUser] = useState(null);
const [language, setLanguage] = useState('en');
const [failedModalVisible, setFailedModalVisible] = useState(false);


const load = false;

/*
THIS FUNCTION WILL CHANGE failedModalVisible to true to display the modal.
IT IS BEING CALLED ON LINE 161 of this file
*/
const handleFailedAttempt = () => {
if (failedModalVisible === false) {
console.log("SETTING")
setFailedModalVisible(true);
}
}

useEffect(() => {
getData('credentials').then((values) => {
setUser(values);
Expand All @@ -71,6 +59,14 @@ const SignIn = ({ navigation }) => {
});
}, [load]);

const handleFailedAttempt = (err) => {
const errorMsg = err.toString().slice(-26) || '';
Alert.alert(
`${errorMsg}`,
'Your username or password may be incorrect, please try again.',
{ cancelable: true }
);
};
const handleSignUp = () => {
navigation.navigate('Sign Up');
};
Expand Down Expand Up @@ -101,7 +97,6 @@ const SignIn = ({ navigation }) => {
I18n.locale = lang;
};

// checks whether user is connected to internet, return true if connected, false otherwise
async function checkOnlineStatus() {
const status = await Network.getNetworkStateAsync();
const { isConnected } = status;
Expand Down Expand Up @@ -154,14 +149,8 @@ const SignIn = ({ navigation }) => {
handleSaveCredentials(values);
});
navigation.navigate('Root');
}, (error) => {
// eslint-disable-next-line
console.log(error);
// handleFailedAttempt(setTest, test)
handleFailedAttempt();
console.log(failedModalVisible)

// console.log(visible)
}, (err) => {
handleFailedAttempt(err);
});
} else {
// offline
Expand Down Expand Up @@ -202,13 +191,13 @@ const SignIn = ({ navigation }) => {
secureTextEntry
/>
) : (
<FormInput
label={I18n.t('signIn.password')}
formikProps={formikProps}
formikKey="password"
placeholder="Password here"
/>
)}
<FormInput
label={I18n.t('signIn.password')}
formikProps={formikProps}
formikKey="password"
placeholder="Password here"
/>
)}
<View style={styles.container}>
<View style={styles.checkbox}>
<Checkbox
Expand All @@ -225,8 +214,8 @@ const SignIn = ({ navigation }) => {
{formikProps.isSubmitting ? (
<ActivityIndicator />
) : (
<Button mode="contained" theme={theme} style={styles.submitButton} onPress={formikProps.handleSubmit}>{I18n.t('signIn.submit')}</Button>
)}
<Button mode="contained" theme={theme} style={styles.submitButton} onPress={formikProps.handleSubmit}>{I18n.t('signIn.submit')}</Button>
)}
<Button mode="text" theme={theme} color="#3E81FD" onPress={handleSignUp}>
{I18n.t('signIn.signUpLink')}
</Button>
Expand All @@ -237,10 +226,7 @@ const SignIn = ({ navigation }) => {
setModalVisible={setModalVisible}
navigation={navigation}
/>
<SignInFailedModal
visible={failedModalVisible}
setVisible={setFailedModalVisible}
/>

</>
)}
</Formik>
Expand Down
2 changes: 1 addition & 1 deletion domains/DataCollection/FormGallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ const styles = StyleSheet.create({
buttonTextBig: {
fontSize: 16
}
})
});
export default FormGallery;
2 changes: 1 addition & 1 deletion domains/DataCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getData } from '../../modules/async-storage';
import FindResidents from '../../components/FindResidents';

import { retrieveCurrentUserFunction } from '../../services/parse/auth';
import { customQueryService } from '../../services/parse/crud';
import customQueryService from '../../services/parse/crud';

import ComingSoonSVG from '../../assets/graphics/static/Adventurer.svg';
import FindRecordSVG from '../../assets/graphics/static/Find-Record-Icon.svg';
Expand Down
2 changes: 1 addition & 1 deletion services/parse/crud/custom-queries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ function customQueryService(offset, limit, parseModel, parseColumn, parseParam)
});
}

export { customQueryService };
export default customQueryService;
2 changes: 1 addition & 1 deletion services/parse/crud/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Parse } from 'parse/react-native';
import { customQueryService } from './custom-queries';
import customQueryService from './custom-queries';

function retrieveHelloFunction() {
Parse.Cloud.run('hello').then((result) => result);
Expand Down

0 comments on commit 792251b

Please sign in to comment.