working on....

This commit is contained in:
2025-05-23 22:33:12 +02:00
parent 038f60d61e
commit cbda4dee82
28 changed files with 255 additions and 99 deletions

27
src/hooks/useOrders.jsx Normal file
View File

@@ -0,0 +1,27 @@
import { useState, useEffect } from "react";
export default function useOrders() {
const [orders, setOrders] = useState([]);
useEffect(() => {
fetch('http://localhost:5000/orders')
.then(res => res.json())
.then(setOrders);
}, []);
const addOrder = async (order) => {
const res = await fetch('http://localhost:5000/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(order)
});
const newOrder = await res.json();
setOrders([...orders, newOrder]);
};
// Можно реализовать фильтрацию прямо в хуке
const inProcess = orders.filter(o => o.status === "in-process");
const completed = orders.filter(o => o.status === "completed");
return { orders, addOrder, inProcess, completed };
}