make Importer component reusable

This commit is contained in:
taehoon 2019-03-30 05:10:57 -04:00
parent 18bb209ace
commit 6d0e98a1c2
5 changed files with 50 additions and 17 deletions

View file

@ -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