diff --git a/web/app/actions.ts b/web/app/actions.ts new file mode 100644 index 0000000..eb14538 --- /dev/null +++ b/web/app/actions.ts @@ -0,0 +1,27 @@ +"use server"; + +import { revalidatePath } from "next/cache"; +import { fetchApi } from "@/lib/api"; +import type { AccUpdate, UserUpdate } from "@/lib/types"; + +export type ActionResult = { ok: true } | { ok: false; error: string }; + +export async function updateAccount(data: AccUpdate): Promise { + try { + await fetchApi("/update-acc-data", { method: "POST", body: data }); + revalidatePath("/"); + return { ok: true }; + } catch (err) { + return { ok: false, error: err instanceof Error ? err.message : String(err) }; + } +} + +export async function updateUser(data: UserUpdate): Promise { + try { + await fetchApi("/update-user-data", { method: "POST", body: data }); + revalidatePath("/users"); + return { ok: true }; + } catch (err) { + return { ok: false, error: err instanceof Error ? err.message : String(err) }; + } +}