28 lines
865 B
TypeScript
28 lines
865 B
TypeScript
"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<ActionResult> {
|
|
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<ActionResult> {
|
|
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) };
|
|
}
|
|
}
|