File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { atom } from "jotai" ;
2
+ import { PostCategoryType } from "../types" ;
3
+ import { CATEGORY } from "../constants" ;
4
+
5
+ const currentCategoryContext = atom < PostCategoryType > ( CATEGORY . COMMON ) ;
6
+
7
+ export default currentCategoryContext ;
Original file line number Diff line number Diff line change
1
+ export { default as currentCategoryContext } from "./currentCategory.context" ;
Original file line number Diff line number Diff line change @@ -3,17 +3,17 @@ import { useRouter } from "next/navigation";
3
3
import dayjs from "dayjs" ;
4
4
import React from "react" ;
5
5
import Swal from "sweetalert2" ;
6
+ import { useAtom } from "jotai" ;
6
7
import { useUser } from "@/@user/hooks" ;
7
8
import { KEY , ROUTER } from "@/constants" ;
8
- import { CATEGORY } from "../constants" ;
9
9
import { defaultPostData } from "../assets/data" ;
10
10
import { useDeletePostMutation } from "../services/post/mutation.service" ;
11
11
import { Post , PostCategoryType } from "../types" ;
12
+ import { currentCategoryContext } from "../context" ;
12
13
13
14
const usePost = ( defaultPostDataState ?: Post ) => {
14
15
const [ postData , setPostData ] = React . useState < Post > ( defaultPostData ) ;
15
- const [ currentCategory , setCurrentCategory ] =
16
- React . useState < PostCategoryType > ( CATEGORY . COMMON ) ;
16
+ const [ currentCategory , setCurrentCategory ] = useAtom ( currentCategoryContext ) ;
17
17
const { mutate : deletePostMutate } = useDeletePostMutation ( ) ;
18
18
const { user } = useUser ( ) ;
19
19
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
+ import { useAtom } from "jotai" ;
2
3
import { useImageUpload } from "@/hooks" ;
4
+ import { useUser } from "@/@user/hooks" ;
3
5
import { getFilteredPostDataByCategory , getPostIsValid } from "../helpers" ;
4
6
import {
5
7
useCreatePostMutation ,
6
8
useUpdatePostMutation ,
7
9
} from "../services/post/mutation.service" ;
8
10
import { Post , PostCategoryType , PostData } from "../types" ;
9
11
import { defaultPostData } from "../assets/data" ;
12
+ import { currentCategoryContext } from "../context" ;
10
13
11
14
// edit과 write를 동시에 처리하는 훅
12
15
const usePostWritable = ( defaultPostDataState ?: Post ) => {
13
- const [ postData , setPostData ] = React . useState < Post > ( defaultPostData ) ;
16
+ const { isAdmin } = useUser ( ) ;
17
+ const [ currentCategory ] = useAtom ( currentCategoryContext ) ;
18
+
19
+ const is유저가공지사항접근 = ! isAdmin && currentCategory === "NOTICE" ;
20
+
21
+ const [ postData , setPostData ] = React . useState < Post > ( {
22
+ ...defaultPostData ,
23
+ category : is유저가공지사항접근 ? "COMMON" : currentCategory ,
24
+ } ) ;
14
25
const [ lostImageUrl , setLostImageUrl ] = React . useState ( ) ;
15
26
const { mutate : updatePostMutate } = useUpdatePostMutation ( ) ;
16
27
const { mutate : createPostMutate } = useCreatePostMutation ( ) ;
You can’t perform that action at this time.
0 commit comments