link-stack/apps/bridge-frontend/app/(main)/facebook/[[...segment]]/_actions/facebook.ts

29 lines
761 B
TypeScript
Raw Normal View History

2024-04-24 21:44:05 +02:00
"use server";
import { revalidatePath } from "next/cache";
import { db } from "@/app/_lib/database";
export const addFacebookBotAction = async (
currentState: any,
formData: FormData,
) => {
const newBot = {
name: formData.get("name")?.toString() ?? null,
description: formData.get("description")?.toString() ?? null,
appId: formData.get("appId")?.toString() ?? null,
appSecret: formData.get("appSecret")?.toString() ?? null,
pageId: formData.get("pageId")?.toString() ?? null,
pageAccessToken: formData.get("pageAccessToken")?.toString() ?? null,
};
await db.insertInto("FacebookBot").values(newBot).execute();
revalidatePath("/facebook");
return {
...currentState,
values: newBot,
success: true,
};
};