Dev Helpers
← Back

Pickup time slot links

Place this file at app/stores/[branch]/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/stores/[branch]/page.tsx

import Link from "next/link";

import { notFound } from "next/navigation";

export default async function PickupTimeSlotLinks({
  params,
}: {
  params: Promise<{ branch: string }>;
}) {
  const branches = [
    { key: "market", opens: 9, closes: 18, sat: true, stock: 12 },
    { key: "pier", opens: 11, closes: 19, sat: false, stock: 4 },
  ];
  const { branch } = await params;
  const store = branches.find((b) => b.key === branch);
  if (!store) notFound();
  return (
    <nav>
      {Array.from(
        { length: store.closes - store.opens },
        (_, i) => store.opens + i,
      ).map((hour) => (
        <Link key={hour} href={{ pathname: "/reserve", query: { branch, hour } }}>
          {hour}:00{" "}
        </Link>
      ))}
    </nav>
  );
}