読み方のヒント
矢印ボタン(または ← → キー)でページを移動できます。
src/ReservationForm.tsx のフォームは、受け取りの日付、時刻、商品ごとの個数、受け取りの名前を入力させます。
const [name, setName] = useState("");
const [date, setDate] = useState("");
const [time, setTime] = useState("08:00");
const [quantities, setQuantities] = useState<Record<string, number>>({});
送るときに、APIの本文の形に組み立てます。
const items = Object.entries(quantities)
.filter(([, quantity]) => quantity > 0)
.map(([productId, quantity]) => ({ productId, quantity }));
{ name, pickupAt: `${date}T${time}:00+09:00`, items }
| 入力 | 本文の項目 | 例 |
|---|---|---|
日付 2026-10-22、時刻 08:00 | pickupAt | "2026-10-22T08:00:00+09:00" |
| 食パン 1、クロワッサン 2、ほかは 0 | items | [{"productId": "p001", "quantity": 1}, {"productId": "p002", "quantity": 2}] |
| 田中 | name | "田中" |
個数が0の商品は、明細に入れません。日時には、日本時間の +09:00 を付けます。付けないと、APIの入力の検査(時差のない日時を断る)で 422 になります。
本文には、価格も利用者も入れません。価格はAPIが商品の表から決め、利用者はAPIの側で決めます。
{"name": "高橋", "pickupAt": "2026-10-23T10:30:00+09:00", "items": [{"productId": "p003", "quantity": 4}, {"productId": "p005", "quantity": 2}]} です。
3 / 20