diff --git a/src/app/api/Ingestion/sendFormAnswer.js b/src/app/api/Ingestion/sendFormAnswer.js index bd71052..48383a6 100644 --- a/src/app/api/Ingestion/sendFormAnswer.js +++ b/src/app/api/Ingestion/sendFormAnswer.js @@ -9,7 +9,6 @@ async function sendFormAnswer(ingestionObject) { endpoint, JSON.stringify(ingestionObject) ); - return response; } diff --git a/src/app/components/forms/AssembleIngestionObject.js b/src/app/components/forms/AssembleIngestionObject.js index 7b9b512..619e05e 100644 --- a/src/app/components/forms/AssembleIngestionObject.js +++ b/src/app/components/forms/AssembleIngestionObject.js @@ -1,7 +1,6 @@ import moment from "moment"; import sendFormAnswer from "../../api/Ingestion/sendFormAnswer"; - const AssembleIngestionObject = ( { images, description }, user, @@ -17,7 +16,7 @@ const AssembleIngestionObject = ( array_to_json: [ { formcode: code, - formsanswersuserinformer: "admin@wpd.com",//user.id, + formsanswersuserinformer: "admin@wpd.com", //user.id, fieldsanswerslongitude: location["longitude"], fieldsanswerslatitude: location["latitude"], fields: [ @@ -49,7 +48,7 @@ const AssembleIngestionPluviometer = ({ array_to_json: [ { formcode: "PLUVIOMETERS_FORM", - formsanswersuserinformer: "admin@wpd.com",//user.id, + formsanswersuserinformer: "admin@wpd.com", //user.id, fias: [ { fieldsanswersdate: moment(date).format("DD-MM-YYYY"), @@ -64,7 +63,13 @@ const AssembleIngestionPluviometer = ({ }; }; -const AssembleIngestionPluvRegistration = ( date, time, user, address, coordinates ) => { +async function AssembleIngestionPluvRegistration( + date, + time, + user, + address, + coordinates +) { console.log(user); console.log(coordinates); const pluvResgistrationObject = { @@ -72,24 +77,29 @@ const AssembleIngestionPluvRegistration = ( date, time, user, address, coordinat array_to_json: [ { formcode: "PLUVIOMETER_REGISTRATION", - formsanswersuserinformer: "admin@wpd.com",//user.id, + formsanswersuserinformer: "admin@wpd.com", //user.id, fieldsanswerslongitude: coordinates["longitude"], - fieldsanswerslatitude: coordinates["latitude"], + fieldsanswerslatitude: coordinates["latitude"], fields: [ { fieldsanswerseventaddress: address, fieldsanswerseventdate: moment(date).format("DD-MM-YYYY"), fieldsanswerseventtime: moment(time).format("HH:mm"), - fieldsanswersinstitutename: user.institutionName ? user.institutionName : null, - fieldsanswerrinstitutetype: user.institutionType ? user.institutionType : null + fieldsanswersinstitutename: user.institutionName + ? user.institutionName + : null, + fieldsanswerrinstitutetype: user.institutionType + ? user.institutionType + : null, }, ], }, ], }, }; - const a = sendFormAnswer(pluvResgistrationObject); -}; + const a = await sendFormAnswer(pluvResgistrationObject); + return a; +} export { AssembleIngestionObject, AssembleIngestionPluviometer, diff --git a/src/app/navigation/FeedNavigator.js b/src/app/navigation/FeedNavigator.js index 6cc687e..7c1d9e0 100644 --- a/src/app/navigation/FeedNavigator.js +++ b/src/app/navigation/FeedNavigator.js @@ -8,7 +8,7 @@ const FeedNavigator = () => (
{ - AssembleIngestionPluvRegistration( + onSubmit={async () => { + showMessage({ + message: "Aguarde! Estamos enviando a informação.", + duration: 2005, + icon: "warning", + type: "warning", + onPress: () => {}, + }); + const isSent = await AssembleIngestionPluvRegistration( date, time, user, location, coordinates ); + if (isSent.ok) { + showMessage({ + message: "Pluviômetro cadastrado!", + duration: 1950, + icon: "success", + type: "success", + onPress: () => {}, + }); + + props.navigation.navigate("Home"); + } + else{ + showMessage({ + message: "Erro ao cadastrar pluviômetro. Por favor, tente mais tarde!", + duration: 1950, + icon: "danger", + type: "danger", + onPress: () => {}, + }); + + } }} > Cadastro do Pluviômetro + + + Data do cadastro:{" "} + - - Data do cadastro:{" "} - - - - setDate(value)} - onTimeChange={(value) => setTime(value)} - date={date} - time={time} - formTypeFace={"pluviometerRegister"} - /> + + setDate(value)} + onTimeChange={(value) => setTime(value)} + date={date} + time={time} + formTypeFace={"pluviometerRegister"} + /> + - Endereço do pluviômetro*: