Browse Source

Merge branch 'main' of https://github.com/IGSD-UoW/WPD-MobileApp into main

master
analuizaff 3 years ago
parent
commit
0d8775525f
  1. 35
      src/app/screens/LoginScreen.js
  2. 4
      src/app/screens/RainSharingDataScreen.js
  3. 27
      src/app/screens/RegisterScreen.js
  4. 2
      src/app/screens/RiverFloodSharingDataScreen.js
  5. 1
      src/app/screens/SharingFloodZonesScreen.js

35
src/app/screens/LoginScreen.js

@ -18,6 +18,7 @@ import Button from "../components/Button";
import { TouchableNativeFeedback } from "react-native-gesture-handler";
import { login, userPersonalData } from "../api/auth";
import PasswordFormField from "../components/forms/PasswordFormField";
import ConfirmationModal from "../components/ConfirmationModal";
const phoneRegex = RegExp(
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/
@ -75,22 +76,40 @@ function DashedOrSeparator() {
export default function LoginScreen(props) {
const authContext = useContext(AuthContext);
const [showLog, setShowLog] = useState({ show: false, message: "" });
const handleSubmit = async (name, password, setLoginFailed) => {
const result = await login(name, password);
if (!result.ok) return setLoginFailed(true);
switch (result.status) {
case 404:
setLoginFailed(true);
return;
case 400:
setShowLog({
show: true,
message: "Um erro inesperado ocorreu. Tente novamente mais tarde",
});
return;
}
await authStorage.setToken(result.data);
// console.log("TOKEN: " + result.data);
setLoginFailed(false);
result.ok && setLoginFailed(false);
const user = await userPersonalData();
user.ok && authContext.setUser(user.data);
};
const [loginFailed, setLoginFailed] = useState(false);
return (
<Screen style={[styles.containter, { backgroundColor: colors.grayBG }]}>
<ConfirmationModal
show={showLog.show}
description={showLog.message}
confirmationLabel="OK"
onConfirm={() => setShowLog({ ...showLog, show: false })}
/>
<Form
initialValues={{
name: "",
@ -110,10 +129,12 @@ export default function LoginScreen(props) {
marginBottom={dimensions.spacing.big_padding}
/>
<ErrorMessage
error="Email ou senha inválidos"
visible={loginFailed}
/>
<View style={{ paddingHorizontal: 16, marginBottom: 12 }}>
<ErrorMessage
error="Email ou senha inválidos"
visible={loginFailed}
/>
</View>
<View style={{ paddingBottom: 24 }}>
<FormField

4
src/app/screens/RainSharingDataScreen.js

@ -209,7 +209,9 @@ const styles = StyleSheet.create({
backgroundColor: colors.white,
},
error_txt: {
fontSize: dimensions.text.default,
paddingHorizontal: 16,
marginTop: 12,
fontSize: 18,
color: colors.danger,
},
labelStyle: {

27
src/app/screens/RegisterScreen.js

@ -265,7 +265,7 @@ export default function RegisterScreen(props) {
const [date, setDate] = useState(_moment);
const [singUpFailed, setSingUpFailed] = useState(false);
const [scroll, setScroll] = useState();
const [showLog, setShowLog] = useState(false);
const [showLog, setShowLog] = useState({show: false, message: ""});
const comparePassword = (password, confirmPassword) => {
if (password !== confirmPassword) {
@ -286,25 +286,25 @@ export default function RegisterScreen(props) {
};
const handleSubmit = async (form) => {
console.log("apaaaaaaa");
const formDate =
date.format("DD/MM/yyyy") === moment().format("DD/MM/yyyy") ? "" : date;
const result = await signup({ ...form, dateofborn: formDate });
// console.log(result)
switch (result.status) {
case 200:
automaticLogin(form);
break;
case 422:
// setError()
default:
setShowLog({show: true, message: "Um erro inesperado ocorreu. Tente novamente mais tarde"})
}
};
const fieldsAreNotInUse = async (form, actions) => {
var inUse = true;
var inUse = false;
const ru = await existUsername(form.number);
if (ru.data) {
actions.setFieldError("number", "Este número de telefone já está em uso");
inUse = false;
@ -315,17 +315,22 @@ export default function RegisterScreen(props) {
actions.setFieldError("name", "Este apelido de usuário já está em uso");
inUse = false;
}
if (!ru.ok || !rn.ok)
setShowLog({show: true, message: "Um erro inesperado ocorreu. Tente novamente mais tarde"})
inUse && setShowLog({show: true, message: "Apelido de usuário ou telefone em uso"})
return inUse;
return !inUse;
};
return (
<Screen style={styles.containter}>
<ConfirmationModal
show={showLog}
description="Apelido de usuário ou telefone em uso"
show={showLog.show}
description={showLog.message}
confirmationLabel="OK"
onConfirm={() => setShowLog(false)}
onConfirm={() => setShowLog({...showLog, show:false})}
/>
<Form
initialValues={{
@ -347,7 +352,7 @@ export default function RegisterScreen(props) {
comparePassword(form.password, form.confirmPassword);
fieldsAreNotInUse(form, actions).then((isNotUsed) => {
isNotUsed ? handleSubmit(form) : setShowLog(true);
isNotUsed && handleSubmit(form);
// NOTE: this woud be nice, but does not work...
// : scroll.scrollTo({
// x: 0,

2
src/app/screens/RiverFloodSharingDataScreen.js

@ -219,6 +219,8 @@ const styles = StyleSheet.create({
justifyContent: "space-between",
},
error_txt: {
paddingHorizontal: 16,
marginTop: 12,
fontSize: 18,
color: colors.danger,
},

1
src/app/screens/SharingFloodZonesScreen.js

@ -181,6 +181,7 @@ const styles = StyleSheet.create({
justifyContent: "center",
},
error_txt: {
marginTop: 12,
paddingHorizontal: 16,
fontSize: 18,
color: colors.danger,

Loading…
Cancel
Save