Skip to content

Commit 3bd6c3e

Browse files
authored
Merge pull request #203 from TEAM-BeautiFlow/mido
Mido
2 parents 0ecc551 + 8b3d338 commit 3bd6c3e

2 files changed

Lines changed: 67 additions & 32 deletions

File tree

src/pages/Manager/Home/AboutReservationPage.tsx

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ function StatusModal({
9494
export default function AboutReservationPage({
9595
onBack,
9696
onStatusChange,
97-
onChat,
9897
}: ReservationDetailPageProps = {}) {
9998
const navigate = useNavigate();
10099
const params = useParams();
@@ -285,36 +284,6 @@ export default function AboutReservationPage({
285284
</span>
286285
</div>
287286
</div>
288-
<button
289-
onClick={onChat}
290-
className="flex items-center space-x-2 rounded-lg bg-[#3a3a3a] py-[6px] pr-2 pl-3"
291-
>
292-
<span className="body1 text-[#bdbebd]">채팅</span>
293-
<svg
294-
width="16"
295-
height="16"
296-
viewBox="0 0 16 16"
297-
fill="none"
298-
xmlns="http://www.w3.org/2000/svg"
299-
>
300-
<g clip-path="url(#clip0_3562_10626)">
301-
<path
302-
d="M3.21379 2.72888C3.5142 2.68275 3.76174 2.76777 3.85246 2.7992C3.9815 2.84392 4.12899 2.9104 4.24211 2.96131L12.6005 6.72302C12.7109 6.77268 12.8567 6.83739 12.9745 6.90369C13.0711 6.95803 13.3491 7.11707 13.5116 7.44568C13.6843 7.79484 13.6843 8.20492 13.5116 8.55408C13.3491 8.88257 13.071 9.04175 12.9745 9.09607C12.8567 9.16237 12.7108 9.22709 12.6005 9.27673L4.24504 13.0365C4.13147 13.0876 3.98366 13.1548 3.85441 13.1996C3.75089 13.2355 3.44173 13.3417 3.08293 13.2416C2.70427 13.1359 2.39771 12.8578 2.2548 12.4916C2.11947 12.1447 2.19327 11.8268 2.21867 11.7201C2.25033 11.5871 2.30316 11.4339 2.34269 11.3158L3.44621 8.01697L2.33879 4.67908C2.29972 4.56138 2.24702 4.4086 2.21574 4.27576C2.19062 4.16897 2.11815 3.85133 2.25383 3.50525C2.39719 3.13971 2.7037 2.86252 3.08195 2.7572L3.21379 2.72888ZM3.49992 7.24939V8.74939H6.99992C7.41413 8.74939 7.74992 8.4136 7.74992 7.99939C7.74975 7.58533 7.41403 7.24939 6.99992 7.24939H3.49992Z"
303-
fill="#BDBEBD"
304-
/>
305-
</g>
306-
<defs>
307-
<clipPath id="clip0_3562_10626">
308-
<rect
309-
width="12"
310-
height="12"
311-
fill="white"
312-
transform="translate(2 2)"
313-
/>
314-
</clipPath>
315-
</defs>
316-
</svg>
317-
</button>
318287
</div>
319288

320289
{/* Customer Photos */}

src/pages/Manager/Home/TodaysFilteredReservationsPage.tsx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { useMemo, useState } from "react";
1+
import { useEffect, useMemo, useRef, useState } from "react";
22
import { useLocation, useNavigate } from "react-router-dom";
33
import { useQuery } from "@tanstack/react-query";
44
import Header from "@/layout/Header";
55
import ManagerNavbar from "@/layout/ManagerNavbar";
66
import RightChevronIcon from "@/assets/icon_right-chevron.svg";
77
import LeftChevronIcon from "@/assets/icon_left-chevron.svg";
88
import { getMonthlyReservations } from "@/apis/manager_home/home";
9+
import { getUserInfo } from "@/apis/mypage/mypage";
10+
import axios from "axios";
911

1012
type FilterKey = "pending" | "completed" | "cancelled";
1113

@@ -119,6 +121,67 @@ export default function TodaysFilteredReservationsPage() {
119121

120122
const fmt = (t?: string) => (t ?? "").slice(0, 5);
121123

124+
const userIdRef = useRef<number | null>(null);
125+
const shopIdRef = useRef<number | null>(null);
126+
127+
useEffect(() => {
128+
let cancelled = false;
129+
(async () => {
130+
try {
131+
const userInfo = await getUserInfo();
132+
if (!cancelled) {
133+
userIdRef.current = userInfo.id;
134+
shopIdRef.current = userInfo.shopMembers?.[0]?.shopId ?? null;
135+
if (shopIdRef.current) {
136+
localStorage.setItem("shopId", String(shopIdRef.current));
137+
}
138+
}
139+
} catch (e) {
140+
console.error("failed to load user info", e);
141+
}
142+
})();
143+
return () => {
144+
cancelled = true;
145+
};
146+
}, []);
147+
148+
// 채팅방 입장
149+
const handleCreateRoom = async (customerId: number, customerName: string) => {
150+
try {
151+
const token = localStorage.getItem("accessToken");
152+
const shopId = shopIdRef.current;
153+
const designerId = userIdRef.current;
154+
155+
if (!token || !designerId || !shopId) {
156+
console.error("정보가 부족합니다.");
157+
return;
158+
}
159+
160+
const response = await axios.post(
161+
`${import.meta.env.VITE_API_BASE_URL}/chat/rooms`,
162+
{ shopId, customerId, designerId },
163+
{ headers: { Authorization: `Bearer ${token}` } },
164+
);
165+
166+
const roomId = response.data.data.roomId;
167+
navigate(`/chat/rooms/${roomId}`, {
168+
state: {
169+
customerId,
170+
name: customerName,
171+
},
172+
});
173+
} catch (error) {
174+
if (axios.isAxiosError(error)) {
175+
console.error("채팅방 생성 실패", {
176+
message: error.message,
177+
response: error.response,
178+
status: error.response?.status,
179+
data: error.response?.data,
180+
});
181+
}
182+
}
183+
};
184+
122185
return (
123186
<div className="mx-auto min-h-screen max-w-[375px] bg-[var(--color-grey-1000)] pb-24 text-[var(--color-grey-150)]">
124187
<Header />
@@ -164,6 +227,9 @@ export default function TodaysFilteredReservationsPage() {
164227
onClick={() =>
165228
navigate(`/manager/reservations/${item.reservationId}`)
166229
}
230+
onChat={() =>
231+
handleCreateRoom(item.customerId, item.customerName)
232+
}
167233
/>
168234
))}
169235
{list.length === 0 && (

0 commit comments

Comments
 (0)