Skip to content

Commit 20a2bdb

Browse files
committed
fix: 공고 등록/편집 페이지 리다이렉트
1 parent deeeb5c commit 20a2bdb

File tree

2 files changed

+101
-11
lines changed

2 files changed

+101
-11
lines changed

src/pages/NoticeEditPage.tsx

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getNotice, putNotice } from "@/apis/services/noticeService";
1010
import { Close } from "@/assets/icon";
1111
import Button from "@/components/Button";
1212
import TextField from "@/components/TextField";
13+
import { ROUTES } from "@/constants/router";
1314
import { MIN_WAGE, MAX_WAGE } from "@/constants/wage";
1415
import { useUserStore } from "@/hooks/useUserStore";
1516
import { 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 }));

src/pages/NoticeRegisterPage.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22

33
import type { AxiosError } from "axios";
44
import DatePicker from "react-datepicker";
@@ -10,6 +10,7 @@ import { postNotice } from "@/apis/services/noticeService";
1010
import { Close } from "@/assets/icon";
1111
import Button from "@/components/Button";
1212
import TextField from "@/components/TextField";
13+
import { ROUTES } from "@/constants/router";
1314
import { MAX_WAGE, MIN_WAGE } from "@/constants/wage";
1415
import { useUserStore } from "@/hooks/useUserStore";
1516
import { useModalStore } from "@/store/useModalStore";
@@ -42,6 +43,36 @@ export default function NoticeRegisterPage() {
4243
description: "",
4344
});
4445

46+
useEffect(() => {
47+
if (!user) {
48+
openModal({
49+
type: "alert",
50+
iconType: "warning",
51+
message: "로그인 후 이용 가능한 기능입니다.",
52+
onClose: () => navigate(ROUTES.AUTH.SIGNIN),
53+
});
54+
return;
55+
}
56+
if (user.type === "employee") {
57+
openModal({
58+
type: "alert",
59+
iconType: "warning",
60+
message: "사장님 계정으로만 이용 가능한 기능입니다.",
61+
onClose: () => navigate(ROUTES.PROFILE.ROOT),
62+
});
63+
return;
64+
}
65+
if (!user.shopId) {
66+
openModal({
67+
type: "alert",
68+
iconType: "warning",
69+
message: "가게 정보 등록 후 이용 가능합니다.",
70+
onClose: () => navigate(ROUTES.SHOP.REGISTER),
71+
});
72+
return;
73+
}
74+
}, []);
75+
4576
const handleChange = (key: keyof FormType, value: string | null | Date) => {
4677
setForm((prev) => ({ ...prev, [key]: value }));
4778
};

0 commit comments

Comments
 (0)