fix(dashboard): scope owner and service views by resolved shop
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { OrderStatus } from "@/lib/types"
|
||||
|
||||
const ACTIVE_STATUSES: ReadonlySet<OrderStatus> = new Set([
|
||||
"pending_payment",
|
||||
"pending_accept",
|
||||
"in_progress",
|
||||
"pending_close",
|
||||
"pending_review",
|
||||
])
|
||||
|
||||
const COMPLETED_STATUSES: ReadonlySet<OrderStatus> = new Set(["completed"])
|
||||
const DISPUTED_STATUSES: ReadonlySet<OrderStatus> = new Set(["disputed"])
|
||||
const PENDING_DISPATCH_STATUSES: ReadonlySet<OrderStatus> = new Set(["pending_accept"])
|
||||
|
||||
export function isActiveOrder(status: OrderStatus) {
|
||||
return ACTIVE_STATUSES.has(status)
|
||||
}
|
||||
|
||||
export function isCompletedOrder(status: OrderStatus, options?: { includeCancelled?: boolean }) {
|
||||
if (options?.includeCancelled && status === "cancelled") {
|
||||
return true
|
||||
}
|
||||
|
||||
return COMPLETED_STATUSES.has(status)
|
||||
}
|
||||
|
||||
export function isDisputedOrder(status: OrderStatus) {
|
||||
return DISPUTED_STATUSES.has(status)
|
||||
}
|
||||
|
||||
export function isPendingDispatch(status: OrderStatus) {
|
||||
return PENDING_DISPATCH_STATUSES.has(status)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { Shop } from "@/lib/types"
|
||||
|
||||
export function resolveOwnerShop(userId: string | undefined, shops: Shop[]): Shop | null {
|
||||
if (!userId) return null
|
||||
return shops.find((shop) => shop.owner.id === userId) ?? null
|
||||
}
|
||||
Reference in New Issue
Block a user