|
|
@ -4,7 +4,7 @@ import { |
|
|
|
FormField, |
|
|
|
ErrorMessage, |
|
|
|
} from "../components/forms"; |
|
|
|
import React, { useState, useEffect } from "react"; |
|
|
|
import React, { useState, useEffect, useContext } from "react"; |
|
|
|
import { StyleSheet, View, Text, TouchableNativeFeedback } from "react-native"; |
|
|
|
import Screen from "../components/Screen"; |
|
|
|
import { dimensions } from "../config/dimensions"; |
|
|
@ -19,7 +19,10 @@ import SearchablePicker from "../components/SearchablePicker"; |
|
|
|
import { states, statesToCities } from "../assets/cities_states"; |
|
|
|
import { useFormikContext } from "formik"; |
|
|
|
import Checkbox from "../components/forms/CheckBox"; |
|
|
|
import {signup} from "../api/auth"; |
|
|
|
import {signup, login, userPersonalData} from "../api/auth"; |
|
|
|
import { AuthContext } from "../auth/context"; |
|
|
|
import authStorage from "../auth/storage"; |
|
|
|
import jwdDecode from "jwt-decode"; |
|
|
|
|
|
|
|
const phoneRegex = RegExp( |
|
|
|
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/ |
|
|
@ -227,6 +230,7 @@ function MaterialCommunityIconsCustom({ |
|
|
|
); |
|
|
|
} |
|
|
|
export default function RegisterScreen(props) { |
|
|
|
const authContext = useContext(AuthContext); |
|
|
|
const _moment = moment(); |
|
|
|
const [date, setDate] = useState(_moment); |
|
|
|
const [singUpFailed, setSingUpFailed] = useState(false); |
|
|
@ -239,9 +243,31 @@ export default function RegisterScreen(props) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const automaticLogin = async (form) => { |
|
|
|
const result = await login(form.number, form.password); |
|
|
|
|
|
|
|
if (!result.ok) return; |
|
|
|
|
|
|
|
authStorage.setToken(result.data); |
|
|
|
const user = await userPersonalData(result.data); |
|
|
|
user.ok && authContext.setUser(user.data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const handleSubmit = async (form) => { |
|
|
|
const result = await signup({...form, dateofborn: date.format("DD/MM/yyyy")}); |
|
|
|
console.log(result); |
|
|
|
const formDate = date.format("DD/MM/yyyy") === moment().format("DD/MM/yyyy") ? "" : date; |
|
|
|
|
|
|
|
const result = await signup({...form, dateofborn: formDate}) |
|
|
|
switch (result.status) { |
|
|
|
case 200: |
|
|
|
automaticLogin(form) |
|
|
|
break; |
|
|
|
case 422: |
|
|
|
// setError()
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
return ( |
|
|
|