admin/import page and functionality
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<BModal
|
||||||
|
id="modal-center"
|
||||||
|
v-model="activeModal"
|
||||||
|
centered
|
||||||
|
title="latienda.coop"
|
||||||
|
:ok-variant="modalColor"> {{ modalText }}
|
||||||
|
</BModal>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-10"></div>
|
<div class="col-10"></div>
|
||||||
<h1 class="title">Importar productos desde CSV</h1>
|
<h1 class="title">Importar productos desde CSV</h1>
|
||||||
@@ -17,22 +24,32 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="error" class="error">{{ error }}</p>
|
<p v-if="error" class="error">{{ error }}</p>
|
||||||
<SubmitButton text="Importar"></SubmitButton>
|
<SubmitButton text="Importar" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
export default {
|
export default {
|
||||||
layout: 'admin',
|
setup() {
|
||||||
middleware: 'auth',
|
definePageMeta({
|
||||||
meta: {
|
layout: 'admin',
|
||||||
auth: { authority: 'SITE_ADMIN' },
|
middleware: 'auth',
|
||||||
|
auth: { authority: 'SITE_ADMIN' },
|
||||||
|
})
|
||||||
|
const auth = useAuthStore();
|
||||||
|
return {
|
||||||
|
auth
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
file: null,
|
file: null,
|
||||||
error: null,
|
error: null,
|
||||||
|
modalText: '',
|
||||||
|
modalColor: '',
|
||||||
|
activeModal: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -46,15 +63,22 @@ export default {
|
|||||||
this.error = null
|
this.error = null
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('csv_file', this.file)
|
formData.append('csv_file', this.file)
|
||||||
|
//TODO: Review functionality
|
||||||
try {
|
try {
|
||||||
await this.$api.post('/load_coops/', formData, {
|
await $fetch('/load_coops/',{
|
||||||
|
baseURL: config.public.baseURL,
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data',
|
Authorization: `Bearer ${this.auth.access}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch {
|
this.modalText = 'Productos importados correctamente'
|
||||||
|
this.modalColor = 'success'
|
||||||
|
this.activeModal = true
|
||||||
|
} catch (error) {
|
||||||
this.error = 'Ha habido un error'
|
this.error = 'Ha habido un error'
|
||||||
|
console.error('Error importing products:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user