diff options
| author | taehoon <th.dev91@gmail.com> | 2019-03-30 05:10:57 -0400 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-04-27 08:31:06 -0400 |
| commit | 6d0e98a1c2c81c587b89736dbd2ac43a8c540d54 (patch) | |
| tree | 33f10f421c9f6fafad4fe29a54621020e09484ab /src/components/importer/importer.js | |
| parent | 18bb209acefcdc332cba6708d9a0e163d0d04e90 (diff) | |
make Importer component reusable
Diffstat (limited to 'src/components/importer/importer.js')
| -rw-r--r-- | src/components/importer/importer.js | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/components/importer/importer.js b/src/components/importer/importer.js index 44d02c93..c5f9e4d2 100644 --- a/src/components/importer/importer.js +++ b/src/components/importer/importer.js @@ -1,10 +1,34 @@ const Importer = { + props: { + submitHandler: { + type: Function, + required: true + }, + submitButtonLabel: { + type: String, + default () { + return this.$t('importer.submit') + } + }, + successMessage: { + type: String, + default () { + return this.$t('importer.success') + } + }, + errorMessage: { + type: String, + default () { + return this.$t('importer.error') + } + } + }, data () { return { file: null, error: false, success: false, - uploading: false + submitting: false } }, methods: { @@ -12,16 +36,12 @@ const Importer = { this.file = this.$refs.input.files[0] }, submit () { - this.uploading = true - this.$store.state.api.backendInteractor.followImport(this.file) - .then((status) => { - if (status) { - this.success = true - } else { - this.error = true - } - this.uploading = false - }) + this.dismiss() + this.submitting = true + this.submitHandler(this.file) + .then(() => { this.success = true }) + .catch(() => { this.error = true }) + .finally(() => { this.submitting = false }) }, dismiss () { this.success = false |
