Dev Helpers
← Back

Minimum stock request

Place this file at app/rental/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/rental/page.tsx

import Form from "next/form";

export default async function MinimumStockRequest({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const equipment = [
    { id: "press", day: 40, deposit: 100, qty: 2 },
    { id: "lamp", day: 12, deposit: 25, qty: 8 },
    { id: "stand", day: 8, deposit: 10, qty: 5 },
  ];
  const { units } = await searchParams;
  return (
    <main>
      <Form action="/rental">
        <input aria-label="Units required" name="units" type="number" min="1" />
        <button>Check</button>
      </Form>
      {equipment
        .filter((e) => e.qty >= Math.max(1, Number(units) || 1))
        .map((e) => (
          <p key={e.id}>
            {e.id}: {e.qty} available
          </p>
        ))}
    </main>
  );
}