Skip to content

Commit

Permalink
feat(#504): Adding xm submission actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed Jul 24, 2024
1 parent cbb42da commit 1a7edec
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app/src/store/modules/explorer/curation/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,53 @@ export default {
{ root: true }
)
}
},
async submitXmlFiles ({ commit, rootGetters }, files) {
const token = rootGetters['auth/token']
try {
const formData = new FormData()
files.forEach(({ file }) => formData.append('uploadfile', file))

const response = await fetch('/api/curate/xml', {
method: 'POST',
headers: {
// 'Content-Type': 'application/json',
Authorization: 'Bearer ' + token
},
body: formData
})

if (response || response.status === 201) {
const { totalXMLFiles, failedXML } = await response.json()
if (failedXML === 0) {
commit(
'setSnackbar',
{
message: 'Your XML has been successfully submitted.',
duration: 10000
},
{ root: true }
)
return router.push('/explorer/xmls')
} else {
return commit(
'setSnackbar',
{
message: `Submission failed for ${failedXML} out of ${totalXMLFiles} entries`,
duration: 10000,
callToActionText: 'Click to view',
action: () => router.push('/explorer/xmls')
},
{ root: true }
)
}
}
} catch (error) {
return commit(
'setSnackbar',
{ message: error.message ?? 'Something went wrong during the request' },
{ root: true }
)
}
}
}

0 comments on commit 1a7edec

Please sign in to comment.