Files
shop-client/shared/constants/order-status.js
T

39 lines
1.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const ORDER_STATUSES = Object.freeze([
"DRAFT",
"PENDING_PAYMENT",
"PAID",
"IN_PROGRESS",
"SHIPPED",
"READY_FOR_PICKUP",
"DONE",
"CANCELLED",
]);
/**
* Допустимые переходы статусов, доступные админу.
* Значение — массив из next-статусов.
* Для IN_PROGRESS: объект с ключами по deliveryType.
*/
export const ADMIN_ORDER_TRANSITIONS = Object.freeze({
DRAFT: ["PENDING_PAYMENT", "CANCELLED"],
PENDING_PAYMENT: ["PAID", "CANCELLED"],
PAID: ["IN_PROGRESS", "CANCELLED"],
IN_PROGRESS: Object.freeze({
delivery: ["SHIPPED", "CANCELLED"],
pickup: ["READY_FOR_PICKUP", "CANCELLED"],
}),
});
export function getNextAdminStatuses(from, deliveryType) {
const transition = ADMIN_ORDER_TRANSITIONS[from];
if (!transition) return [];
if (Array.isArray(transition)) return [...transition];
return transition[deliveryType] ? [...transition[deliveryType]] : [];
}
export function canTransitionAdminOrderStatus(order, next) {
const from = order.status;
if (from === next) return true;
return getNextAdminStatuses(from, order.deliveryType).includes(next);
}