Feedback now includes file name if one is uploaded

This commit is contained in:
mrfry 2021-03-17 16:39:39 +01:00
parent 2e7317962e
commit 6a2c22f24a

View file

@ -61,8 +61,8 @@ function addPost(title, content) {
}
function postFeedback(content, file) {
return new Promise((resolve) => {
const promises = [
const postText = (file) => {
return new Promise((resolve) => {
fetch(constants.apiUrl + 'postfeedback', {
method: 'POST',
credentials: 'include',
@ -72,34 +72,44 @@ function postFeedback(content, file) {
},
body: JSON.stringify({
content: content,
file: file ? file.name : null,
}),
}).then((res) => {
return res.json()
}),
]
})
.then((res) => {
return res.json()
})
.then((res) => {
resolve(res)
})
})
}
return new Promise((resolve) => {
if (file) {
console.log('FIEEEEEEEEEELE')
const formData = new FormData() // eslint-disable-line
formData.append('file', file)
promises.push(
fetch(constants.apiUrl + 'postfeedbackfile', {
method: 'POST',
credentials: 'include',
headers: {
Accept: 'application/json',
},
body: formData,
}).then((res) => {
fetch(constants.apiUrl + 'postfeedbackfile', {
method: 'POST',
credentials: 'include',
headers: {
Accept: 'application/json',
},
body: formData,
})
.then((res) => {
return res.json()
})
)
.then((fileres) => {
postText(file).then((textres) => {
resolve({ fileres, textres })
})
})
} else {
postText().then((res) => {
resolve(res)
})
}
Promise.all(promises).then((res) => {
resolve(res)
})
})
}
@ -252,8 +262,7 @@ export default function Index({ globalData }) {
}
console.log(type, title, content, file)
if (type === 'private') {
postFeedback(content, file).then((res) => {
console.log(res)
postFeedback(content, file).then((/* { fileres, textres } */) => {
alert('Privát visszajelzés elküldve!')
})
} else {