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