This commit is contained in:
mark H 2024-09-24 11:06:23 +08:00
parent d1ff1c7f85
commit ce8a5996b3
1 changed files with 24 additions and 2 deletions

View File

@ -12,16 +12,35 @@ const Main: React.FC = () => {
const [activeTask, setActiveTask] = useState<Task | null>(null);
const { kdsStage, updateKDSstage } = useAppContext();
const [tasks, setTasks] = useState(kdsStage);
const [stages, setstages] = useState([]);
useEffect(() => {
setTasks(kdsStage);
}, [kdsStage]);
useEffect(() => {
getStages()
}, []);
const handleDragStart = (event: any) => {
const { id } = event.active;
const task = findTaskById(id);
setActiveTask(task);
};
const getStages = async () => {
try {
const response = await fetch("http://localhost:3002/get-stages");
if (!response.ok) {
throw new Error("Network response was not ok");
} else {
const stages = await response.json();
setstages(stages); // Ensure you're setting stages in the correct state
//console.log(stages);
return stages; // Return the stages so they can be used later
}
} catch (error) {
console.error("Failed to fetch KDS data:", error);
return [];
}
};
// const updateKDS = async (kdsItem, newState, pos) => {
// try {
@ -56,7 +75,10 @@ const Main: React.FC = () => {
);
console.log(newState);
// If the new state is "serve", make the second API call to update the order state
if (newState === "served") {
const lastStage = stages?.find(stage => stage.last_stage === true);
console.log()
// If the newState matches the last stage name, update the order state
if (newState === lastStage.name) {
const body = {
id: kdsItem.order_id, // Assuming order_id is available in kdsItem
state: "done",