diff options
author | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-08 12:37:48 +0100 |
---|---|---|
committer | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-08 12:37:48 +0100 |
commit | 6ab556eb9adc0f02a279b8f89bc9309734525522 (patch) | |
tree | 568f95dfb8ec3fbb293fef0597dccd751c348f2d /public/js | |
parent | 6b220e094f215c488eb5102e25506f5b3d371245 (diff) |
Refactor: import event form
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/modules/new.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/public/js/modules/new.js b/public/js/modules/new.js index fbb99ed..84391b7 100644 --- a/public/js/modules/new.js +++ b/public/js/modules/new.js @@ -199,3 +199,47 @@ function newEventGroupForm() { }, }; } + +function importEventForm() { + return { + data: { + creatorEmail: "", + }, + errors: [], + submitting: false, + async submitForm() { + this.submitting = true; + this.errors = []; + const formData = new FormData(); + for (const [key, value] of Object.entries(this.data)) { + formData.append(key, value); + } + formData.append( + "icsImportControl", + this.$refs.icsImportControl.files[0], + ); + try { + const response = await fetch("/import/event", { + method: "POST", + body: formData, + }); + this.submitting = false; + if (!response.ok) { + if (response.status !== 400) { + this.errors = unexpectedError; + return; + } + const json = await response.json(); + this.errors = json.errors; + return; + } + const json = await response.json(); + window.location.assign(json.url); + } catch (error) { + console.log(error); + this.errors = unexpectedError; + this.submitting = false; + } + }, + }; +} |