File tree 2 files changed +26
-8
lines changed
backend/src/views/Products
2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 8
8
Add new Product
9
9
</button >
10
10
</div >
11
- <ProductsTable />
12
- <ProductModal v-model =" showProductModal" :product =" product " />
11
+ <ProductsTable @clickEdit = " editProduct " />
12
+ <ProductModal v-model =" showProductModal" :product =" productModel " @close = " onModalClose " />
13
13
</template >
14
14
15
15
<script setup>
@@ -18,14 +18,34 @@ import store from "../../store";
18
18
import ProductModal from " ./ProductModal.vue" ;
19
19
import ProductsTable from " ./ProductsTable.vue" ;
20
20
21
+ const DEFAULT_PRODUCT = {
22
+ id: ' ' ,
23
+ title: ' ' ,
24
+ description: ' ' ,
25
+ image: ' ' ,
26
+ price: ' '
27
+ }
28
+
21
29
const products = computed (() => store .state .products );
22
30
23
- const product = ref ({})
31
+ const productModel = ref ({... DEFAULT_PRODUCT })
24
32
const showProductModal = ref (false );
25
33
26
34
function showAddNewModal () {
27
35
showProductModal .value = true
28
36
}
37
+
38
+ function editProduct (p ) {
39
+ store .dispatch (' getProduct' , p .id )
40
+ .then (({data}) => {
41
+ productModel .value = data
42
+ showAddNewModal ();
43
+ })
44
+ }
45
+
46
+ function onModalClose () {
47
+ productModel .value = {... DEFAULT_PRODUCT}
48
+ }
29
49
</script >
30
50
31
51
<style scoped>
Original file line number Diff line number Diff line change @@ -189,6 +189,8 @@ const sortDirection = ref('desc')
189
189
const product = ref ({})
190
190
const showProductModal = ref (false );
191
191
192
+ const emit = defineEmits ([' clickEdit' ])
193
+
192
194
onMounted (() => {
193
195
getProducts ();
194
196
})
@@ -243,11 +245,7 @@ function deleteProduct(product) {
243
245
}
244
246
245
247
function editProduct (p ) {
246
- store .dispatch (' getProduct' , p .id )
247
- .then (({data}) => {
248
- product .value = data
249
- showAddNewModal ();
250
- })
248
+ emit (' clickEdit' , p)
251
249
}
252
250
</script >
253
251
You can’t perform that action at this time.
0 commit comments