Обновить web/app/orders/[id]/page.tsx
This commit is contained in:
parent
755fccf039
commit
b8334cc346
@ -1,46 +1,46 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import type { Order } from "@/lib/types";
|
import type { Order } from "@/lib/types";
|
||||||
|
|
||||||
export default function OrderPage() {
|
export default function OrderPage() {
|
||||||
const params = useParams<{ id: string }>();
|
const params = useParams<{ id: string }>();
|
||||||
const [order, setOrder] = useState<Order | null>(null);
|
const [order, setOrder] = useState<Order | null>(null);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void (async () => {
|
void (async () => {
|
||||||
const response = await fetch(`/backend/orders/${params.id}`, { credentials: "include", cache: "no-store" });
|
const response = await fetch(`/backend/orders/${params.id}`, { credentials: "include", cache: "no-store" });
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
setError("Заказ не найден");
|
setError("Заказ не найден");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setOrder(await response.json());
|
setOrder(await response.json());
|
||||||
})();
|
})();
|
||||||
}, [params.id]);
|
}, [params.id]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <p className="error">{error}</p>;
|
return <p className="error">{error}</p>;
|
||||||
}
|
}
|
||||||
if (!order) {
|
if (!order) {
|
||||||
return <p>Загрузка…</p>;
|
return <p>Загрузка...</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Заказ {order.id}</h1>
|
<h1>Заказ {order.id}</h1>
|
||||||
<p>Статус: создан, без оплаты.</p>
|
<p>Статус: создан, без оплаты.</p>
|
||||||
<p>
|
<p>
|
||||||
{order.customer_name}, {order.customer_phone}
|
{order.customer_name}, {order.customer_phone}
|
||||||
</p>
|
</p>
|
||||||
{order.items.map((item) => (
|
{order.items.map((item) => (
|
||||||
<p key={item.product_id}>
|
<p key={item.product_id}>
|
||||||
{item.title} × {item.qty} — {item.price} ₽
|
{item.title} x {item.qty} - {item.price} руб.
|
||||||
</p>
|
</p>
|
||||||
))}
|
))}
|
||||||
<p>Итого: {order.total} ₽</p>
|
<p>Итого: {order.total} руб.</p>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user