Back to DevLog

Shipping Got Real: Built Universal Order Management for AdminStack

2 min read

Just wrapped up a marathon coding session building out the complete shipping and order management system for AdminStack. This was one of those sessions where everything just clicked into place.

What I Shipped Today

The big win was getting the universal order management system working. Now AdminStack can handle orders from any product across different Stripe accounts - each product just needs its own stripe_secret_key_env and we're good to go.

Here's what I built:

The API Layer

  • /api/orders/sync - Pulls checkout sessions from Stripe (way better than charges for getting customer/shipping data)
  • /api/orders/[id]/shipping-email - Sends those slick SendGrid emails with tracking info
  • /api/orders/shipping-config/[productId] - Maps all the template variables

The UI Components

  • Complete ShippingModal with carrier auto-URL generation and email preview
  • Enhanced orders list with product filtering and shipping status badges
  • Order details now show tracking links and let you resend emails

The Smart Bits

  • Carrier URL patterns that automatically generate tracking links
  • BunkerVault tier extraction (Starter=32GB/2, Standard=64GB/4, Pro=128GB/6)
  • Proper UTC date handling so timezones don't mess up your shipping dates

The Bug Hunt

Of course, nothing works perfectly on the first try. Spent time fixing:

  • Shipping field persistence issues
  • Order number collisions (learned to query highest existing ORD-NNNN suffix instead of just counting)
  • Email template data formatting
  • Badge logic that was checking delivered status in the wrong order

That order number collision bug was particularly sneaky - turns out using total count breaks when you delete orders or have non-standard prefixes.

Technical Decisions

Went with checkout sessions over charges for Stripe sync because they give us way richer customer and shipping data. Also decided to scope everything to the authenticated user's org to keep things secure and performant.

Added both order_id and sendgrid_template_id to the email_sends table for a complete audit trail. Might be overkill but I like having the data.

What's Next

Need to run that migration in Supabase and do some end-to-end testing with real SendGrid templates. Also thinking about adding bulk shipping emails for when you need to process a bunch of orders at once.

The shipping system is fully functional now for any product that has the right config. Feels good to have this foundational piece locked down.

1410 lines added, 257 removed. Not bad for a day's work.

Share this post