import {
Form,
SubmitButton,
FormField,
ErrorMessage,
} from "../components/forms";
import React, { useState, useEffect } from "react";
import { StyleSheet, View, Text, TouchableNativeFeedback } from "react-native";
import Screen from "../components/Screen";
import { dimensions } from "../config/dimensions";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import colors from "../config/colors";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import * as Yup from "yup";
import FormDatePicker from "../components/forms/FormDatePicker";
import moment from "moment";
import { Shadow } from "react-native-shadow-2";
import SearchablePicker from "../components/SearchablePicker";
import { states, statesToCities } from "../assets/cities_states";
import { useFormikContext } from "formik";
const phoneRegex = RegExp(
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/
);
const validationSchema = Yup.object().shape({
name: Yup.string()
.required("O nome é obrigatória")
.matches(/[a-zA-Z]/, "O nome e só pode conter letras"),
number: Yup.string()
.matches(phoneRegex, "Número inválido")
.required("O número de telefone é obrigatório"),
password: Yup.string()
.required("A senha é obrigatória")
.min(8, "Senha muito curta, minimo 8 caracteres")
.matches(/[a-zA-Z]/, "A senha só pode conter letras"),
confirmPassword: Yup.string()
.required("A senha é obrigatória")
.min(8, "Senha muito curta, minimo 8 caracteres")
.matches(/[a-zA-Z]/, "A senha só pode conter letras"),
state: Yup.string().required("O estado é obrigatório"),
institutionName: Yup.string(),
secQuestionAns: Yup.string()
.required("A resposta da pergunta de segurança é obrigatória")
.max(255),
});
function LocalDatePicker({ date, setDate, _moment }) {
const formatDate = () => date.format("DD/MM/YYYY");
return (
setDate(value)}
minimumDate={new Date(moment().subtract(110, "year"))}
date={date}
>
{date != _moment
? formatDate()
: "Selecione a data de nascimento"}
);
}
function GenderPicker({ name }) {
const [items, setItems] = useState([
{ value: "Feminino", label: "Feminino" },
{ value: "Masculino", label: "Masculino" },
{ value: "Prefiro não dizer", label: "Prefiro não dizer" },
]);
return (
);
}
function InstitutionPicker({ name }) {
const [items, setItems] = useState([
{ value: "Escola", label: "Escola" },
{ value: "Defesa civil", label: "Defesa civil" },
{ value: "Não governamental", label: "Não governamental" },
{ value: "Outra", label: "Outra" },
{ value: "Nenhuma", label: "Nenhuma" },
]);
return (
);
}
function StatePicker({ name }) {
const [items, setItems] = useState(states);
return (
);
}
function CityPicker({ name }) {
const { values } = useFormikContext();
const state = values["state"];
useEffect(() => {
state && setItems(statesToCities[state].cities);
}, [state]);
const [items, setItems] = useState([]);
return (
);
}
function SecQuestionPicker({ name }) {
const [items, setItems] = useState([
{ value: "a", label: "Qual a sua cor predileta?" },
{ value: "s", label: "Qual foi o seu livro predileto?" },
{ value: "d", label: "Qual o nome da rua em que você cresceu?" },
{ value: "f", label: "Qual o nome do seu bicho de estimação predileto?" },
{ value: "g", label: "Qual a sua comida predileta?" },
{ value: "h", label: "Qual cidade você nasceu?" },
{ value: "j", label: "Qual é o seu país preferido?" },
{ value: "k", label: "Qual é a sua marca de carro predileto?" },
]);
return (
);
}
export default function RegisterScreen(props) {
const _moment = moment();
const [date, setDate] = useState(_moment);
const [singUpFailed, setSingUpFailed] = useState(false);
const comparePassword = (password, confirmPassword) => {
if (password !== confirmPassword) {
setSingUpFailed(true);
} else {
setSingUpFailed(false);
}
};
return (
);
}
const styles = StyleSheet.create({
containter: {
flex: 1,
justifyContent: "center",
textAlign: "center",
paddingHorizontal: 10,
},
labelStyle: {
fontSize: dimensions.text.secondary,
fontWeight: "bold",
textAlign: "left",
color: colors.secondary,
marginTop: 10,
},
iconField: {
width: "100%",
flex: 1,
alignItems: "center",
flexDirection: "row",
marginTop: 12,
marginBottom: 24,
},
dateInput: {
paddingLeft: 16,
},
});