Skip to content

Commit

Permalink
fix: loading icon on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Jan 29, 2021
1 parent 78953f8 commit cc67451
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
31 changes: 18 additions & 13 deletions domains/DataCollection/Forms/IdentificationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Formik } from 'formik';

import { postIdentificationForm } from '../../../../modules/cached-resources';
import { isEmpty } from '../../../../modules/utils';
import { layout } from '../../../../modules/theme';
import { layout, theme } from '../../../../modules/theme';
import I18n from '../../../../modules/i18n';

import PaperButton from '../../../../components/Button';
Expand Down Expand Up @@ -38,6 +38,7 @@ const IdentificationForm = ({
const [inputs, setInputs] = useState({});
const [photoFile, setPhotoFile] = useState('State Photo String');
const [validationSchema, setValidationSchema] = useState();
const [submitting, setSubmitting] = useState(false)

useEffect(() => {
setInputs(configArray);
Expand All @@ -48,7 +49,8 @@ const IdentificationForm = ({
<TouchableWithoutFeedback onPress={Keyboard.dismiss()} accessible={false}>
<Formik
initialValues={{}}
onSubmit={async (values, actions) => {
onSubmit={async (values) => {
setSubmitting(true)
setPhotoFile('Submitted Photo String');

const formObject = values;
Expand All @@ -69,7 +71,7 @@ const IdentificationForm = ({
const submitAction = () => {
setTimeout(() => {
setSelectedForm('');
actions.setSubmitting(false);
setSubmitting(false)
}, 1000);
};

Expand Down Expand Up @@ -110,17 +112,20 @@ const IdentificationForm = ({
formikProps={formikProps}
inputs={inputs}
/>
{formikProps.isSubmitting ? (
<ActivityIndicator />
) : (
<PaperButton
onPressEvent={formikProps.handleSubmit}
buttonText={I18n.t('global.submit')}
{submitting ? (
<ActivityIndicator
size="large"
color={theme.colors.primary}
/>
// <Button icon="human" onPress={formikProps.handleSubmit}>
// <Text>Submit</Text>
// </Button>
)}
) : (
<PaperButton
onPressEvent={formikProps.handleSubmit}
buttonText={I18n.t('global.submit')}
/>
// <Button icon="human" onPress={formikProps.handleSubmit}>
// <Text>Submit</Text>
// </Button>
)}
</View>
)}
</Formik>
Expand Down
37 changes: 23 additions & 14 deletions domains/DataCollection/Forms/SupplementaryForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Formik } from 'formik';

import { postSupplementaryForm } from '../../../../modules/cached-resources';

import { layout } from '../../../../modules/theme';
import { layout, theme } from '../../../../modules/theme';
import I18n from '../../../../modules/i18n';
import { isEmpty } from '../../../../modules/utils';

Expand All @@ -31,6 +31,7 @@ const SupplementaryForm = ({
const [config, setConfig] = useState({});
const [photoFile, setPhotoFile] = useState('State Photo String');
const [validationSchema, setValidationSchema] = useState();
const [submitting, setSubmitting] = useState(false)

const toRoot = () => {
navigation.navigate('Root');
Expand All @@ -55,7 +56,8 @@ const SupplementaryForm = ({
return (
<Formik
initialValues={{}}
onSubmit={async (values, actions) => {
onSubmit={async (values) => {
setSubmitting(true);
setPhotoFile('Submitted Photo String');

const formObject = values;
Expand Down Expand Up @@ -93,11 +95,15 @@ const SupplementaryForm = ({
};
}

postSupplementaryForm(postParams).then(() => {
const submitAction = () => {
setTimeout(() => {
actions.setSubmitting(false);
setSubmitting(false);
toRoot();
}, 1000);
};

postSupplementaryForm(postParams).then(() => {
submitAction();
});
}}
validationSchema={validationSchema}
Expand All @@ -123,17 +129,20 @@ const SupplementaryForm = ({
inputs={config.fields}
/>

{formikProps.isSubmitting ? (
<ActivityIndicator />
{submitting ? (
<ActivityIndicator
size="large"
color={theme.colors.primary}
/>
) : (
<Button
disabled={!surveyee.objectId}
onPress={formikProps.handleSubmit}
>
{surveyee.objectId && <Text>{I18n.t('global.submit')}</Text>}
{!surveyee.objectId && <Text>{I18n.t('supplementaryForms.attachResident')}</Text>}
</Button>
)}
<Button
disabled={!surveyee.objectId}
onPress={formikProps.handleSubmit}
>
{surveyee.objectId && <Text>{I18n.t('global.submit')}</Text>}
{!surveyee.objectId && <Text>{I18n.t('supplementaryForms.attachResident')}</Text>}
</Button>
)}
</View>
)}
</Formik>
Expand Down

0 comments on commit cc67451

Please sign in to comment.