Skip to content
Snippets Groups Projects

Issue #29: User can't answer a form twice

Merged Richard Fernando Heise Ferreira requested to merge issue/29-Answer into development
1 file
+ 34
0
Compare changes
  • Side-by-side
  • Inline
+ 34
0
@@ -153,6 +153,7 @@ function AnwserForm() {
const res = await api
.post(`/answer/${id}`, backendTranslation())
.then(function(res) {
setCookie("answerForm", id, 92);
alert("Formulário respondido!");
})
.catch(error => {
@@ -205,6 +206,7 @@ function AnwserForm() {
const res = await api
.get(`/form/${id}`)
.then(function(res) {
checkCookie(id);
setFormData(res.data);
mapInputs(res.data);
})
@@ -223,6 +225,38 @@ function AnwserForm() {
});
}
function setCookie(cookieName, cookieValue, expirationsDays) {
var date = new Date();
date.setTime(date.getTime() + expirationsDays * 60 * 60 * 24 * 1000);
var expires = "expires=" + date.toUTCString();
document.cookie =
cookieName + "=" + cookieValue + ";" + expires + ";path=/";
}
function getCookie(cookieName) {
var name = cookieName + "=";
var ca = document.cookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie(id) {
var answer = getCookie("answerForm");
if (answer == id) {
alert("Você já respondeu esse formulário! ");
let path = `/signin`;
history.push(path);
}
}
/** First thing the page does is getting the form from the API. */
useEffect(() => {
getForm(id);
Loading