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. 68
      src/app/hooks/usePluviometricStation.js
  3. 4
      src/app/screens/AccountScreen.js
  4. 127
      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]) => {

68
src/app/hooks/usePluviometricStation.js

@ -10,39 +10,37 @@ async function getPluvStation_data(id) {
return null; return null;
} }
function assemblePluvStationObject(pluvData){
var date = null;
var time = null;
var address = null;
var institutionType = null;
var institutionName = null;
function assemblePluvStationObject(pluvData) {
var date = null;
var time = null;
var address = null;
var institutionType = null;
var institutionName = null;
pluvData.array_to_json.forEach(function (field) {
if(field.fieldname == "eventaddress"){
address = field.fieldsanswersvalue;
}
else if (field.fieldname == "eventdate") {
date = field.fieldsanswersvalue;
}
else if (field.fieldname == "eventtime") {
time = field.fieldsanswersvalue;
}
else if(field.fieldname== "institutename"){
institutionName = field.fieldsanswersvalue;
}
else if(field.fieldname== "institutetype"){
institutionType = field.institutionType;
}
});
return{
regiterDate: date + " | " + time,
address: address,
institutionType: institutionType,
institutionName:institutionName,
coordinates:{lat: pluvData.formsanswerslatitude, long:pluvData.formsanswerslongitude}
pluvData.array_to_json.forEach(function (field) {
if (field.fieldname == "eventaddress") {
address = field.fieldsanswersvalue;
} else if (field.fieldname == "eventdate") {
date = field.fieldsanswersvalue;
} else if (field.fieldname == "eventtime") {
time = field.fieldsanswersvalue;
} else if (field.fieldname == "institutename") {
institutionName = field.fieldsanswersvalue;
} else if (field.fieldname == "institutetype") {
institutionType = field.institutionType;
} }
});
return {
regiterDate: date + " | " + time,
address: address,
institutionType: institutionType,
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");
}, },

127
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,51 +215,66 @@ function PluviometerRegisterScreen(props) {
}); });
}} }}
> >
<View style={{ padding: 6, flex: 1, flexDirection:"column" }}>
<Text style={styles.title}>Cadastro do Pluviômetro</Text>
<View style={{flex: 0.25}}>
<Text
style={{
marginTop: 24,
marginBottom: 16,
fontSize: dimensions.text.secondary,
fontWeight: "bold",
textAlign: "left",
color: colors.secondary,
}}
>
Data do cadastro:
</Text>
<PluvDateTimePicker
onDateChange={(value) => setDate(value)}
onTimeChange={(value) => setTime(value)}
date={date}
time={time}
formTypeFace={"pluviometerRegister"}
pluviometer={user.pluviometer}
/>
<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>
</View> </View>
<View style={{flex: 0.25}}>
<Text style={styles.label}>Endereço do pluviômetro*: </Text>
<View style={{ flex: 0.95, justifyContent: "space-between" }}>
<View style={{ flex: 0.19 }}>
<Text
style={{
marginTop: 24,
marginBottom: 16,
fontSize: dimensions.text.secondary,
fontWeight: "bold",
textAlign: "left",
color: colors.secondary,
}}
>
Data do cadastro:
</Text>
<View marginBottom={24}>
<LocationPicker
navigation={props.navigation}
location={location}
setLocationAddr={setLocationAddr}
setGeoLocation={setCoordinates}
<PluvDateTimePicker
onDateChange={(value) => setDate(value)}
onTimeChange={(value) => setTime(value)}
date={date}
time={time}
formTypeFace={"pluviometerRegister"}
pluviometer={user.pluviometer} pluviometer={user.pluviometer}
/> />
</View> </View>
</View>
<View style={{flex: 0.25}}>
<Institution user={user} />
</View>
<View style={{flex: 0.25}}>
{!user.pluviometer && (
<SubmitButton title="Cadastrar" paddingHorizontal={0} />
)}
<View style={{ flex: 0.19 }}>
<Text style={styles.label}>Endereço do pluviômetro*: </Text>
<View marginBottom={24}>
<LocationPicker
navigation={props.navigation}
location={location}
setLocationAddr={setLocationAddr}
setGeoLocation={setCoordinates}
pluviometer={user.pluviometer}
/>
</View>
</View>
<View style={{ flex: 0.38 }}>
<Institution user={user} />
</View>
<View style={{ flex: 0.19 }}>
{!user.pluviometer && (
<SubmitButton
style={{ alignSelf: "" }}
title="Cadastrar"
paddingHorizontal={0}
/>
)}
</View>
</View> </View>
</View> </View>
</Form> </Form>
@ -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