Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

refactor(vendor): enhance order status handling with improved type safety

Jakub Sieradzki9e51bef30df9
diff --git a/packages/vendor/src/lib/order-helpers.ts b/packages/vendor/src/lib/order-helpers.ts
index 4102ba374..b4410b32c 100644
--- a/packages/vendor/src/lib/order-helpers.ts
+++ b/packages/vendor/src/lib/order-helpers.ts
@@ -15,7 +15,7 @@ export const getOrderPaymentStatus = (
t: TFunction<"translation">,
status: string
) => {
- const [label, color] = {
+ const statusMap: Record<string, [string, "red" | "orange" | "green"]> = {
not_paid: [t("orders.payment.status.notPaid"), "red"],
authorized: [t("orders.payment.status.authorized"), "orange"],
partially_authorized: [
@@ -35,7 +35,9 @@ export const getOrderPaymentStatus = (
],
canceled: [t("orders.payment.status.canceled"), "red"],
requires_action: [t("orders.payment.status.requiresAction"), "orange"],
- }[status] as [string, "red" | "orange" | "green"]
+ }
+
+ const [label, color] = statusMap[status] ?? [status ?? "-", "red" as const]
return { label, color }
}
@@ -44,7 +46,7 @@ export const getOrderFulfillmentStatus = (
t: TFunction<"translation">,
status: string
) => {
- const [label, color] = {
+ const statusMap: Record<string, [string, "red" | "orange" | "green"]> = {
not_fulfilled: [t("orders.fulfillment.status.notFulfilled"), "red"],
partially_fulfilled: [
t("orders.fulfillment.status.partiallyFulfilled"),
@@ -68,7 +70,9 @@ export const getOrderFulfillmentStatus = (
returned: [t("orders.fulfillment.status.returned"), "green"],
canceled: [t("orders.fulfillment.status.canceled"), "red"],
requires_action: [t("orders.fulfillment.status.requiresAction"), "orange"],
- }[status] as [string, "red" | "orange" | "green"]
+ }
+
+ const [label, color] = statusMap[status] ?? [status ?? "-", "red" as const]
return { label, color }
}