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 { TouchableNativeFeedback } from "react-native-gesture-handler";
import { login, userPersonalData } from "../api/auth"; import { login, userPersonalData } from "../api/auth";
import PasswordFormField from "../components/forms/PasswordFormField"; import PasswordFormField from "../components/forms/PasswordFormField";
import ConfirmationModal from "../components/ConfirmationModal";
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})$/
@ -75,22 +76,40 @@ function DashedOrSeparator() {
export default function LoginScreen(props) { export default function LoginScreen(props) {
const authContext = useContext(AuthContext); const authContext = useContext(AuthContext);
const [showLog, setShowLog] = useState({ show: false, message: "" });
const handleSubmit = async (name, password, setLoginFailed) => { const handleSubmit = async (name, password, setLoginFailed) => {
const result = await login(name, password); 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); await authStorage.setToken(result.data);
// console.log("TOKEN: " + result.data);
setLoginFailed(false);
result.ok && setLoginFailed(false);
const user = await userPersonalData(); const user = await userPersonalData();
user.ok && authContext.setUser(user.data); user.ok && authContext.setUser(user.data);
}; };
const [loginFailed, setLoginFailed] = useState(false); const [loginFailed, setLoginFailed] = useState(false);
return ( return (
<Screen style={[styles.containter, { backgroundColor: colors.grayBG }]}> <Screen style={[styles.containter, { backgroundColor: colors.grayBG }]}>
<ConfirmationModal
show={showLog.show}
description={showLog.message}
confirmationLabel="OK"
onConfirm={() => setShowLog({ ...showLog, show: false })}
/>
<Form <Form
initialValues={{ initialValues={{
name: "", name: "",
@ -110,10 +129,12 @@ export default function LoginScreen(props) {
marginBottom={dimensions.spacing.big_padding} 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 }}> <View style={{ paddingBottom: 24 }}>
<FormField <FormField

4
src/app/screens/RainSharingDataScreen.js

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

27
src/app/screens/RegisterScreen.js

@ -265,7 +265,7 @@ export default function RegisterScreen(props) {
const [date, setDate] = useState(_moment); const [date, setDate] = useState(_moment);
const [singUpFailed, setSingUpFailed] = useState(false); const [singUpFailed, setSingUpFailed] = useState(false);
const [scroll, setScroll] = useState(); const [scroll, setScroll] = useState();
const [showLog, setShowLog] = useState(false);
const [showLog, setShowLog] = useState({show: false, message: ""});
const comparePassword = (password, confirmPassword) => { const comparePassword = (password, confirmPassword) => {
if (password !== confirmPassword) { if (password !== confirmPassword) {
@ -286,25 +286,25 @@ export default function RegisterScreen(props) {
}; };
const handleSubmit = async (form) => { const handleSubmit = async (form) => {
console.log("apaaaaaaa");
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(result)
switch (result.status) { switch (result.status) {
case 200: case 200:
automaticLogin(form); automaticLogin(form);
break; break;
case 422:
// setError()
default:
setShowLog({show: true, message: "Um erro inesperado ocorreu. Tente novamente mais tarde"})
} }
}; };
const fieldsAreNotInUse = async (form, actions) => { const fieldsAreNotInUse = async (form, actions) => {
var inUse = true;
var inUse = false;
const ru = await existUsername(form.number); const ru = await existUsername(form.number);
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 = false;
@ -316,16 +316,21 @@ export default function RegisterScreen(props) {
inUse = false; inUse = false;
} }
return inUse;
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 ( return (
<Screen style={styles.containter}> <Screen style={styles.containter}>
<ConfirmationModal <ConfirmationModal
show={showLog}
description="Apelido de usuário ou telefone em uso"
show={showLog.show}
description={showLog.message}
confirmationLabel="OK" confirmationLabel="OK"
onConfirm={() => setShowLog(false)}
onConfirm={() => setShowLog({...showLog, show:false})}
/> />
<Form <Form
initialValues={{ initialValues={{
@ -347,7 +352,7 @@ 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) : setShowLog(true);
isNotUsed && handleSubmit(form);
// NOTE: this woud be nice, but does not work... // NOTE: this woud be nice, but does not work...
// : scroll.scrollTo({ // : scroll.scrollTo({
// x: 0, // x: 0,

2
src/app/screens/RiverFloodSharingDataScreen.js

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

1
src/app/screens/SharingFloodZonesScreen.js

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

Loading…
Cancel
Save