From 794e63808152704232d133f1dc658070a373a006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Otgaar?= Date: Wed, 7 Jan 2026 11:54:29 +0100 Subject: [PATCH] feat: start with functionality ref: N25B-400 --- src/pages/MonitoringPage/MonitoringPage.tsx | 24 ++++++++++++++++++- src/pages/MonitoringPage/MonitoringPageAPI.ts | 19 +++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/pages/MonitoringPage/MonitoringPageAPI.ts diff --git a/src/pages/MonitoringPage/MonitoringPage.tsx b/src/pages/MonitoringPage/MonitoringPage.tsx index 32f7b6b..d19dbae 100644 --- a/src/pages/MonitoringPage/MonitoringPage.tsx +++ b/src/pages/MonitoringPage/MonitoringPage.tsx @@ -1,6 +1,7 @@ import React from 'react'; import styles from './MonitoringPage.module.css'; import useProgramStore from "../../utils/programStore.ts"; +import { nextPhase } from ".//MonitoringPageAPI.ts" type Goal = { id?: string | number; description?: string; achieved?: boolean }; type Trigger = { id?: string | number; label?: string ; achieved?: boolean }; @@ -13,6 +14,9 @@ const MonitoringPage: React.FC = () => { const getGoalsInPhase = useProgramStore((s) => s.getGoalsInPhase); const getTriggersInPhase = useProgramStore((s) => s.getTriggersInPhase); + // Can be used to block actions until feedback from CB. + const [loading, setLoading] = React.useState(false); + const phaseIds = getPhaseIds(); const [phaseIndex, setPhaseIndex] = React.useState(0); @@ -26,6 +30,18 @@ const MonitoringPage: React.FC = () => { const triggers = getTriggersInPhase(phaseId) as Trigger[]; const norms = getNormsInPhase(phaseId) as Norm[]; + // Handle logic of 'next' button. + const handleNext = async () => { + try { + setLoading(true); + await nextPhase(); + } catch (err) { + console.log("Monitoring Page could not advance to the next phase:") + console.error(err); + } finally { + setLoading(false); + } + }; return (
@@ -47,7 +63,13 @@ const MonitoringPage: React.FC = () => {

Experiment Controls

- +
diff --git a/src/pages/MonitoringPage/MonitoringPageAPI.ts b/src/pages/MonitoringPage/MonitoringPageAPI.ts new file mode 100644 index 0000000..d08f78c --- /dev/null +++ b/src/pages/MonitoringPage/MonitoringPageAPI.ts @@ -0,0 +1,19 @@ +const API_BASE = "http://localhost:8000/"; // Change depending on Pims interup agent/ correct endpoint + + +/** + * Sends an API call to the CB for going to the next phase. + * In case we can't go to the next phase, the function will throw an error. + */ +export async function nextPhase(): Promise { + const res = await fetch(`${API_BASE}/experiment/next`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + }); + + if (!res.ok) { + throw new Error("Failed to advance to next phase"); + } +} \ No newline at end of file