Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T173 generic field #174

Merged
merged 24 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bf0f692
Making Docker build more easy , with node-alpine image, and updating …
SabinoGs Apr 9, 2018
3365af2
Init of the GenericField component
SabinoGs Apr 10, 2018
e9be180
Verificacao inicial do texto em GenericField
SabinoGs Apr 10, 2018
ddfe139
error message when not pass the regexp test
SabinoGs Apr 11, 2018
fcc75ee
generic field update
SabinoGs Apr 12, 2018
e3357f2
Reverse Dockerfile config
SabinoGs Apr 12, 2018
f1a00d4
Reverse package.json
SabinoGs Apr 12, 2018
9bf84f6
package.json
SabinoGs Apr 12, 2018
c131100
#166 - Adjusting generic text input
matheusoliveira30 Apr 12, 2018
a4b869a
Merge branch 'T166-RegistrationFormValidation' of https://github.com/…
matheusoliveira30 Apr 12, 2018
7237ab6
#166 - MINOR: Fixing validation parameters
matheusoliveira30 Apr 12, 2018
24849b0
#166 - MINOR: Removed workarround for generic input
matheusoliveira30 Apr 12, 2018
c7ed599
#166 - Initial state for working generic field
matheusoliveira30 Apr 12, 2018
54fd914
#166 - MINOR: Fixing eslint issues discovered by CI
matheusoliveira30 Apr 12, 2018
d363805
#166 - MINOR: Updating RegisterScreen Jest Snapshot
matheusoliveira30 Apr 12, 2018
1840e20
Merge branch 'master' of https://github.com/Ronyell/2017.2-MerendaMai…
matheusoliveira30 Apr 17, 2018
9a88def
Co-authored-by: Matheus Oliveira <matheus_oliveira30@hotmail.com>
matheusoliveira30 Apr 17, 2018
6556b2d
Merge branch 'master' of https://github.com/Ronyell/2017.2-MerendaMai…
matheusoliveira30 Apr 17, 2018
50a4ea1
Co-authored-by: Matheus Oliveira <matheus_oliveira30@hotmail.com>
matheusoliveira30 Apr 17, 2018
ea9a63b
166 - MINOR: Updating Jest snapshot for RegisterScreen
matheusoliveira30 Apr 17, 2018
34686b6
Merge branch 'T166-RegistrationFormValidation' of https://github.com/…
matheusoliveira30 Apr 19, 2018
2e89a90
#166 - MINOR: Small refactoring in GenericField
matheusoliveira30 Apr 19, 2018
a9ea8be
#166 - New styles for generic input
matheusoliveira30 Apr 19, 2018
cf8fcdc
166 - MINOR: Updating Style path
SabinoGs Apr 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/screens/__snapshots__/RegisterScreen.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ exports[`Testing RegisterScreen renders as expected 1`] = `
}
}
>
<GenericField
errorMessage="Está errado!"
header="Genérico"
icon="chevrons-up"
placeholderMessage="Componente de Input"
regexInput={/\\\\w\\{6,\\}/}
setStateValue={[Function]}
/>
<Text
accessible={true}
allowFontScaling={true}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ merenda_mais:
echo 32768 | sudo tee -a /proc/sys/fs/inotify/max_queued_events
echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches
npm start
"
"
17 changes: 17 additions & 0 deletions src/Styles/GeneralStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ const { height } = Dimensions.get('window');
const { width } = Dimensions.get('window');

const styles = {

genericViewSection: {
flex: 1,
flexDirection: 'row',
padding: 10,
marginTop: 1,
backgroundColor: '#FAFAFA',
justifyContent: 'flex-start',
alignItems: 'center',
borderRadius: 7,
marginBottom: 10,
borderWidth: 1,
borderColor: 'gray',
},
genericInputBox: {
marginBotom: 10,
},
bigButton: {
paddingVertical: 20,
borderWidth: 1,
Expand Down
81 changes: 81 additions & 0 deletions src/components/GenericField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Text, View, TextInput } from 'react-native';
import styles from '../Styles/GeneralStyles';

export default class GenericField extends Component {
constructor(props) {
super(props);

this.state = {
styleInUse: styles.InputFieldStyle,
errorTextArea: <Text />,
text: '',
validValue: -1,
};
}

handleInput(newText) {
this.setState({ text: newText.trim() }, () => {
this.validateText(this.state.text, this.props.validorRegex);
});
}

handleUpdate() {
if (this.state.validValue) {
this.setState({ errorTextArea: <Text /> });
this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#80FF80', borderWidth: 2 }] });
} else {
this.setState({ errorTextArea: <Text>{this.props.errorMessage}</Text> });
this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#FF9999', borderWidth: 2 }] });
}
}

validateText(text, regexTest) {
if (regexTest.global) {
console.warn('validateText()', 'Regexp using global flag! The results may be wrong.');
} else {
// Do nothing
}

const isValid = regexTest.test(text);

if (isValid) {
console.warn('Valido');
this.setState({ validValue: true }, () => {
this.handleUpdate();
});
} else {
console.warn('Invalido');
this.setState({ validValue: false }, () => {
this.handleUpdate();
});
}
}

render() {
return (
<View>
<Text> {this.props.header.toUpperCase()} </Text>
<TextInput
style={this.state.styleInUse}
placeholder={this.props.message}
value={this.state.test}
onChangeText={text => this.handleInput(text)}
/>

{this.state.errorTextArea}

</View>
);
}
}

GenericField.propTypes = {
header: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
validorRegex: PropTypes.string.isRequired,
errorMessage: PropTypes.string.isRequired,
};

// export default GenericField;
15 changes: 15 additions & 0 deletions src/screens/RegisterScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import CpfField from '../components/CpfField';
import NameField from '../components/NameField';
import EmailField from '../components/EmailField';
import PasswordField from '../components/PasswordField';
import GenericField from '../components/GenericField';
import PhoneField from '../components/PhoneField';
import DropdownComponent from '../components/DropdownComponent';
import MunicipalDistrict from '../components/MunicipalDistrict';
Expand Down Expand Up @@ -119,6 +120,7 @@ export default class RegisterScreen extends React.Component {
super(props);

this.state = {
teste: '',
email: '',
name: '',
password: '',
Expand Down Expand Up @@ -246,13 +248,26 @@ export default class RegisterScreen extends React.Component {
logInfo(FILE_NAME, 'render()',
`State of register page: ${JSON.stringify(this.state, null, 2)}`);

// Testing regex list
const sixMoreWordCharRegex = /\w{6,}/;

return (
<View style={styles.principal}>
<Header />
<KeyboardAvoidingView style={styles.content} behavior="padding">
<ScrollView>
<View style={{ paddingHorizontal: 15 }}>

<GenericField
header="Genérico"
placeholderMessage="Componente de Input"
icon="chevrons-up"
setStateValue={newValue => this.setState({ teste: newValue })}
onChange={console.warn('OnChange', this.state.teste)}
regexInput={sixMoreWordCharRegex}
errorMessage="Está errado!"
/>

<Text>CPF</Text>
<CpfField
value={this.state.profile.cpf}
Expand Down