Skip to content

Commit

Permalink
Merge pull request #490 from hopetambala/PLATFORM_584_v2
Browse files Browse the repository at this point in the history
Platform 584 v2
  • Loading branch information
hopetambala authored Jul 23, 2022
2 parents 95db3e9 + 9a1abd5 commit adee493
Show file tree
Hide file tree
Showing 14 changed files with 4,387 additions and 29,482 deletions.
64 changes: 44 additions & 20 deletions components/Button/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
import PropTypes from 'prop-types';
import * as React from 'react';
import { Button } from 'react-native-paper';
import { Button as PaperButton } from 'react-native-paper';

import { layout, theme } from '../../modules/theme';

export default function PaperButton({
onPressEvent, buttonText,
mode, compact, icon, disabled, loading,
const colorStyle = {
primary: theme.colors.primary,
accent: theme.colors.accent,
empty: theme.colors.placeholder,
black: theme.colors.black
};

const Button = ({
onPress, buttonText,
mode, compact, icon, disabled, loading, color,
style
}) {
return (
<Button
icon={icon || ''}
mode={mode || 'contained'}
disabled={!!disabled}
theme={theme}
style={[layout.button, style]}
onPress={onPressEvent}
compact={!!compact}
loading={!!loading}
>
{buttonText}
</Button>
);
}
}) => (
<PaperButton
icon={icon || ''}
mode={mode || 'contained'}
disabled={!!disabled}
theme={theme}
style={[layout.button, style]}
onPress={onPress}
compact={!!compact}
loading={!!loading}
color={colorStyle[color]}
>
{buttonText}
</PaperButton>
);

Button.defaultProps = {
color: 'primary',
icon: '',
disabled: false,
loading: false
};

Button.propTypes = {
color: PropTypes.oneOf(['primary', 'accent', 'empty', 'black']),
icon: PropTypes.string,
disabled: PropTypes.bool,
loading: PropTypes.bool,
onPress: PropTypes.func.isRequired
};

export default Button;
4 changes: 2 additions & 2 deletions components/FormikFields/PaperInputPicker/Geolocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ const Geolocation = ({ errors, formikKey, setFieldValue }) => {
<View key={formikKey}>
{location === null && (
<PaperButton
onPressEvent={handleLocation}
onPress={handleLocation}
buttonText={I18n.t('paperButton.getLocation')}
/>
)}
{location !== null && (
<View>
<PaperButton
onPressEvent={handleLocation}
onPress={handleLocation}
buttonText={I18n.t('paperButton.getLocationAgain')}
/>
<View style={{ marginLeft: 'auto', marginRight: 'auto', flexDirection: 'row' }}>
Expand Down
4 changes: 2 additions & 2 deletions context/auth.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ export const UserContextProvider = ({ children }) => {
* @returns User Object
*/

const register = async (params) => {
const register = async (params, notificationType) => {
const { password } = params;
storeData(password, 'password');
setIsLoading(true);
try {
const u = await retrieveSignUpFunction(params);
const u = await retrieveSignUpFunction(params, notificationType);
setUser(u);
setError(null);
setIsLoading(false);
Expand Down
53 changes: 38 additions & 15 deletions domains/Auth/SignUp/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Formik } from 'formik';
import React, { useContext } from 'react';
import React, { useContext, useState } from 'react';
import {
ActivityIndicator,
KeyboardAvoidingView,
Expand All @@ -10,10 +10,11 @@ import {
} from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import {
Button, Checkbox, Text
Checkbox, Text
} from 'react-native-paper';
import * as yup from 'yup';

import Button from '../../../components/Button';
import FormInput from '../../../components/FormikFields/FormInput';
import Autofill from '../../../components/FormikFields/PaperInputPicker/AutoFill';
import TermsModal from '../../../components/TermsModal';
Expand Down Expand Up @@ -56,13 +57,12 @@ const validationSchema = yup.object().shape({

// export default () => (
export default function SignUp({ navigation }) {
const [checked, setChecked] = React.useState(false);
const [visible, setVisible] = React.useState(false);
const [scrollViewScroll, setScrollViewScroll] = React.useState();
const [checked, setChecked] = useState(false);
const [visible, setVisible] = useState(false);
const [scrollViewScroll, setScrollViewScroll] = useState();
const [notificationType, setNotificationType] = useState('email');

const { register } = useContext(UserContext);
const handleLogIn = () => {
navigation.navigate('Sign In');
};

return (
<KeyboardAvoidingView
Expand All @@ -71,15 +71,18 @@ export default function SignUp({ navigation }) {
style={{ backgroundColor: theme.colors.accent, flex: 1 }}
>
<View>
<Button icon="arrow-left" width={100} style={{ paddingTop: 40 }} onPress={handleLogIn}>
Back
</Button>
<Button
icon="arrow-left"
onPress={() => navigation.navigate('Sign In')}
buttonText="Back"
style={[styles.serviceButton, { marginTop: 60 }]}
/>
<ScrollView
style={{ backgroundColor: theme.colors.accent }}
keyboardShouldPersistTaps="never"
scrollEnabled={scrollViewScroll}
>
<SafeAreaView style={{ marginTop: 10 }}>
<SafeAreaView style={{ marginTop: 50, marginBottom: 150 }}>
<Formik
initialValues={{
firstname: '', lastname: '', email: '', phonenumber: '', password: '', password2: '', organization: ''
Expand All @@ -90,7 +93,7 @@ export default function SignUp({ navigation }) {
} else if (values.password !== values.password2) {
alert(I18n.t('signUp.errorPassword')) // eslint-disable-line
} else {
register(values)
register(values, notificationType)
.then(() => navigation.navigate('Root')).catch((error) => {
// sign up failed alert user
console.log(`Error: ${error.code} ${error.message}`); // eslint-disable-line
Expand Down Expand Up @@ -145,6 +148,18 @@ export default function SignUp({ navigation }) {
placeholder="Password Here"
secureTextEntry
/>
<Button
color={notificationType === 'email' ? 'primary' : 'empty'}
onPress={() => setNotificationType('email')}
buttonText="Send confirmation via email?"
style={styles.serviceButton}
/>
<Button
color={notificationType === 'text' ? 'primary' : 'empty'}
onPress={() => setNotificationType('text')}
buttonText="Send confirmation via text?"
style={styles.serviceButton}
/>
<Autofill
parameter="organization"
formikProps={formikProps}
Expand All @@ -154,7 +169,11 @@ export default function SignUp({ navigation }) {
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
/>
<Button mode="text" theme={theme} color="#3E81FD" style={styles.serviceButton} onPress={() => setVisible(true)}>{I18n.t('signUp.termsOfService.view')}</Button>
<Button
onPress={() => setVisible(true)}
buttonText={I18n.t('signUp.termsOfService.view')}
style={styles.serviceButton}
/>
<View style={styles.container}>
<Text style={styles.serviceText}>
{I18n.t('signUp.termsOfService.acknoledgement')}
Expand All @@ -173,7 +192,11 @@ 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
onPress={formikProps.handleSubmit}
buttonText={I18n.t('signUp.submit')}
style={styles.serviceButton}
/>
)}

<TermsModal visible={visible} setVisible={setVisible} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ const PeopleModal = ({
{people.length !== 1 && (
<PaperButton
buttonText={I18n.t('peopleModal.remove')}
onPressEvent={() => handleRemoveClick(i)}
onPress={() => handleRemoveClick(i)}
/>
)}
{people.length - 1 === i && (
<PaperButton
buttonText={I18n.t('peopleModal.add')}
onPressEvent={handleAddClick}
onPress={handleAddClick}
/>
)}
</View>
Expand Down
4 changes: 2 additions & 2 deletions domains/DataCollection/Assets/NewAssets/AssetCore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const AssetCore = ({
<ActivityIndicator />
) : (
<PaperButton
onPressEvent={formikProps.handleSubmit}
onPress={formikProps.handleSubmit}
buttonText={_.isEmpty(formikProps.values) ? I18n.t('global.emptyForm') : I18n.t('assetForms.createAsset')}
icon={_.isEmpty(formikProps.values) ? 'alert-octagon' : 'plus'}
style={{ backgroundColor: _.isEmpty(formikProps.values) ? 'red' : 'green' }}
Expand All @@ -110,7 +110,7 @@ const AssetCore = ({
<PaperButton
mode="text"
buttonText={I18n.t('assetCore.swipeAttachForm')}
onPressEvent={() => setPage('assetSupplementary')}
onPress={() => setPage('assetSupplementary')}
/>
<PopupError
error={submissionError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ const AssetSupplementary = ({
<PaperButton
disabled={!validForm()}
style={{ backgroundColor: validForm() ? 'green' : '#f75231' }}
onPressEvent={() => formikProps.handleSubmit()}
onPress={() => formikProps.handleSubmit()}
icon={validForm() ? 'plus' : 'alert-octagon'}
buttonText={validForm() ? I18n.t('global.submit') : I18n.t('assetForms.attachForm')}
/>
)}
<PaperButton
mode="text"
buttonText={I18n.t('assetCore.tapCreateAsset')}
onPressEvent={() => setPage('assetCore')}
onPress={() => setPage('assetCore')}
/>
</View>
<PopupError
Expand Down
2 changes: 1 addition & 1 deletion domains/DataCollection/Forms/IdentificationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const IdentificationForm = ({
/>
) : (
<PaperButton
onPressEvent={formikProps.handleSubmit}
onPress={formikProps.handleSubmit}
buttonText={_.isEmpty(formikProps.values) ? I18n.t('global.emptyForm') : I18n.t('global.submit')}
icon={_.isEmpty(formikProps.values) ? 'alert-octagon' : 'plus'}
style={{ backgroundColor: _.isEmpty(formikProps.values) ? 'red' : 'green' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const OfflineData = ({ surveyingOrganization, scrollViewScroll, setScrollViewScr
{(formikProps) => (
<View style={layout.formContainer}>
<PaperButton
onPressEvent={repopulateAllData}
onPress={repopulateAllData}
buttonText="Populate all ID Forms"
loading={!!isLoading}
style={{ backgroundColor: 'blue' }}
Expand All @@ -66,14 +66,14 @@ const OfflineData = ({ surveyingOrganization, scrollViewScroll, setScrollViewScr
</View>
))}
<PaperButton
onPressEvent={formikProps.handleSubmit}
onPress={formikProps.handleSubmit}
buttonText={_.isEmpty(formikProps.values) ? I18n.t('global.emptyForm') : I18n.t('global.submit')}
disabled={!!_.isEmpty(formikProps.values)}
icon={_.isEmpty(formikProps.values) ? 'alert-octagon' : 'plus'}
style={{ backgroundColor: _.isEmpty(formikProps.values) ? '#FFDDDD' : 'green' }}
/>
<PaperButton
onPressEvent={() => deleteData('residentData')}
onPress={() => deleteData('residentData')}
buttonText="Clear Cached ID Forms"
icon="delete"
style={{ backgroundColor: 'red' }}
Expand Down
Loading

0 comments on commit adee493

Please sign in to comment.