Browse Source

Fixing username/phonenumber in use error. Scroll to top when true

master
GabrielTrettel 3 years ago
parent
commit
fd3581a994
  1. 72
      src/app/screens/RegisterScreen.js

72
src/app/screens/RegisterScreen.js

@ -38,7 +38,7 @@ import ConfirmationModal from "../components/ConfirmationModal";
import PasswordFormField from "../components/forms/PasswordFormField"; import PasswordFormField from "../components/forms/PasswordFormField";
import constants from "../config/constants"; import constants from "../config/constants";
import CheckBox from "../components/forms/CheckBox"; import CheckBox from "../components/forms/CheckBox";
import defaultStyles from "../config/styles"
import defaultStyles from "../config/styles";
const phoneRegex = RegExp( const phoneRegex = RegExp(
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/ /^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/
@ -81,31 +81,31 @@ function LocalDatePicker({ date, setDate, _moment }) {
date={date} date={date}
> >
<View style={[styles.dateInput, { flex: 1, paddingRight: 2 }]}> <View style={[styles.dateInput, { flex: 1, paddingRight: 2 }]}>
<View
<View
style={{
...defaultStyles.shadow,
height: 58,
paddingLeft: 12,
backgroundColor: colors.white,
borderColor: colors.grayBG,
borderWidth: 1,
padding: 5,
borderRadius: 6,
flexDirection: "row",
alignItems: "center",
}}
>
<Text
style={{ style={{
...defaultStyles.shadow,
height: 58,
paddingLeft: 12,
backgroundColor: colors.white,
borderColor: colors.grayBG,
borderWidth: 1,
padding: 5,
borderRadius: 6,
flexDirection: "row",
alignItems: "center",
color: colors.medium,
fontSize: 18,
}} }}
> >
<Text
style={{
color: colors.medium,
fontSize: 18,
}}
>
{date != _moment
? formatDate()
: "Selecione a data de nascimento"}
</Text>
</View>
{date != _moment
? formatDate()
: "Selecione a data de nascimento"}
</Text>
</View>
</View> </View>
</FormDatePicker> </FormDatePicker>
</View> </View>
@ -319,15 +319,23 @@ export default function RegisterScreen(props) {
}; };
const handleSubmit = async (form) => { const handleSubmit = async (form) => {
console.log(form);
const formDate = const formDate =
date.format("DD/MM/yyyy") === moment().format("DD/MM/yyyy") ? "" : date; date.format("DD/MM/yyyy") === moment().format("DD/MM/yyyy") ? "" : date;
const result = await signup({ ...form, dateofborn: formDate }); const result = await signup({ ...form, dateofborn: formDate });
// console.log(JSON.stringify(result))
switch (result.status) { switch (result.status) {
case 200: case 200:
automaticLogin(form); automaticLogin(form);
break; break;
case 422:
setShowLog({
show: true,
message: "Campo obrigatório não informado",
});
break;
default: default:
setShowLog({ setShowLog({
show: true, show: true,
@ -342,13 +350,13 @@ export default function RegisterScreen(props) {
if (ru.data) { if (ru.data) {
actions.setFieldError("number", "Este número de telefone já está em uso"); actions.setFieldError("number", "Este número de telefone já está em uso");
inUse = false;
inUse = true;
} }
const rn = await existNickname(form.name); const rn = await existNickname(form.name);
if (rn.data) { if (rn.data) {
actions.setFieldError("name", "Este apelido de usuário já está em uso"); actions.setFieldError("name", "Este apelido de usuário já está em uso");
inUse = false;
inUse = true;
} }
if (!ru.ok || !rn.ok) if (!ru.ok || !rn.ok)
@ -394,13 +402,11 @@ export default function RegisterScreen(props) {
comparePassword(form.password, form.confirmPassword); comparePassword(form.password, form.confirmPassword);
fieldsAreNotInUse(form, actions).then((isNotUsed) => { fieldsAreNotInUse(form, actions).then((isNotUsed) => {
isNotUsed && handleSubmit(form);
// NOTE: this woud be nice, but does not work...
// : scroll.scrollTo({
// x: 0,
// y: 0,
// animated: true,
// });
if (isNotUsed) {
handleSubmit(form);
} else {
scroll.scrollTo({ x: 0, y: 0, animated: true });
}
}); });
}} }}
validationSchema={validationSchema} validationSchema={validationSchema}
@ -535,7 +541,6 @@ export default function RegisterScreen(props) {
/> />
</View> </View>
<Text style={styles.labelStyle}>Termos de uso*</Text> <Text style={styles.labelStyle}>Termos de uso*</Text>
<View <View
flexDirection={"column"} flexDirection={"column"}
@ -555,7 +560,6 @@ export default function RegisterScreen(props) {
backgroundColor={colors.primary} backgroundColor={colors.primary}
/> />
<TouchableNativeFeedback <TouchableNativeFeedback
onPress={() => { onPress={() => {
props.navigation.goBack(); props.navigation.goBack();

Loading…
Cancel
Save