1- <template >
1+ <template >
22 <form @submit.prevent =" fetchProduct()" >
3- <p class =" mb-1 max-w-sm" ><v-select
4- placeholder =" Select a product"
5- :options =" products"
6- :get-option-key =" (option) => option.product_id"
7- :get-option-label =" (option) => option.title"
8- :searchable =" true"
9- @input =" input"
10- /></p >
3+ <div class =" mb-1 max-w-sm" >
4+ <ui-combobox
5+ class =" w-full"
6+ clearable =" true"
7+ :label =" __('Select a product')"
8+ v-model =" selectedProduct"
9+ optionLabel =" title"
10+ :options =" products"
11+ optionValue =" product_id"
12+ searchable =" true"
13+ />
14+ </div >
1115
1216 <div class =" flex items-center" >
13- <button type =" submit " class = " btn-primary " > Import Product</ button >
14- <p class =" ml-2 text-sm " :class = " messageColor " v-if =" message" >{{ message }}</p >
17+ <ui- button type =" button " @click = " fetch() " :disabled = " processing " >{{ processing ? 'Please wait' : ' Import product' }}</ ui- button >
18+ <ui-error-message class =" ml-2" v-if =" message" >{{ message }}</ui-error-message >
1519 </div >
1620 </form >
1721</template >
@@ -28,10 +32,10 @@ export default {
2832
2933 data () {
3034 return {
31- products: [],
3235 message: null ,
33- messageColor: ' text-black' ,
34- selectedProduct: null
36+ selectedProduct: null ,
37+ processing: false ,
38+ products: [],
3539 }
3640 },
3741
@@ -47,25 +51,20 @@ export default {
4751 })
4852 },
4953
50- input (value ) {
51- this .selectedProduct = value
52- },
53-
5454 fetchProduct () {
55- this .message = ' working.... '
56- this .messageColor = ' text-black '
55+ this .message = ' ' ;
56+ this .processing = true ;
5757
5858 axios .get (` ${ this .url } ?product=${ this .selectedProduct .product_id } ` )
5959 .then (res => {
6060 this .message = res .data .message
61- this .messageColor = ' text-green'
6261
6362 setTimeout (() => this .message = null , 3000 )
6463 }).catch (err => {
6564 this .message = ' Something went wrong. Please try again.'
66- this .messageColor = ' text-red'
6765 setTimeout (() => this .message = null , 5000 )
6866 })
67+ .finally (() => this .processing = false )
6968 }
7069 }
7170}
0 commit comments