my orders
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import axios from "@/config/axios";
|
||||
import type { OrderType, ProductsResponseType } from "../type/Types";
|
||||
import type {
|
||||
MyOrdersResponseType,
|
||||
OrderType,
|
||||
ProductsResponseType,
|
||||
} from "../type/Types";
|
||||
import { OrderStatusEnum, TabMyOrdersEnum } from "../enum/OrderEnum";
|
||||
|
||||
export const getProducts = async () => {
|
||||
const { data } = await axios.get<ProductsResponseType>(`/public/products`);
|
||||
@@ -11,7 +16,35 @@ export const submitOrder = async (params: OrderType[]) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getMyOrders = async () => {
|
||||
const { data } = await axios.get(`/public/orders`);
|
||||
export const getMyOrders = async (
|
||||
page: number = 1,
|
||||
active: TabMyOrdersEnum,
|
||||
) => {
|
||||
const statuses =
|
||||
active === TabMyOrdersEnum.IN_PROGRESS
|
||||
? [
|
||||
OrderStatusEnum.DESIGN_FINISHED,
|
||||
OrderStatusEnum.DESIGN_INITIATED,
|
||||
OrderStatusEnum.DESIGN_REVISION,
|
||||
OrderStatusEnum.IN_PRINTING,
|
||||
OrderStatusEnum.AFTER_PRINT_BOXING,
|
||||
OrderStatusEnum.AFTER_PRINT_CARTONING,
|
||||
OrderStatusEnum.AFTER_PRINT_COVER,
|
||||
OrderStatusEnum.READY_FOR_DELIVERY,
|
||||
OrderStatusEnum.READY_TO_PRINTING,
|
||||
]
|
||||
: active === TabMyOrdersEnum.CANCELLED
|
||||
? [OrderStatusEnum.CANCELED]
|
||||
: active === TabMyOrdersEnum.DELIVERED
|
||||
? [OrderStatusEnum.DELIVERED]
|
||||
: undefined;
|
||||
|
||||
let query = `?page=${page}`;
|
||||
if (statuses) {
|
||||
query += `statuses=${statuses}`;
|
||||
}
|
||||
const { data } = await axios.get<MyOrdersResponseType>(
|
||||
`/public/orders${query}`,
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user