Skip to content

Commit 516990e

Browse files
authored
Merge pull request #134 from codeit-6team/fix/132-url
🐛 fix: url 경로 수정 및 post 컴포넌트 수정
2 parents dbfe136 + 86e6e35 commit 516990e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function App() {
2020
<Routes>
2121
{/* 공통 페이지 */}
2222
<Route path="/" element={<NoticeList />} />
23-
<Route path=":id" element={<Notice />} />
23+
<Route path=":shopId/:userId" element={<Notice />} />
2424
<Route path="login" element={<Login />} />
2525
<Route path="signup" element={<Signup />} />
2626

@@ -32,7 +32,7 @@ export default function App() {
3232
</Route>
3333
<Route path="post">
3434
<Route index element={<StoreForm />} />
35-
<Route path=":id" element={<StorePost />} />
35+
<Route path=":shopId/:userId" element={<StorePost />} />
3636
</Route>
3737
</Route>
3838

src/components/common/Post.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useNavigate, useLocation } from 'react-router-dom';
12
import formatWorkTime from '@/utils/formatWorkTime';
23
import ClockRed from '@/assets/icons/clock-red.svg';
34
import ClockGray from '@/assets/icons/clock-gray.svg';
@@ -26,15 +27,17 @@ function getStatus(
2627

2728
export default function Post({ data }: { data: NoticeShopItem }) {
2829
const {
30+
id: noticeId,
2931
hourlyPay,
3032
workhour,
3133
startsAt,
3234
closed,
3335
shop: {
34-
item: { name, address1, imageUrl, originalHourlyPay },
36+
item: { id: shopId, name, address1, imageUrl, originalHourlyPay },
3537
},
3638
} = data;
37-
39+
const navigate = useNavigate();
40+
const location = useLocation();
3841
const status = getStatus(startsAt, closed);
3942
const isInactive = status !== 'ACTIVE';
4043
const overlayText = isInactive
@@ -79,8 +82,20 @@ export default function Post({ data }: { data: NoticeShopItem }) {
7982
}
8083
}
8184

85+
const handleClick = () => {
86+
const isOwnerPage = location.pathname.startsWith('/owner');
87+
88+
const path = isOwnerPage
89+
? `/owner/post/${shopId}/${noticeId}`
90+
: `/${shopId}/${noticeId}`;
91+
92+
navigate(path);
93+
};
8294
return (
83-
<div className="flex h-261 w-full cursor-pointer flex-col gap-12 rounded-xl border border-gray-20 bg-white p-12 md:h-359 md:gap-20 md:p-16 lg:h-348">
95+
<button
96+
onClick={handleClick}
97+
className="flex h-261 w-full cursor-pointer flex-col gap-12 rounded-xl border border-gray-20 bg-white p-12 md:h-359 md:gap-20 md:p-16 lg:h-348"
98+
>
8499
<div className="relative">
85100
<div
86101
className="relative h-84 w-full rounded-xl bg-cover bg-center md:h-171 lg:h-160"
@@ -152,6 +167,6 @@ export default function Post({ data }: { data: NoticeShopItem }) {
152167
)}
153168
</div>
154169
</div>
155-
</div>
170+
</button>
156171
);
157172
}

src/pages/store/StoreForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default function StoreForm() {
104104
const handleModalConfirm = useCallback(() => {
105105
if (modal.message === '등록이 완료되었습니다.') {
106106
setModal({ isOpen: false, message: '' });
107-
navigate(`/owner/post/${noticeId.current}`);
107+
navigate(`/owner/post/${shopId.current}/${noticeId.current}`);
108108
} else if (modal.message.includes('로그인')) {
109109
setModal({ isOpen: false, message: '' });
110110
navigate('/login');

0 commit comments

Comments
 (0)