diff --git a/ui/src/app/page.js b/ui/src/app/page.js index a562cc9..7acb3f0 100644 --- a/ui/src/app/page.js +++ b/ui/src/app/page.js @@ -138,7 +138,7 @@ const Home = async () => { alertDialogDescription={` This action cannot be undone. This will reset the healthy counter and start the sick interval.`} - handleUpdate={async function s() { + handleUpdate={async function update() { "use server"; return recordEvent("ohno"); }} @@ -151,7 +151,10 @@ const Home = async () => { alertDialogDescription={` This action cannot be undone. This will reset the sick counter and start the healthy interval.`} - // handleUpdate={recordEvent("fine")} + handleUpdate={async function update() { + "use server"; + return recordEvent("fine"); + }} /> diff --git a/ui/src/utils/actions.js b/ui/src/utils/actions.js index 536b728..6268ef7 100644 --- a/ui/src/utils/actions.js +++ b/ui/src/utils/actions.js @@ -1,4 +1,4 @@ -"use server"; +// "use server"; /** * @typedef {Object } RecordEventApiResponse @@ -10,12 +10,11 @@ * @param {string} endpoint - The endpoint to record the event to. * @returns {Promise} A promise that resolves when the event is successfully recorded. */ -export const recordEvent = async (endpoint) => { - // "use server"; - try { - const rootUrl = process.env.NEXT_PUBLIC_ROOT_API_URL; - const url = `${rootUrl}/${endpoint}`; +export const recordEvent = async (eventType) => { + const rootUrl = process.env.NEXT_PUBLIC_ROOT_API_URL; + const url = `${rootUrl}${eventType}`; + try { const response = await fetch(url, { method: "POST", headers: { @@ -23,19 +22,19 @@ export const recordEvent = async (endpoint) => { }, }); - console.log("response: ", response); - if (!response.ok) { throw new Error("Failed to record event"); } + /** @type {RecordEventApiResponse} */ const data = await response.json(); + if (!data || !data.message) { throw new Error("Invalid response data"); } + return; } catch (error) { - console.log(error); - throw new Error(`Error recording event: ${error.message}`); + throw new Error(error.message); } };