51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { useForm } from "react-hook-form";
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import { PostForm } from "@/widgets/post";
|
|
import { PostApi, postFormSchema, type PostFormData } from "@/entities/post";
|
|
import { useAlertStore, useUserStore, useMutationWrapper } from "@/shared/lib";
|
|
|
|
function CreatePage({ bbsId, pstNo }: { bbsId: string; pstNo?: string }) {
|
|
const answerRegisterMode = !!pstNo;
|
|
|
|
const router = useRouter();
|
|
const userInfo = useUserStore((state) => state.userInfo);
|
|
const alert = useAlertStore((state) => state.setMessage);
|
|
|
|
const { mutateAsync: createPost } = useMutationWrapper({
|
|
mutationFn: (data: PostFormData) => PostApi.createPost(data),
|
|
onSuccess: () => {
|
|
alert("등록되었습니다.", router.back);
|
|
},
|
|
});
|
|
|
|
const form = useForm<PostFormData>({
|
|
resolver: zodResolver(postFormSchema),
|
|
values: {
|
|
bbsId: parseInt(bbsId),
|
|
pstTtl: "",
|
|
wrtrNm: userInfo?.userName ?? "",
|
|
pstPswd: userInfo?.userUnqId ?? "",
|
|
popupYn: "N",
|
|
upndFixYn: "N",
|
|
prdPstgYn: "N",
|
|
parentPstNo: pstNo ? parseInt(pstNo) : null,
|
|
},
|
|
});
|
|
|
|
return (
|
|
<div className="card card-border !mt-6">
|
|
<div className="card-header">
|
|
<h3 className="text-2xl font-medium text-label">
|
|
{answerRegisterMode ? "답글 등록" : "게시글 등록"}
|
|
</h3>
|
|
</div>
|
|
<PostForm form={form} handleSave={createPost} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { CreatePage };
|