Add common "form poster" logic, to make CSRF token/header names configurable

also refactor the Feedback logic to use it
This commit is contained in:
Lance Edgar 2020-12-16 14:28:41 -06:00
parent a801672821
commit cc833c52b6
6 changed files with 66 additions and 29 deletions

View file

@ -2,6 +2,7 @@
let FeedbackForm = {
props: ['action', 'message'],
template: '#feedback-template',
mixins: [FormPosterMixin],
methods: {
showFeedback() {
@ -20,30 +21,11 @@ let FeedbackForm = {
message: this.message.trim(),
}
let headers = {
// TODO: should find a better way to handle CSRF token
'X-CSRF-TOKEN': this.csrftoken,
}
this.$http.post(this.action, params, {headers: headers}).then(({ data }) => {
if (data.ok) {
alert("Message successfully sent.\n\nThank you for your feedback.")
this.showDialog = false
// clear out message, in case they need to send another
this.message = ""
} else {
this.$buefy.toast.open({
message: "Failed to send feedback: " + data.error,
type: 'is-danger',
duration: 4000, // 4 seconds
})
}
}, response => {
this.$buefy.toast.open({
message: "Failed to send feedback! (unknown server error)",
type: 'is-danger',
duration: 4000, // 4 seconds
})
this.submitForm(this.action, params, response => {
alert("Message successfully sent.\n\nThank you for your feedback.")
this.showDialog = false
// clear out message, in case they need to send another
this.message = ""
})
},
}