feat: 게시글 등록/수정 유효성 검증 작업

This commit is contained in:
2025-05-07 15:50:23 +09:00
parent 8233f91532
commit a12390672a
7 changed files with 35 additions and 19 deletions
@@ -1,2 +1,10 @@
import { CreatePage } from "@/pages/notice";
export default CreatePage;
export default async function PstBbsNoticeRegisterPage({
params,
}: {
params: Promise<{ bbsId: string }>;
}) {
const { bbsId } = await params;
return <CreatePage bbsId={bbsId} />;
}
@@ -15,7 +15,7 @@ import {
DialogTrigger,
} from "@common/components";
import { ENDPOINT } from "@/shared/config";
import { useAlertStore } from "@/shared/lib/use-alert-store";
import { useAlertStore } from "@/shared/lib";
import {
menuAuthorityFormSchema,
type MenuAuthorityFormData,
@@ -1,13 +1,15 @@
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type {
Post,
PostInfo,
PostList,
PostParams,
PostService,
PostFormData,
PostUpdateFormData,
import {
postFormSchema,
postUpdateFormSchema,
type Post,
type PostInfo,
type PostList,
type PostParams,
type PostService,
type PostFormData,
type PostUpdateFormData,
} from "../model/post-interface";
export class PostApiService implements PostService {
@@ -30,9 +32,10 @@ export class PostApiService implements PostService {
}
public async createPost(data: PostFormData): Promise<Post> {
const validatedData = postFormSchema.parse(data);
const response = await client.post<Post>(
`${ENDPOINT.BOARD_SERVICE.POSTS_USER}`,
data,
validatedData,
);
return response.data;
}
@@ -42,9 +45,10 @@ export class PostApiService implements PostService {
pstNo: string,
data: PostUpdateFormData,
): Promise<Post> {
const validatedData = postUpdateFormSchema.parse(data);
const response = await client.put<Post>(
`${ENDPOINT.BOARD_SERVICE.POSTS_USER}/${bbsId}/${pstNo}`,
data,
validatedData,
);
return response.data;
}
@@ -41,7 +41,7 @@ export interface PostInfo extends Post {
export const postFormSchema = z.object({
bbsId: z.number(),
pstTtl: z.string(),
pstTtl: z.string().nonempty(),
pstCn: z.string().nullish(),
rfrncUrl: z.string().nullish(),
popupYn: z.string().nullish(),
@@ -56,7 +56,6 @@ export const postFormSchema = z.object({
export const postUpdateFormSchema = postFormSchema.omit({
bbsId: true,
pstPswd: true,
parentPstNo: true,
});
@@ -28,6 +28,7 @@ import {
import { CodeSelect } from "@/entities/code/@x/posting";
import { SiteApi, type Site } from "@/entities/site/@x/posting";
import type { PageableList } from "@/shared/model";
import { useAlertStore } from "@/shared/lib";
import { ENDPOINT } from "@/shared/config";
import { PostingApi } from "../api/posting-service";
import {
@@ -36,7 +37,6 @@ import {
type PostingType,
type PostPayload,
} from "../model/posting-interface";
import { useAlertStore } from "@/shared/lib/use-alert-store";
type DateRange = {
from: string;
@@ -9,7 +9,7 @@ import { PostApi, postFormSchema, type PostFormData } from "@/entities/post";
import { useAlertStore, useUserStore } from "@/shared/lib";
import { NoticeLayout } from "./notice-layout";
function CreatePage() {
function CreatePage({ bbsId }: { bbsId: string }) {
const router = useRouter();
const { userInfo } = useUserStore((state) => state);
const { setMessage: alert } = useAlertStore((state) => state);
@@ -24,7 +24,7 @@ function CreatePage() {
const form = useForm<PostFormData>({
resolver: zodResolver(postFormSchema),
values: {
bbsId: 0,
bbsId: parseInt(bbsId),
pstTtl: "",
wrtrNm: userInfo?.userName ?? "",
pstPswd: userInfo?.userUnqId ?? "",
@@ -10,11 +10,12 @@ import {
type PostUpdateFormData,
} from "@/entities/post";
import { ENDPOINT } from "@/shared/config";
import { useAlertStore } from "@/shared/lib/use-alert-store";
import { useAlertStore, useUserStore } from "@/shared/lib";
import { NoticeLayout } from "./notice-layout";
function ModifyPage({ bbsId, pstNo }: { bbsId: string; pstNo: string }) {
const { setMessage: alert } = useAlertStore((state) => state);
const { userInfo } = useUserStore((state) => state);
const { data: postInfo } = useQuery({
queryKey: [ENDPOINT.BOARD_SERVICE.POSTS_USER, bbsId, pstNo],
@@ -31,7 +32,11 @@ function ModifyPage({ bbsId, pstNo }: { bbsId: string; pstNo: string }) {
const form = useForm<PostUpdateFormData>({
resolver: zodResolver(postUpdateFormSchema),
values: postInfo,
values: {
...postInfo,
pstTtl: postInfo?.pstTtl ?? "",
pstPswd: userInfo?.userUnqId ?? "",
},
});
return (