Skip to content

Commit

Permalink
feat: autofill for sign up organization
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Feb 4, 2021
1 parent bafcd10 commit ec22084
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
25 changes: 16 additions & 9 deletions domains/Auth/SignUp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import TermsModal from '../../../components/TermsModal';
import { theme } from '../../../modules/theme';

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

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

Expand All @@ -43,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 @@ -61,7 +62,7 @@ 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');
};
Expand All @@ -75,7 +76,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 @@ -145,11 +149,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 @@ -170,8 +177,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
25 changes: 23 additions & 2 deletions modules/cached-resources/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ec22084

Please sign in to comment.