@@ -10,6 +10,7 @@ import { getNotice, putNotice } from "@/apis/services/noticeService";
1010import { Close } from "@/assets/icon" ;
1111import Button from "@/components/Button" ;
1212import TextField from "@/components/TextField" ;
13+ import { ROUTES } from "@/constants/router" ;
1314import { MIN_WAGE , MAX_WAGE } from "@/constants/wage" ;
1415import { useUserStore } from "@/hooks/useUserStore" ;
1516import { useModalStore } from "@/store/useModalStore" ;
@@ -45,19 +46,77 @@ export default function NoticeEditPage() {
4546 } ) ;
4647
4748 useEffect ( ( ) => {
48- async function fetchNotice ( ) {
49- if ( ! shopId || ! noticeId ) return ;
50- const res = await getNotice ( shopId , noticeId ) ;
51- const { hourlyPay, startsAt, workhour, description } = res . data . item ;
52- setForm ( {
53- hourlyPay : numberCommaFormatter ( hourlyPay ) ,
54- startsAt : new Date ( startsAt ) ,
55- workhour : String ( workhour ) ,
56- description : description ?? "" ,
49+ if ( ! user ) {
50+ openModal ( {
51+ type : "alert" ,
52+ iconType : "warning" ,
53+ message : "로그인 후에 이용 가능한 기능입니다." ,
54+ onClose : ( ) => navigate ( ROUTES . AUTH . SIGNIN ) ,
55+ } ) ;
56+ return ;
57+ }
58+ if ( user . type === "employee" ) {
59+ openModal ( {
60+ type : "alert" ,
61+ iconType : "warning" ,
62+ message : "사장님 계정으로만 이용 가능한 기능입니다." ,
63+ onClose : ( ) => navigate ( ROUTES . PROFILE . ROOT ) ,
5764 } ) ;
65+ return ;
5866 }
67+ if ( ! user . shopId ) {
68+ openModal ( {
69+ type : "alert" ,
70+ iconType : "warning" ,
71+ message : "가게 정보 등록 후 이용 가능합니다." ,
72+ onClose : ( ) => navigate ( ROUTES . SHOP . REGISTER ) ,
73+ } ) ;
74+ return ;
75+ }
76+ } , [ ] ) ;
77+
78+ useEffect ( ( ) => {
79+ if ( ! shopId || ! noticeId ) return ;
80+ const fetchNotice = async ( ) => {
81+ try {
82+ const res = await getNotice ( shopId , noticeId ) ;
83+ const {
84+ hourlyPay,
85+ startsAt,
86+ workhour,
87+ description,
88+ shop : noticeShop ,
89+ } = res . data . item ;
90+
91+ const ownerShopId = noticeShop ?. item . id ;
92+
93+ if ( ownerShopId !== shopId ) {
94+ openModal ( {
95+ type : "alert" ,
96+ iconType : "warning" ,
97+ message : "다른 가게의 공고 편집은 불가능합니다." ,
98+ onClose : ( ) => navigate ( ROUTES . SHOP . ROOT ) ,
99+ } ) ;
100+ return ;
101+ }
102+
103+ setForm ( {
104+ hourlyPay : numberCommaFormatter ( hourlyPay ) ,
105+ startsAt : new Date ( startsAt ) ,
106+ workhour : String ( workhour ) ,
107+ description : description ?? "" ,
108+ } ) ;
109+ } catch {
110+ openModal ( {
111+ type : "alert" ,
112+ iconType : "warning" ,
113+ message : "다른 가게의 공고 편집은 불가능합니다." ,
114+ onClose : ( ) => navigate ( ROUTES . SHOP . ROOT ) ,
115+ } ) ;
116+ }
117+ } ;
59118 fetchNotice ( ) ;
60- } , [ shopId , noticeId ] ) ;
119+ } , [ shopId , noticeId , navigate , openModal ] ) ;
61120
62121 const handleChange = ( key : keyof FormType , value : string | null | Date ) => {
63122 setForm ( ( prev ) => ( { ...prev , [ key ] : value } ) ) ;
0 commit comments