Skip to content

Commit 467550b

Browse files
Merge pull request #149 from codeit-6team/feat/143-notice-edit-page
✨ feat: 공고 편집 페이지 및 경로 추가
2 parents da30c59 + 6b41653 commit 467550b

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default function App() {
3333
<Route path="post">
3434
<Route index element={<StoreForm />} />
3535
<Route path=":shopId/:noticeId" element={<StorePost />} />
36+
<Route path=":shopId/:noticeId/edit" element={<StoreForm />} />
3637
</Route>
3738
</Route>
3839

src/pages/store/StoreForm.tsx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { useState, useEffect, useCallback, useRef } from 'react';
2-
import { Link, useNavigate } from 'react-router-dom';
2+
import { Link, useNavigate, useParams } from 'react-router-dom';
33
import { getUser } from '@/api/userApi';
4-
import { postShopNotice, type NoticeUpsertRequest } from '@/api/noticeApi';
4+
import {
5+
getShopNotice,
6+
postShopNotice,
7+
putShopNotice,
8+
type NoticeUpsertRequest,
9+
} from '@/api/noticeApi';
510
import Input from '@/components/common/Input';
611
import Button from '@/components/common/Button';
712
import Modal from '@/components/common/Modal';
@@ -15,8 +20,9 @@ export default function StoreForm() {
1520
workhour: undefined,
1621
description: '',
1722
});
18-
const shopId = useRef('');
19-
const noticeId = useRef('');
23+
const params = useParams();
24+
const shopId = useRef(params.shopId ?? '');
25+
const noticeId = useRef(params.noticeId ?? '');
2026

2127
const [modal, setModal] = useState({
2228
isOpen: false,
@@ -36,8 +42,23 @@ export default function StoreForm() {
3642

3743
(async () => {
3844
try {
39-
const userInfo = await getUser(userId);
40-
shopId.current = userInfo.item.shop?.item.id ?? '';
45+
if (shopId.current) {
46+
const { item } = await getShopNotice(
47+
shopId.current,
48+
noticeId.current,
49+
);
50+
setNoticeInfo({
51+
...item,
52+
startsAt: new Date(
53+
new Date(item.startsAt).getTime() + 1000 * 60 * 60 * 9,
54+
)
55+
.toISOString()
56+
.slice(0, 16),
57+
});
58+
} else {
59+
const userInfo = await getUser(userId);
60+
shopId.current = userInfo.item.shop?.item.id ?? '';
61+
}
4162
} catch (error) {
4263
setModal({
4364
isOpen: true,
@@ -82,13 +103,18 @@ export default function StoreForm() {
82103

83104
try {
84105
const startsTime = new Date(noticeInfo?.startsAt).toISOString();
85-
const { item } = await postShopNotice(shopId.current, {
106+
const body = {
86107
hourlyPay: noticeInfo?.hourlyPay ?? 0,
87108
startsAt: startsTime,
88109
workhour: noticeInfo?.workhour ?? 0,
89110
description: noticeInfo?.description ?? '',
90-
});
91-
noticeId.current = item.id;
111+
};
112+
if (noticeId.current) {
113+
await putShopNotice(shopId.current, noticeId.current, body);
114+
} else {
115+
const { item } = await postShopNotice(shopId.current, body);
116+
noticeId.current = item.id;
117+
}
92118
setModal({
93119
isOpen: true,
94120
message: '등록이 완료되었습니다.',
@@ -117,8 +143,14 @@ export default function StoreForm() {
117143
<div className="min-h-[calc(100vh-102px)] bg-gray-5 md:min-h-[calc(100vh-70px)]">
118144
<div className="mx-12 flex flex-col gap-24 pt-40 pb-80 md:mx-32 md:gap-32 md:py-60 lg:mx-auto lg:w-964">
119145
<div className="flex items-center justify-between">
120-
<h1 className="text-h3/24 font-bold md:text-h1/34">내 프로필</h1>
121-
<Link to="/owner/store">
146+
<h1 className="text-h3/24 font-bold md:text-h1/34">공고 등록</h1>
147+
<Link
148+
to={
149+
noticeId.current
150+
? `/owner/post/${shopId.current}/${noticeId.current}`
151+
: '/owner/store'
152+
}
153+
>
122154
<img src={close} alt="닫기" className="md:size-32" />
123155
</Link>
124156
</div>

src/pages/store/StorePost.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ export default function StorePost() {
6565
</div>
6666
{notice && (
6767
<PostLarge data={notice}>
68-
<Button size={isMobile ? 'medium' : 'large'} solid={false}>
68+
<Button
69+
size={isMobile ? 'medium' : 'large'}
70+
solid={false}
71+
onClick={() =>
72+
navigate(`/owner/post/${shopId}/${noticeId}/edit`)
73+
}
74+
>
6975
공고 편집하기
7076
</Button>
7177
</PostLarge>

0 commit comments

Comments
 (0)