Files
terminalShop/pkg/models/order_display.go
marcusDenslow e5ec247a6b feat(orders): customer-facking tracking labels and webhook response body
the big colored status on the order detail page used to just say
"Shipped" the moment i bought the label, which didnt really feel right
since the carrier hadnt actually picked anything up yet. now it walks
through "Label created" -> "In transit" -> "Delivered" as real scans
come in, and keeps the "Delivery Issue" / "Returned to sender" labels
for unhappy paths

also wired up the existing tracking_status_details column to the tui. i
skipped it before but the response actually includes a description of
the delivery, that is now subtext under the colored statu.

and the shippo webhook now returns a small json body instead of an empty
200. this is just for the operator that runs the curls commands to
     update the shipment, which makes debugging a lot less guesswork
2026-05-14 21:17:50 +02:00

77 lines
2.2 KiB
Go

package models
// DisplayKind is a ui agnostic color/severity token.
// The TUI (or any other renderer) maps this to a concrete style
// the model stays free of UI deps.
type DisplayKind string
const (
DisplayKindNeutral DisplayKind = "neutral" // pending, default
DisplayKindAccent DisplayKind = "accent" // paid, awaiting fulfillment
DisplayKindBrand DisplayKind = "brand" // shipped / in transit
DisplayKindSuccess DisplayKind = "success" // delivered
DisplayKindError DisplayKind = "error" // cancelled, failed, refunded
DisplayKindWarning DisplayKind = "warning" // refund pending, delivery issue
)
func (order *Order) DisplayState() string {
switch order.Status {
case OrderStatusPending:
return "Awaiting payment"
case OrderStatusPaid:
if order.TrackingNumber == "" {
return "Paid * awaiting label"
}
// !IMPORTANT
// Reachable only if UpdateTracking auto-promote is removed later
if order.TrackingStatus == TrackingStatusPreTransit {
return "Paid * ready to ship"
}
return "Paid"
case OrderStatusShipped:
switch order.TrackingStatus {
case TrackingStatusTransit:
return "In Transit"
case TrackingStatusFailure:
return "Delivery Issue"
case TrackingStatusReturned:
return "Returned to Sender"
case TrackingStatusDelivered:
// Webhook hasn't promoted Status yet, trust tracking
return "Delivered"
}
return "Label Created"
case OrderStatusDelivered:
return "Delivered"
case OrderStatusCancelled:
return "Cancelled"
case OrderStatusRefunded:
return "Refunded"
case OrderStatusFailed:
return "Payment failed"
}
return string(order.Status)
}
func (order *Order) DisplayKind() DisplayKind {
switch order.Status {
case OrderStatusPending:
return DisplayKindNeutral
case OrderStatusPaid:
return DisplayKindAccent
case OrderStatusShipped:
switch order.TrackingStatus {
case TrackingStatusFailure, TrackingStatusReturned:
return DisplayKindWarning
case TrackingStatusDelivered:
return DisplayKindSuccess
}
return DisplayKindBrand
case OrderStatusDelivered:
return DisplayKindSuccess
case OrderStatusCancelled, OrderStatusRefunded, OrderStatusFailed:
return DisplayKindError
}
return DisplayKindNeutral
}