Skip to content

Commit

Permalink
feat: autofill for organization
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Feb 7, 2021
1 parent 6bbe5ac commit 3a8d7ee
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 55 deletions.
58 changes: 37 additions & 21 deletions domains/Auth/SignUp/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { Formik } from 'formik';
import React from 'react';
import React, { useEffect } from 'react';
import {
ActivityIndicator,
KeyboardAvoidingView,
Platform,
SafeAreaView,
ActivityIndicator,
StyleSheet,
View
View,
KeyboardAvoidingView,
Platform
} from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import {
Button, Checkbox, Text
Checkbox, Button, Text
} from 'react-native-paper';
import { ScrollView } from 'react-native-gesture-handler';
import { Formik } from 'formik';
import * as yup from 'yup';
import { retrieveSignUpFunction } from '../../../services/parse/auth';

import FormInput from '../../../components/FormikFields/FormInput';
import TermsModal from '../../../components/TermsModal';
import { populateCache } from '../../../modules/cached-resources';
import I18n from '../../../modules/i18n';
// STYLING
import { theme } from '../../../modules/theme';
import { retrieveSignUpFunction } from '../../../services/parse/auth';

import { populateCache, cacheAutofillData } from '../../../modules/cached-resources';
import Autofill from '../../../components/FormikFields/PaperInputPicker/AutoFill';

import I18n from '../../../modules/i18n';

const validationSchema = yup.object().shape({
firstname: yup
Expand All @@ -41,7 +44,7 @@ const validationSchema = yup.object().shape({
.min(10, 'Seems a bit short..'),
organization: yup
.string()
.label('Username')
.label('Organization')
.required(),
password: yup
.string()
Expand All @@ -59,10 +62,17 @@ const validationSchema = yup.object().shape({
export default function SignUp({ navigation }) {
const [checked, setChecked] = React.useState(false);
const [visible, setVisible] = React.useState(false);

const [scrollViewScroll, setScrollViewScroll] = React.useState();
const handleLogIn = () => {
navigation.navigate('Sign In');
};

useEffect(() => {
cacheAutofillData('organization').then((result) => {
console.log(result)
})
}, [])

return (
<KeyboardAvoidingView
enabled
Expand All @@ -73,7 +83,10 @@ export default function SignUp({ navigation }) {
<Button icon="arrow-left" width={100} style={{ paddingTop: 40 }} onPress={handleLogIn}>
Back
</Button>
<ScrollView style={{ backgroundColor: theme.colors.accent }}>
<ScrollView style={{ backgroundColor: theme.colors.accent }}
keyboardShouldPersistTaps="never"
scrollEnabled={scrollViewScroll}
>
<SafeAreaView style={{ marginTop: 10 }}>
<Formik
initialValues={{
Expand Down Expand Up @@ -143,11 +156,14 @@ export default function SignUp({ navigation }) {
placeholder="Password Here"
secureTextEntry
/>
<FormInput
label={I18n.t('signUp.organization')}
<Autofill
parameter={"organization"}
formikProps={formikProps}
formikKey="organization"
placeholder="Puente"
formikKey={"organization"}
label={'signUp.organization'}
translatedLabel={"Organization"}
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
/>
<Button mode="text" theme={theme} color="#3E81FD" style={styles.serviceButton} onPress={() => setVisible(true)}>{I18n.t('signUp.termsOfService.view')}</Button>
<View style={styles.container}>
Expand All @@ -168,8 +184,8 @@ export default function SignUp({ navigation }) {
{formikProps.isSubmitting ? (
<ActivityIndicator />
) : (
<Button mode="contained" theme={theme} style={styles.submitButton} onPress={formikProps.handleSubmit}>{I18n.t('signUp.submit')}</Button>
)}
<Button mode="contained" theme={theme} style={styles.submitButton} onPress={formikProps.handleSubmit}>{I18n.t('signUp.submit')}</Button>
)}

<TermsModal visible={visible} setVisible={setVisible} />
</>
Expand Down Expand Up @@ -223,4 +239,4 @@ const styles = StyleSheet.create({
marginBottom: 'auto'

},
});
});
63 changes: 30 additions & 33 deletions modules/cached-resources/read.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { residentIDQuery, customQueryService } from '../../services/parse/crud';
import retrievePuenteAutofillData from '../../services/aws';
import { customQueryService, residentIDQuery } from '../../services/parse/crud';
import getTasks from '../../services/tasky';
import { getData, storeData } from '../async-storage';
import checkOnlineStatus from '../offline';
import { getData, storeData } from '../async-storage';
import getTasks from '../../services/tasky';

async function residentQuery(queryParams) {
let records = await residentIDQuery(queryParams);
Expand All @@ -22,8 +22,29 @@ async function cacheAutofillData(parameter) {
checkOnlineStatus().then((connected) => {
if (connected) {
retrievePuenteAutofillData('all').then((result) => {
storeData(result, 'autofill_information');
resolve(result[parameter]);
// cache organizations tied to all users
customQueryService(0, 500, 'User', 'adminVerified', "true").then((users) => {
const orgsCapitalized = [];
const orgResults = [];
users.forEach((user) => {
console.log(user.get("organization"))
const org = user.get("organization")
if (org !== null && org !== undefined && org !== '') {
const orgCapitalized = org.toUpperCase().trim() || '';
if (!orgsCapitalized.includes(orgCapitalized) && org !== '') {
orgsCapitalized.push(orgCapitalized);
orgResults.push(org);
}
}
});
const autofillData = result;
autofillData["organization"] = orgResults;
storeData(autofillData, 'autofill_information')
resolve(autofillData[parameter]);
}, () => {
storeData(result, 'autofill_information');
resolve(result[parameter]);
})
}, (error) => {
reject(error);
});
Expand Down Expand Up @@ -67,29 +88,6 @@ function customFormsQuery(surveyingOrganization) {
});
}

function assetFormsQuery() {
return new Promise((resolve, reject) => {
checkOnlineStatus().then((online) => {
if (online) {
customQueryService(0, 5000, 'FormSpecificationsV2', 'typeOfForm', 'Assets').then(async (forms) => {
await storeData(forms, 'assetForms');
resolve(JSON.parse(JSON.stringify(forms)));
}, (error) => {
reject(error);
});
} else {
getData('assetForms').then((forms) => {
resolve(forms);
}, (error) => {
reject(error);
});
}
}, (error) => {
reject(error);
});
});
}

function getTasksAsync() {
return new Promise((resolve, reject) => {
checkOnlineStatus().then(async (online) => {
Expand All @@ -114,10 +112,9 @@ function getTasksAsync() {
}

export {
assetFormsQuery,
cacheAutofillData,
residentQuery,
cacheResidentData,
cacheAutofillData,
customFormsQuery,
getTasksAsync,
residentQuery
};
getTasksAsync
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a8d7ee

Please sign in to comment.