feat(web): add updateAccount and updateUser Server Actions
This commit is contained in:
parent
3297c500a4
commit
b398faba0a
27
web/app/actions.ts
Normal file
27
web/app/actions.ts
Normal file
@ -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<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) };
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user