Finish order admin page with detail dialog and actions
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
import { fetchAllOrders, fetchUserOrders } from "@/data/api/orderApi";
|
||||
import { fetchAllOrders, fetchUserOrders, patchOrder } from "@/data/api/orderApi";
|
||||
import { OrderApiModel } from "@/data/models/apiEndpoints/orderApiModel";
|
||||
import { AccountModel } from "@/data/models/user/accountModel";
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { useAccountStore } from "./account.store";
|
||||
|
||||
export const useOrderStore = defineStore("orderStore", {
|
||||
state: () => ({
|
||||
/** All orders of one/all users */
|
||||
orders: ref<Array<OrderApiModel>>([]),
|
||||
|
||||
/** Current selected order */
|
||||
order: ref<OrderApiModel>(new OrderApiModel),
|
||||
|
||||
/** Show detail dialog on admin page */
|
||||
showDetailDialog: ref<boolean>(false),
|
||||
|
||||
/** Request to server sent, waiting for data response */
|
||||
@@ -22,9 +25,10 @@ export const useOrderStore = defineStore("orderStore", {
|
||||
* Get all orders from all accounts from server
|
||||
*/
|
||||
async getAllOrders() {
|
||||
const accountStore = useAccountStore()
|
||||
this.fetchInProgress = true
|
||||
|
||||
fetchAllOrders()
|
||||
fetchAllOrders(accountStore.userAccountToken)
|
||||
.then(res => {
|
||||
this.orders = res.data
|
||||
this.fetchInProgress = false
|
||||
@@ -46,13 +50,31 @@ export const useOrderStore = defineStore("orderStore", {
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Open detail dialog
|
||||
*
|
||||
* @param order Order to view
|
||||
*/
|
||||
openDetails(order: OrderApiModel) {
|
||||
this.order = order
|
||||
this.showDetailDialog = true
|
||||
},
|
||||
|
||||
async deleteOrder(order: OrderApiModel) {
|
||||
// todo
|
||||
|
||||
/**
|
||||
*
|
||||
* @param order
|
||||
* @param shipped
|
||||
*/
|
||||
async changeOrderShippedState(order: OrderApiModel, shipped: boolean) {
|
||||
this.fetchInProgress = true
|
||||
|
||||
order.shipped = shipped
|
||||
|
||||
patchOrder(order)
|
||||
.then(res => {
|
||||
this.getAllOrders()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user