Skip to content

Commit

Permalink
chore(post): write page 전역 state로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jyh071116 committed Dec 27, 2023
1 parent 0492ef1 commit b375ad8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/templates/post/hooks/usePostWritable.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import React from "react";
import { useAtom } from "jotai";
import { useImageUpload } from "@/hooks";
import { useUser } from "@/@user/hooks";
import { getFilteredPostDataByCategory, getPostIsValid } from "../helpers";
import {
useCreatePostMutation,
useUpdatePostMutation,
} from "../services/post/mutation.service";
import { Post, PostCategoryType, PostData } from "../types";
import { defaultPostData } from "../assets/data";
import currentCategoryContext from "../context/currentCategory.context";

// edit과 write를 동시에 처리하는 훅
const usePostWritable = (defaultPostDataState?: Post) => {
const [postData, setPostData] = React.useState<Post>(defaultPostData);
const { isAdmin } = useUser();
const [currentCategory] = useAtom(currentCategoryContext);

const is유저가공지사항접근 = !isAdmin && currentCategory === "NOTICE";

const [postData, setPostData] = React.useState<Post>({
...defaultPostData,
category: is유저가공지사항접근 ? "COMMON" : currentCategory,
});
const [lostImageUrl, setLostImageUrl] = React.useState();
const { mutate: updatePostMutate } = useUpdatePostMutation();
const { mutate: createPostMutate } = useCreatePostMutation();
Expand Down

0 comments on commit b375ad8

Please sign in to comment.