diff --git a/apps/university-web/src/apis/community/api.ts b/apps/university-web/src/apis/community/api.ts deleted file mode 100644 index 52e7ba6d..00000000 --- a/apps/university-web/src/apis/community/api.ts +++ /dev/null @@ -1,153 +0,0 @@ -import type { AxiosResponse } from "axios"; -import { COMMUNITY_MAX_UPLOAD_IMAGES } from "@/constants/community"; -import type { - CommentCreateRequest, - CommentIdResponse, - ListPost, - Post, - PostCreateRequest, - PostIdResponse, - PostLikeResponse, - PostUpdateRequest, -} from "@/types/community"; -import { axiosInstance, publicAxiosInstance } from "@/utils/axiosInstance"; - -// QueryKeys for community domain -export const CommunityQueryKeys = { - posts: "posts", - postList: "postList1", // 기존 api/boards와 동일한 키 유지 -} as const; - -export interface BoardListResponse { - 0: string; - 1: string; - 2: string; - 3: string; -} - -export interface BoardResponseItem { - id: number; - title: string; - content: string; - likeCount: number; - commentCount: number; - createdAt: string; - updatedAt: string; - postCategory: string; - postThumbnailUrl: null | string; -} - -export interface BoardResponse { - 0: BoardResponseItem[]; - 1: BoardResponseItem[]; - 2: BoardResponseItem[]; - 3: BoardResponseItem[]; -} - -// Delete response types -export interface DeletePostResponse { - message: string; - postId: number; -} - -// Re-export types from @/types/community for convenience -export type { - Post, - PostCreateRequest, - PostIdResponse, - PostUpdateRequest, - PostLikeResponse, - CommentCreateRequest, - CommentIdResponse, - ListPost, -}; - -export const communityApi = { - /** - * 게시글 목록 조회 (클라이언트) - */ - getPostList: (boardCode: string, category: string | null = null): Promise> => { - const params = category && category !== "전체" ? { category } : {}; - return publicAxiosInstance.get(`/boards/${boardCode}`, { params }); - }, - - getBoardList: async (params?: Record): Promise => { - const res = await axiosInstance.get(`/boards`, { params }); - return res.data; - }, - - getBoard: async (boardCode: string, params?: Record): Promise => { - const res = await axiosInstance.get(`/boards/${boardCode}`, { params }); - return res.data; - }, - - getPostDetail: async (postId: number): Promise => { - const response: AxiosResponse = await axiosInstance.get(`/posts/${postId}`); - return response.data; - }, - - createPost: async (request: PostCreateRequest): Promise => { - const convertedRequest: FormData = new FormData(); - convertedRequest.append( - "postCreateRequest", - new Blob([JSON.stringify(request.postCreateRequest)], { type: "application/json" }), - ); - request.file.slice(0, COMMUNITY_MAX_UPLOAD_IMAGES).forEach((file) => { - convertedRequest.append("file", file); - }); - - const response: AxiosResponse = await axiosInstance.post(`/posts`, convertedRequest, { - headers: { "Content-Type": "multipart/form-data" }, - }); - - return { - ...response.data, - boardCode: request.postCreateRequest.boardCode, - }; - }, - - updatePost: async (postId: number, request: PostUpdateRequest): Promise => { - const convertedRequest: FormData = new FormData(); - convertedRequest.append( - "postUpdateRequest", - new Blob([JSON.stringify(request.postUpdateRequest)], { type: "application/json" }), - ); - request.file.slice(0, COMMUNITY_MAX_UPLOAD_IMAGES).forEach((file) => { - convertedRequest.append("file", file); - }); - - const response: AxiosResponse = await axiosInstance.patch(`/posts/${postId}`, convertedRequest, { - headers: { "Content-Type": "multipart/form-data" }, - }); - return response.data; - }, - - deletePost: async (postId: number): Promise> => { - return axiosInstance.delete(`/posts/${postId}`); - }, - - likePost: async (postId: number): Promise => { - const response: AxiosResponse = await axiosInstance.post(`/posts/${postId}/like`); - return response.data; - }, - - unlikePost: async (postId: number): Promise => { - const response: AxiosResponse = await axiosInstance.delete(`/posts/${postId}/like`); - return response.data; - }, - - createComment: async (request: CommentCreateRequest): Promise => { - const response: AxiosResponse = await axiosInstance.post(`/comments`, request); - return response.data; - }, - - deleteComment: async (commentId: number): Promise => { - const response: AxiosResponse = await axiosInstance.delete(`/comments/${commentId}`); - return response.data; - }, - - updateComment: async (commentId: number, data: { content: string }): Promise => { - const res = await axiosInstance.patch(`/comments/${commentId}`, data); - return res.data; - }, -}; diff --git a/apps/university-web/src/apis/community/deleteComment.ts b/apps/university-web/src/apis/community/deleteComment.ts deleted file mode 100644 index 5f22aee0..00000000 --- a/apps/university-web/src/apis/community/deleteComment.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; - -import { showIconToast } from "@/lib/toast/showIconToast"; -import { type CommentIdResponse, CommunityQueryKeys, communityApi } from "./api"; - -interface DeleteCommentRequest { - commentId: number; - postId: number; -} - -/** - * @description 댓글 삭제를 위한 useMutation 커스텀 훅 - */ -const useDeleteComment = () => { - const queryClient = useQueryClient(); - - return useMutation({ - mutationFn: ({ commentId }) => communityApi.deleteComment(commentId), - onSuccess: (_data, variables) => { - // 해당 게시글 상세 쿼리를 무효화하여 댓글 목록 갱신 - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts, variables.postId] }); - showIconToast("logo", "댓글이 삭제되었습니다."); - }, - }); -}; - -export default useDeleteComment; diff --git a/apps/university-web/src/apis/community/deleteLikePost.ts b/apps/university-web/src/apis/community/deleteLikePost.ts deleted file mode 100644 index 82c4027d..00000000 --- a/apps/university-web/src/apis/community/deleteLikePost.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; - -import { CommunityQueryKeys, communityApi, type PostLikeResponse } from "./api"; - -/** - * @description 게시글 좋아요 취소를 위한 useMutation 커스텀 훅 - */ -const useDeleteLike = () => { - const queryClient = useQueryClient(); - - return useMutation({ - mutationFn: communityApi.unlikePost, - onSuccess: (_data, postId) => { - // 해당 게시글 상세 쿼리를 무효화하여 최신 데이터 반영 - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts, postId] }); - }, - }); -}; - -export default useDeleteLike; diff --git a/apps/university-web/src/apis/community/deletePost.ts b/apps/university-web/src/apis/community/deletePost.ts deleted file mode 100644 index e7f42384..00000000 --- a/apps/university-web/src/apis/community/deletePost.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; - -import type { AxiosError, AxiosResponse } from "axios"; -import { useRouter } from "next/navigation"; -import { showIconToast } from "@/lib/toast/showIconToast"; -import useAuthStore from "@/lib/zustand/useAuthStore"; -import { CommunityQueryKeys, communityApi, type DeletePostResponse } from "./api"; - -interface DeletePostVariables { - postId: number; - boardCode?: string; -} - -/** - * @description ISR 페이지를 revalidate하는 함수 - * @param boardCode - 게시판 코드 - * @param accessToken - 사용자 인증 토큰 - */ -const revalidateCommunityPage = async (boardCode: string, accessToken: string) => { - try { - if (!accessToken) { - return; - } - - await fetch("/api/revalidate", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${accessToken}`, - }, - body: JSON.stringify({ boardCode }), - }); - } catch (error) {} -}; - -/** - * @description 게시글 삭제를 위한 useMutation 커스텀 훅 - */ -const useDeletePost = () => { - const router = useRouter(); - const queryClient = useQueryClient(); - const { accessToken } = useAuthStore(); - - return useMutation, AxiosError, DeletePostVariables>({ - mutationFn: ({ postId }) => communityApi.deletePost(postId), - onSuccess: async (_result, variables) => { - // 'posts' 쿼리 키를 가진 모든 쿼리를 무효화하여 - // 게시글 목록을 다시 불러오도록 합니다. - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts] }); - - // ISR 페이지 revalidate - if (variables.boardCode && accessToken) { - await revalidateCommunityPage(variables.boardCode, accessToken); - } - - showIconToast("logo", "게시글이 성공적으로 삭제되었습니다."); - - // 게시글 목록 페이지 이동 - router.replace(`/community/${variables.boardCode || "FREE"}`); - }, - }); -}; - -export default useDeletePost; diff --git a/apps/university-web/src/apis/community/getBoard.ts b/apps/university-web/src/apis/community/getBoard.ts deleted file mode 100644 index f4614784..00000000 --- a/apps/university-web/src/apis/community/getBoard.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; -import { QueryKeys } from "../queryKeys"; -import { type BoardResponse, communityApi } from "./api"; - -const useGetBoard = (boardCode: string | number, params?: Record) => { - return useQuery({ - queryKey: [QueryKeys.community.board, boardCode, params], - queryFn: () => communityApi.getBoard(boardCode as string, params), - enabled: !!boardCode, - }); -}; - -export default useGetBoard; diff --git a/apps/university-web/src/apis/community/getBoardList.ts b/apps/university-web/src/apis/community/getBoardList.ts deleted file mode 100644 index b431eb01..00000000 --- a/apps/university-web/src/apis/community/getBoardList.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; -import { QueryKeys } from "../queryKeys"; -import { type BoardListResponse, communityApi } from "./api"; - -const useGetBoardList = (params?: Record) => { - return useQuery({ - queryKey: [QueryKeys.community.boardList, params], - queryFn: () => communityApi.getBoardList(params ? { params } : {}), - }); -}; - -export default useGetBoardList; diff --git a/apps/university-web/src/apis/community/getPostDetail.ts b/apps/university-web/src/apis/community/getPostDetail.ts deleted file mode 100644 index 8323dad7..00000000 --- a/apps/university-web/src/apis/community/getPostDetail.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; -import { CommunityQueryKeys, communityApi, type Post } from "./api"; - -/** - * @description 게시글 상세 조회를 위한 useQuery 커스텀 훅 - */ -const useGetPostDetail = (postId: number) => { - return useQuery({ - queryKey: [CommunityQueryKeys.posts, postId], - queryFn: () => communityApi.getPostDetail(postId), - enabled: !!postId, - }); -}; - -export default useGetPostDetail; diff --git a/apps/university-web/src/apis/community/getPostList.ts b/apps/university-web/src/apis/community/getPostList.ts deleted file mode 100644 index 28885d0a..00000000 --- a/apps/university-web/src/apis/community/getPostList.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; - -import { CommunityQueryKeys, communityApi } from "./api"; - -interface UseGetPostListProps { - boardCode: string; - category?: string | null; -} - -/** - * @description 게시글 목록 조회 훅 - */ -const useGetPostList = ({ boardCode, category = null }: UseGetPostListProps) => { - return useQuery({ - queryKey: [CommunityQueryKeys.postList, boardCode, category], - queryFn: () => communityApi.getPostList(boardCode, category), - staleTime: Infinity, - gcTime: 1000 * 60 * 30, // 30분 - select: (response) => { - return [...response.data].sort((a, b) => { - return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(); - }); - }, - }); -}; - -export default useGetPostList; diff --git a/apps/university-web/src/apis/community/index.ts b/apps/university-web/src/apis/community/index.ts deleted file mode 100644 index d396a31d..00000000 --- a/apps/university-web/src/apis/community/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -export type { - CommentCreateRequest, - CommentIdResponse, - ListPost, - Post, - PostCreateRequest, - PostIdResponse, - PostLikeResponse, - PostUpdateRequest, -} from "./api"; -export { CommunityQueryKeys, communityApi } from "./api"; -export { default as useDeleteComment } from "./deleteComment"; -export { default as useDeleteLike } from "./deleteLikePost"; -export { default as useDeletePost } from "./deletePost"; -export { default as useGetBoard } from "./getBoard"; -export { default as useGetBoardList } from "./getBoardList"; -export { default as useGetPostDetail } from "./getPostDetail"; -export { default as useGetPostList } from "./getPostList"; -export { default as usePatchUpdateComment } from "./patchUpdateComment"; -export { default as useUpdatePost } from "./patchUpdatePost"; -export { default as useCreateComment } from "./postCreateComment"; -export { default as useCreatePost } from "./postCreatePost"; -export { default as usePostLike } from "./postLikePost"; - -// Server-side functions -export { getPostListServer } from "./server"; diff --git a/apps/university-web/src/apis/community/patchUpdateComment.ts b/apps/university-web/src/apis/community/patchUpdateComment.ts deleted file mode 100644 index 8b235b55..00000000 --- a/apps/university-web/src/apis/community/patchUpdateComment.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useMutation } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; -import { type CommentIdResponse, communityApi } from "./api"; - -const usePatchUpdateComment = () => { - return useMutation({ - mutationFn: ({ commentId, content }) => communityApi.updateComment(commentId, { content }), - }); -}; - -export default usePatchUpdateComment; diff --git a/apps/university-web/src/apis/community/patchUpdatePost.ts b/apps/university-web/src/apis/community/patchUpdatePost.ts deleted file mode 100644 index a45e948d..00000000 --- a/apps/university-web/src/apis/community/patchUpdatePost.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; -import { showIconToast } from "@/lib/toast/showIconToast"; -import useAuthStore from "@/lib/zustand/useAuthStore"; -import { CommunityQueryKeys, communityApi, type PostIdResponse, type PostUpdateRequest } from "./api"; - -interface UpdatePostVariables { - postId: number; - data: PostUpdateRequest; - boardCode?: string; -} - -/** - * @description ISR 페이지를 revalidate하는 함수 - * @param boardCode - 게시판 코드 - * @param accessToken - 사용자 인증 토큰 - */ -const revalidateCommunityPage = async (boardCode: string, accessToken: string) => { - try { - if (!accessToken) { - return; - } - - await fetch("/api/revalidate", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${accessToken}`, - }, - body: JSON.stringify({ boardCode }), - }); - } catch (error) {} -}; - -/** - * @description 게시글 수정을 위한 useMutation 커스텀 훅 - */ -const useUpdatePost = () => { - const queryClient = useQueryClient(); - const { accessToken } = useAuthStore(); - - return useMutation({ - mutationFn: ({ postId, data }) => communityApi.updatePost(postId, data), - onSuccess: async (_result, variables) => { - // 해당 게시글 상세 쿼리와 목록 쿼리를 무효화 - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts, variables.postId] }); - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts] }); - - // ISR 페이지 revalidate - if (variables.boardCode && accessToken) { - await revalidateCommunityPage(variables.boardCode, accessToken); - } - - showIconToast("logo", "게시글이 수정되었습니다."); - }, - }); -}; - -export default useUpdatePost; diff --git a/apps/university-web/src/apis/community/postCreateComment.ts b/apps/university-web/src/apis/community/postCreateComment.ts deleted file mode 100644 index 5fea1a65..00000000 --- a/apps/university-web/src/apis/community/postCreateComment.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; - -import { showIconToast } from "@/lib/toast/showIconToast"; -import { type CommentCreateRequest, type CommentIdResponse, CommunityQueryKeys, communityApi } from "./api"; - -/** - * @description 댓글 생성을 위한 useMutation 커스텀 훅 - */ -const useCreateComment = () => { - const queryClient = useQueryClient(); - - return useMutation({ - mutationFn: communityApi.createComment, - onSuccess: (_data, variables) => { - // 해당 게시글 상세 쿼리를 무효화하여 댓글 목록 갱신 - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts, variables.postId] }); - showIconToast("logo", "댓글이 등록되었습니다."); - }, - }); -}; - -export default useCreateComment; diff --git a/apps/university-web/src/apis/community/postCreatePost.ts b/apps/university-web/src/apis/community/postCreatePost.ts deleted file mode 100644 index aec6291c..00000000 --- a/apps/university-web/src/apis/community/postCreatePost.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; -import { showIconToast } from "@/lib/toast/showIconToast"; -import useAuthStore from "@/lib/zustand/useAuthStore"; -import { CommunityQueryKeys, communityApi, type PostCreateRequest, type PostIdResponse } from "./api"; - -/** - * @description ISR 페이지를 revalidate하는 함수 - * @param boardCode - 게시판 코드 - * @param accessToken - 사용자 인증 토큰 - */ -const revalidateCommunityPage = async (boardCode: string, accessToken: string) => { - try { - if (!accessToken) { - return; - } - - await fetch("/api/revalidate", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${accessToken}`, - }, - body: JSON.stringify({ boardCode }), - }); - } catch (error) {} -}; - -/** - * @description 게시글 생성을 위한 useMutation 커스텀 훅 - */ -const useCreatePost = () => { - const queryClient = useQueryClient(); - const { accessToken } = useAuthStore(); - - return useMutation({ - mutationFn: communityApi.createPost, - onSuccess: async (data) => { - // 게시글 목록 쿼리를 무효화하여 최신 목록 반영 - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts] }); - - // ISR 페이지 revalidate (사용자 인증 토큰 사용) - if (accessToken) { - await revalidateCommunityPage(data.boardCode, accessToken); - } - - showIconToast("logo", "게시글이 등록되었습니다."); - }, - }); -}; - -export default useCreatePost; diff --git a/apps/university-web/src/apis/community/postLikePost.ts b/apps/university-web/src/apis/community/postLikePost.ts deleted file mode 100644 index 6ddfb937..00000000 --- a/apps/university-web/src/apis/community/postLikePost.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { AxiosError } from "axios"; - -import { CommunityQueryKeys, communityApi, type PostLikeResponse } from "./api"; - -/** - * @description 게시글 좋아요를 위한 useMutation 커스텀 훅 - */ -const usePostLike = () => { - const queryClient = useQueryClient(); - - return useMutation({ - mutationFn: communityApi.likePost, - onSuccess: (_data, postId) => { - // 해당 게시글 상세 쿼리를 무효화하여 최신 데이터 반영 - queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts, postId] }); - }, - }); -}; - -export default usePostLike; diff --git a/apps/university-web/src/apis/community/server.ts b/apps/university-web/src/apis/community/server.ts deleted file mode 100644 index 9f394816..00000000 --- a/apps/university-web/src/apis/community/server.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { ListPost } from "@/types/community"; -import serverFetch, { type ServerFetchResult } from "@/utils/serverFetchUtil"; - -interface GetPostListParams { - boardCode: string; - category?: string | null; - revalidate?: number | false; -} - -/** - * @description 게시글 목록을 서버에서 가져오는 함수 (ISR 지원) - * @param boardCode - 게시판 코드 - * @param category - 카테고리 (선택) - * @param revalidate - ISR revalidate 시간(초) 또는 false (무한 캐시) - * @returns Promise> - */ -export const getPostListServer = async ({ - boardCode, - category = null, - revalidate = false, -}: GetPostListParams): Promise> => { - const params = new URLSearchParams(); - if (category && category !== "전체") { - params.append("category", category); - } - - const queryString = params.toString(); - const url = `/boards/${boardCode}${queryString ? `?${queryString}` : ""}`; - - return serverFetch(url, { - method: "GET", - next: { - ...(revalidate !== false && { revalidate }), - tags: [`posts-${boardCode}`], - }, - }); -}; diff --git a/apps/university-web/src/constants/community.ts b/apps/university-web/src/constants/community.ts deleted file mode 100644 index 198a9770..00000000 --- a/apps/university-web/src/constants/community.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const COMMUNITY_BOARDS = [ - { code: "FREE", nameKo: "자유" }, - { code: "EUROPE", nameKo: "유럽권" }, - { code: "AMERICAS", nameKo: "미주권" }, - { code: "ASIA", nameKo: "아시아권" }, -]; - -export const COMMUNITY_CATEGORIES = ["전체", "자유", "질문"]; - -export const COMMUNITY_MAX_UPLOAD_IMAGES = 5; diff --git a/apps/university-web/src/types/community.ts b/apps/university-web/src/types/community.ts deleted file mode 100644 index 0e0e39dc..00000000 --- a/apps/university-web/src/types/community.ts +++ /dev/null @@ -1,96 +0,0 @@ -export interface Board { - name: string; - koreanName: string; -} - -export interface CommunityUser { - id: number; - nickname: string; - profileImageUrl: string; -} - -export interface Comment { - id: number; - parentId: number | null; - content: string; - isOwner: boolean; - createdAt: string; - updatedAt: string; - postFindSiteUserResponse: CommunityUser; -} - -export interface PostImage { - id: number; - url: string; -} - -export interface Post { - id: number; - title: string; - content: string; - isQuestion: boolean; - likeCount: number; - viewCount: number; - commentCount: number; - postCategory: string; - isOwner: boolean; - isLiked: boolean; - createdAt: string; - updatedAt: string; - postFindBoardResponse: Board; - postFindSiteUserResponse: CommunityUser; - postFindCommentResponses: Comment[]; - postFindPostImageResponses: PostImage[]; -} - -export interface ListPost { - id: number; - title: string; - content: string; - likeCount: number; - commentCount: number; - createdAt: string; - updatedAt: string; - postCategory: string; - url: string | null; - postThumbnailUrl: string | null; -} - -export interface PostCreateRequest { - postCreateRequest: { - boardCode: string; - postCategory: string; - title: string; - content: string; - isQuestion: boolean; - }; - file: Blob[]; -} - -export interface PostUpdateRequest { - postUpdateRequest: { - postCategory: string; - title: string; - content: string; - }; - file: File[]; -} - -export interface CommentCreateRequest { - postId: number; - content: string; - parentId: number | null; -} - -export interface PostIdResponse { - id: number; -} - -export interface CommentIdResponse { - id: number; -} - -export interface PostLikeResponse { - likeCount: number; - isLiked: boolean; -} diff --git a/apps/web/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx b/apps/web/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx index d281a181..6dfdb2b4 100644 --- a/apps/web/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx +++ b/apps/web/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx @@ -3,9 +3,10 @@ import { useRouter } from "next/navigation"; import { useEffect, useRef, useState } from "react"; import { useUpdatePost } from "@/apis/community"; +import PostCategorySelector from "@/app/community/_components/PostCategorySelector"; import useCommunityImageUpload from "@/app/community/_hooks/useCommunityImageUpload"; import { showIconToast } from "@/lib/toast/showIconToast"; -import { IconArrowBackFilled, IconImage, IconPostCheckboxFilled, IconPostCheckboxOutlined } from "@/public/svgs"; +import { IconArrowBackFilled, IconImage } from "@/public/svgs"; type PostModifyFormProps = { boardCode: string; @@ -26,7 +27,9 @@ const PostModifyForm = ({ }: PostModifyFormProps) => { const [title, setTitle] = useState(defaultTitle); const [content, setContent] = useState(defaultContent); - const [isQuestion, setIsQuestion] = useState(defaultIsQuestion); + const [postCategory, setPostCategory] = useState( + defaultPostCategory || (defaultIsQuestion ? "질문" : "자유"), + ); const textareaRef = useRef(null); const titleRef = useRef(null); const { @@ -99,7 +102,7 @@ const PostModifyForm = ({ boardCode, data: { postUpdateRequest: { - postCategory: isQuestion ? "질문" : "자유", + postCategory, title: trimmedTitle, content: trimmedContent, }, @@ -152,13 +155,8 @@ const PostModifyForm = ({ }} /> -
-
- - 질문으로 업로드 하기 -
+
+
-
-
- - 질문으로 업로드 하기 -
+
+
+ ); + })} +
+ ); +}; + +export default PostCategorySelector; diff --git a/apps/web/src/constants/community.ts b/apps/web/src/constants/community.ts index 198a9770..3c1b8339 100644 --- a/apps/web/src/constants/community.ts +++ b/apps/web/src/constants/community.ts @@ -5,6 +5,8 @@ export const COMMUNITY_BOARDS = [ { code: "ASIA", nameKo: "아시아권" }, ]; -export const COMMUNITY_CATEGORIES = ["전체", "자유", "질문"]; +export const COMMUNITY_CATEGORIES = ["전체", "자유", "질문", "동행", "중고거래"]; + +export const COMMUNITY_POST_CATEGORIES = ["자유", "질문", "동행", "중고거래"]; export const COMMUNITY_MAX_UPLOAD_IMAGES = 5;