Browse Source

fixing issue when retrieving user's pluviometer station

master
analuizaff 3 years ago
parent
commit
8bb2845fdd
  1. 1
      src/app/api/auth.js
  2. 38
      src/app/hooks/usePluviometricStation.js
  3. 4
      src/app/screens/AccountScreen.js
  4. 59
      src/app/screens/PluviometerRegisterScreen.js

1
src/app/api/auth.js

@ -35,7 +35,6 @@ function signup({
securityanswer: secQuestionAns, securityanswer: secQuestionAns,
termsofusage: consent, termsofusage: consent,
roles: role !== "" ? [role] : ["ROLE_CLIENT"], roles: role !== "" ? [role] : ["ROLE_CLIENT"],
pluviometer: false,
}; };
Object.entries(body).forEach(([key, value]) => { Object.entries(body).forEach(([key, value]) => {

38
src/app/hooks/usePluviometricStation.js

@ -10,7 +10,7 @@ async function getPluvStation_data(id) {
return null; return null;
} }
function assemblePluvStationObject(pluvData){
function assemblePluvStationObject(pluvData) {
var date = null; var date = null;
var time = null; var time = null;
var address = null; var address = null;
@ -18,31 +18,29 @@ function assemblePluvStationObject(pluvData){
var institutionName = null; var institutionName = null;
pluvData.array_to_json.forEach(function (field) { pluvData.array_to_json.forEach(function (field) {
if(field.fieldname == "eventaddress"){
if (field.fieldname == "eventaddress") {
address = field.fieldsanswersvalue; address = field.fieldsanswersvalue;
}
else if (field.fieldname == "eventdate") {
} else if (field.fieldname == "eventdate") {
date = field.fieldsanswersvalue; date = field.fieldsanswersvalue;
}
else if (field.fieldname == "eventtime") {
} else if (field.fieldname == "eventtime") {
time = field.fieldsanswersvalue; time = field.fieldsanswersvalue;
}
else if(field.fieldname== "institutename"){
} else if (field.fieldname == "institutename") {
institutionName = field.fieldsanswersvalue; institutionName = field.fieldsanswersvalue;
}
else if(field.fieldname== "institutetype"){
} else if (field.fieldname == "institutetype") {
institutionType = field.institutionType; institutionType = field.institutionType;
} }
}); });
return{
return {
regiterDate: date + " | " + time, regiterDate: date + " | " + time,
address: address, address: address,
institutionType: institutionType, institutionType: institutionType,
institutionName:institutionName,
coordinates:{lat: pluvData.formsanswerslatitude, long:pluvData.formsanswerslongitude}
}
institutionName: institutionName,
coordinates: {
lat: pluvData.formsanswerslatitude,
long: pluvData.formsanswerslongitude,
},
};
} }
async function getPluviometerStation(userId, setPluviometerStation) { async function getPluviometerStation(userId, setPluviometerStation) {
@ -53,14 +51,12 @@ async function getPluviometerStation(userId, setPluviometerStation) {
socketObject.onmessage = async ({ data }) => { socketObject.onmessage = async ({ data }) => {
const dataObject = JSON.parse(data); const dataObject = JSON.parse(data);
if (dataObject?.success) { if (dataObject?.success) {
pluvStation_id =
dataObject.responseData.array_to_json[0].formsanswersid;
pluvStation_data = await getPluvStation_data(
pluvStation_id
pluvStation_id = dataObject.responseData.array_to_json[0].formsanswersid;
pluvStation_data = await getPluvStation_data(pluvStation_id);
const pluvObject = assemblePluvStationObject(
pluvStation_data.data.responseData.array_to_json[0]
); );
const pluvObject = assemblePluvStationObject(pluvStation_data.data.responseData.array_to_json[0])
setPluviometerStation(pluvObject); setPluviometerStation(pluvObject);
} else { } else {
setPluviometerStation(false); setPluviometerStation(false);
} }

4
src/app/screens/AccountScreen.js

@ -77,7 +77,7 @@ function AccountScreen(props) {
const isRegistered = user?.username != null; const isRegistered = user?.username != null;
const [showLog, setShowLog] = useState(false); const [showLog, setShowLog] = useState(false);
console.log(user);
//console.log(user);
const logout = () => { const logout = () => {
setShowLog(false) setShowLog(false)
setUser(true); setUser(true);
@ -107,7 +107,7 @@ function AccountScreen(props) {
icon: "account", icon: "account",
show: isRegistered, show: isRegistered,
IconProvider: MaterialCommunityIcons, IconProvider: MaterialCommunityIcons,
title: "Cadastrar pluviômetro",
title: user.pluviometer? "Dados do pluviômetro" : "Cadastrar pluviômetro",
onPress: () => { onPress: () => {
props.navigation.navigate("PluviometerRegister"); props.navigation.navigate("PluviometerRegister");
}, },

59
src/app/screens/PluviometerRegisterScreen.js

@ -28,8 +28,8 @@ function Institution({ user }) {
}; };
return ( return (
<View style={{ marginBottom: 24 }}>
<Text style={styles.label}>Tipo de instituição: </Text>
<View style={{ marginBottom: 24, flex: 1 }}>
<Text style={styles.labelTipoInst}>Tipo de instituição: </Text>
<View style={{ flexDirection: "row", marginTop: 16 }}> <View style={{ flexDirection: "row", marginTop: 16 }}>
<FontAwesome5 name="university" size={30} color={colors.primary} /> <FontAwesome5 name="university" size={30} color={colors.primary} />
<Text style={styles.subText}> <Text style={styles.subText}>
@ -74,7 +74,9 @@ function LocationPicker({
{pluviometer && ( {pluviometer && (
<View style={{ flexDirection: "row", marginTop: 16 }}> <View style={{ flexDirection: "row", marginTop: 16 }}>
<Text style={styles.subText}> <Text style={styles.subText}>
{pluviometer?.address ? pluviometer.address : "Erro ao carregar endereço"}
{pluviometer.address
? pluviometer.address
: "Erro ao carregar endereço"}
</Text> </Text>
</View> </View>
)} )}
@ -141,11 +143,13 @@ function PluvDateTimePicker({
formTypeFace={formTypeFace} formTypeFace={formTypeFace}
/> />
)} )}
{pluviometer && ( {pluviometer && (
<View <View
style={{ style={{
flexDirection: "row", flexDirection: "row",
alignItems: "center", alignItems: "center",
alignContent: "center",
}} }}
> >
<MaterialCommunityIcons <MaterialCommunityIcons
@ -153,9 +157,11 @@ function PluvDateTimePicker({
size={30} size={30}
color={colors.primary} color={colors.primary}
/> />
<View style={{ flexDirection: "row", marginTop: 16 }}>
<Text style={styles.subText}>
{pluviometer.regiterDate ? pluviometer.regiterDate : "Erro ao carregar a data"}
<View style={styles.date}>
<Text style={styles.subTextDate}>
{pluviometer.regiterDate
? pluviometer.regiterDate
: "Erro ao carregar a data"}
</Text> </Text>
</View> </View>
</View> </View>
@ -209,9 +215,19 @@ function PluviometerRegisterScreen(props) {
}); });
}} }}
> >
<View style={{ padding: 6, flex: 1, flexDirection:"column" }}>
<View
style={{
padding: 6,
flex: 1,
flexDirection: "column",
justifyContent: "space-evenly",
}}
>
<View style={{ flex: 0.05 }}>
<Text style={styles.title}>Cadastro do Pluviômetro</Text> <Text style={styles.title}>Cadastro do Pluviômetro</Text>
<View style={{flex: 0.25}}>
</View>
<View style={{ flex: 0.95, justifyContent: "space-between" }}>
<View style={{ flex: 0.19 }}>
<Text <Text
style={{ style={{
marginTop: 24, marginTop: 24,
@ -234,7 +250,7 @@ function PluviometerRegisterScreen(props) {
pluviometer={user.pluviometer} pluviometer={user.pluviometer}
/> />
</View> </View>
<View style={{flex: 0.25}}>
<View style={{ flex: 0.19 }}>
<Text style={styles.label}>Endereço do pluviômetro*: </Text> <Text style={styles.label}>Endereço do pluviômetro*: </Text>
<View marginBottom={24}> <View marginBottom={24}>
@ -247,15 +263,20 @@ function PluviometerRegisterScreen(props) {
/> />
</View> </View>
</View> </View>
<View style={{flex: 0.25}}>
<View style={{ flex: 0.38 }}>
<Institution user={user} /> <Institution user={user} />
</View> </View>
<View style={{flex: 0.25}}>
<View style={{ flex: 0.19 }}>
{!user.pluviometer && ( {!user.pluviometer && (
<SubmitButton title="Cadastrar" paddingHorizontal={0} />
<SubmitButton
style={{ alignSelf: "" }}
title="Cadastrar"
paddingHorizontal={0}
/>
)} )}
</View> </View>
</View> </View>
</View>
</Form> </Form>
</View> </View>
); );
@ -275,6 +296,12 @@ const styles = StyleSheet.create({
textAlign: "left", textAlign: "left",
color: colors.secondary, color: colors.secondary,
}, },
labelTipoInst: {
fontSize: dimensions.text.secondary,
fontWeight: "bold",
textAlign: "left",
color: colors.secondary,
},
subText: { subText: {
color: colors.subText, color: colors.subText,
fontSize: 16, fontSize: 16,
@ -282,8 +309,14 @@ const styles = StyleSheet.create({
fontWeight: "500", fontWeight: "500",
paddingLeft: 16, paddingLeft: 16,
}, },
subTextDate: {
color: colors.subText,
fontSize: 16,
alignSelf: "center",
fontWeight: "500",
},
title: { title: {
marginVertical: 24,
// marginVertical: 24,
fontSize: 18, fontSize: 18,
fontWeight: "bold", fontWeight: "bold",
textAlign: "center", textAlign: "center",

Loading…
Cancel
Save