Files
latosa-escrima/frontend/app/(auth)/dashboard/blogs/new/editor.tsx
cdricms dbddf12f25 CSR
2025-02-20 20:09:43 +01:00

55 lines
1.3 KiB
TypeScript

"use client";
import { Editor } from "@/components/editor";
import { Button } from "@/components/ui/button";
import useApiMutation from "@/hooks/use-api";
import { useState } from "react";
export default function BlogEditor() {
const {
trigger,
isMutating: loading,
isSuccess,
} = useApiMutation("/blog/new", undefined, "POST", false, true);
const content = localStorage.getItem("blog_draft") ?? "";
return (
<section className="m-10">
<div className="flex">
<div className="flex-1">
<Editor content={content} />
</div>
</div>
<Button
className="text-black bg-white"
onClick={async () => {
try {
// const blogContent = localStorage.getItem("blog_draft");
const res = await trigger({
label: "This is my label",
summary: "A summary",
image: "none",
href: "none",
blogID: "id",
slug: "myslug",
// content: blogContent,
published: "",
});
if (!res)
throw new Error("The server hasn't responded.");
if (res.status === "Error")
throw new Error(res.message);
if (res.data) console.log(res.data);
return res;
} catch (error: any) {
throw new Error(error.message);
}
}}
>
Sauvegarder
</Button>
</section>
);
}