Skip to content

Commit 1e985bc

Browse files
authored
Merge pull request #206 from Podo-Store/feat/admin-able-to-change-script-info
Feat/admin able to change script info
2 parents aabb236 + c4d5bf0 commit 1e985bc

File tree

6 files changed

+131
-52
lines changed

6 files changed

+131
-52
lines changed

src/App.jsx

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import PerformanceInfo from "./pages/myPage/PerformanceInfo";
2525
import PerformanceRefund from "./pages/myPage/PerformanceRefund";
2626
import ScriptManage from "./pages/myPage/ScriptManage";
2727

28-
//Ver 1.1.0
28+
//Ver 1.1.0
2929
import ScriptManageDetail from "./pages/myPage/ScriptManageDetail";
3030

3131
//Ver 2.2.0
@@ -56,6 +56,9 @@ function App() {
5656
<AuthProvider>
5757
<Routes>
5858
<Route path="/" element={<DefaultLayout />}>
59+
<Route path="admin/scriptManage" element={<AdminSwitch page={0} />} />
60+
<Route path="admin/orderManage" element={<AdminSwitch page={1} />} />
61+
5962
<Route index element={<MainVer2 />} />
6063
<Route path="v1" element={<MainVer1 />} />
6164

@@ -71,21 +74,9 @@ function App() {
7174
<Route path="list" element={<List />} />
7275
<Route path="list/detail/:id" element={<Detail />} />
7376

74-
<Route
75-
path="purchase/:id"
76-
element={<ProtectedRoute element={<Purchase />} />}
77-
/>
77+
<Route path="purchase/:id" element={<ProtectedRoute element={<Purchase />} />} />
7878

7979
<Route element={<MarginLayout />}>
80-
<Route
81-
path="admin/scriptManage"
82-
element={<AdminSwitch page={0} />}
83-
/>
84-
<Route
85-
path="admin/orderManage"
86-
element={<AdminSwitch page={1} />}
87-
/>
88-
8980
<Route path="policy/:id" element={<PolicyBar />} />
9081

9182
{/*<Route path="list/detail/:id" element={<Detail />} />*/}
@@ -94,15 +85,9 @@ function App() {
9485
path="purchase/success"
9586
element={<ProtectedRoute element={<PurchaseSuccess />} />}
9687
/>
97-
<Route
98-
path="purchase/abort"
99-
element={<ProtectedRoute element={<Abort />} />}
100-
/>
88+
<Route path="purchase/abort" element={<ProtectedRoute element={<Abort />} />} />
10189
<Route path="post" element={<PostWork />} />
102-
<Route
103-
path="mypage/liked"
104-
element={<ProtectedRoute element={<LikedWorks />} />}
105-
/>
90+
<Route path="mypage/liked" element={<ProtectedRoute element={<LikedWorks />} />} />
10691
<Route
10792
path="mypage/purchased"
10893
element={<ProtectedRoute element={<PurchasedScript />} />}

src/components/admin/AdminScriptManage.tsx

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import React, { useState, useEffect } from "react";
2020

2121
import TableCellCenter from "./TableCellCenter";
2222

23+
import { toastAlert } from "@/utils/ToastAlert";
24+
2325
import { OrderStatus } from "@/types/orderStatus";
2426
import { FilterStatus } from "./types/filterStatus";
2527

@@ -28,7 +30,6 @@ import { SERVER_URL } from "@/constants/ServerURL";
2830
import DownloadSvg from "../../assets/image/component/DownloadSvg";
2931
import AcceptSvg from "../../assets/image/component/AcceptSvg";
3032
import DenySvg from "../../assets/image/component/DenySvg";
31-
import { toastAlert } from "@/utils/ToastAlert";
3233

3334
type PlayType = "LONG" | "SHORT" | null; // undefined: 선택 안함
3435

@@ -57,6 +58,10 @@ const AdminScriptManage = () => {
5758
const [page, setPage] = useState<number>(1);
5859
const [totalPages, setTotalPages] = useState<number>(1);
5960

61+
// 작품 제목 / 작가명 변경
62+
const [tempTitleMap, setTempTitleMap] = useState<Record<string, string>>({});
63+
const [tempWriterMap, setTempWriterMap] = useState<Record<string, string>>({});
64+
6065
// 전체
6166
const [totalCount, setTotalCount] = useState<number>(0);
6267
// 수락
@@ -116,6 +121,68 @@ const AdminScriptManage = () => {
116121
setPage(value);
117122
};
118123

124+
// 제목 변경
125+
const handleUpdateTitle = async (id: string) => {
126+
const newTitle = tempTitleMap[id];
127+
// 새로 입력하지 않았거나 기존 제목과 같으면 API 호출 X
128+
if (!newTitle || newTitle === data.find((item) => item.id === id)?.title) {
129+
return;
130+
}
131+
132+
toastAlert("수정사항 반영 중...", "info");
133+
try {
134+
await axios.patch(
135+
`${SERVER_URL}admin/products/title`,
136+
{
137+
productId: id,
138+
title: newTitle,
139+
},
140+
{
141+
headers: {
142+
"Content-Type": "application/json",
143+
Authorization: Cookies.get("accessToken")
144+
? `Bearer ${Cookies.get("accessToken")}`
145+
: undefined,
146+
},
147+
}
148+
);
149+
toastAlert("수정사항이 반영되었습니다.", "success");
150+
} catch (error) {
151+
toastAlert("오류가 발생했습니다. 새로고침 후 다시 시도해주세요.", "error");
152+
}
153+
};
154+
155+
// 작가명 변경
156+
const handleUpdateWriter = async (id: string) => {
157+
const newWriter = tempWriterMap[id];
158+
// 새로 입력하지 않았거나 기존 제목과 같으면 API 호출 X
159+
if (!newWriter || newWriter === data.find((item) => item.id === id)?.writer) {
160+
return;
161+
}
162+
163+
toastAlert("수정사항 반영 중...", "info");
164+
try {
165+
await axios.patch(
166+
`${SERVER_URL}admin/products/writer`,
167+
{
168+
productId: id,
169+
writer: newWriter,
170+
},
171+
{
172+
headers: {
173+
"Content-Type": "application/json",
174+
Authorization: Cookies.get("accessToken")
175+
? `Bearer ${Cookies.get("accessToken")}`
176+
: undefined,
177+
},
178+
}
179+
);
180+
toastAlert("수정사항이 반영되었습니다.", "success");
181+
} catch (error) {
182+
toastAlert("오류가 발생했습니다. 새로고침 후 다시 시도해주세요.", "error");
183+
}
184+
};
185+
119186
// 장편극 / 단편극 변경
120187
const onChangeClassification = (id: string, newClassification: PlayType) => {
121188
const updatedData = data.map((item) =>
@@ -283,8 +350,30 @@ const AdminScriptManage = () => {
283350
<TableRow key={item.id}>
284351
<TableCellCenter>{totalCount - ((page - 1) * 10 + index)}</TableCellCenter>
285352
<TableCellCenter>{item.createdAt}</TableCellCenter>
286-
<TableCellCenter>{item.title}</TableCellCenter>
287-
<TableCellCenter>{item.writer}</TableCellCenter>
353+
<TableCellCenter>
354+
<TextField
355+
variant="standard"
356+
value={tempTitleMap[item.id] ?? item.title}
357+
onChange={(event) => {
358+
setTempTitleMap((prev) => ({ ...prev, [item.id]: event.target.value }));
359+
}}
360+
onBlur={() => {
361+
handleUpdateTitle(item.id);
362+
}}
363+
></TextField>
364+
</TableCellCenter>
365+
<TableCellCenter>
366+
<TextField
367+
variant="standard"
368+
value={tempWriterMap[item.id] ?? item.writer}
369+
onChange={(event) => {
370+
setTempWriterMap((prev) => ({ ...prev, [item.id]: event.target.value }));
371+
}}
372+
onBlur={() => {
373+
handleUpdateWriter(item.id);
374+
}}
375+
></TextField>
376+
</TableCellCenter>
288377
<TableCellCenter
289378
sx={{
290379
backgroundColor:

src/index.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
body {
22
margin: 0;
3-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4-
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5-
sans-serif;
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu",
4+
"Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
65
-webkit-font-smoothing: antialiased;
76
-moz-osx-font-smoothing: grayscale;
7+
8+
overflow-x: hidden;
89
}
910

1011
code {
11-
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
12-
monospace;
12+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
1313
}
1414

1515
@font-face {

src/layouts/DefaultLayout.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.__default-layout__ {
2+
width: 100vw;
23
min-height: 100vh;
34
}

src/pages/admin/AdminSwitch.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.admin-switch {
22
margin-top: 6.481vh; /* 70px */
3+
4+
width: 66.66666666666667%;
35
}
46

57
.admin-switch .switch-bar {

src/pages/admin/AdminSwitch.tsx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@ const AdminSwitch = ({ page = 0 }) => {
99
const navigate = useNavigate();
1010

1111
return (
12-
<div className="admin-switch">
13-
<div className="d-flex switch-bar">
14-
<h1
15-
className={`h1-bold c-pointer ${page === 0 ? "c-black" : "c-grey"}`}
16-
onClick={() => {
17-
navigate("/admin/scriptManage");
18-
}}
19-
>
20-
작품 관리
21-
</h1>
22-
<h1
23-
className={`h1-bold c-pointer ${page === 1 ? "c-black" : "c-grey"}`}
24-
onClick={() => {
25-
navigate("/admin/orderManage");
26-
}}
27-
>
28-
주문 관리
29-
</h1>
30-
</div>
12+
<main className="flex flex-col items-center w-full">
13+
<div className="admin-switch">
14+
<div className="d-flex switch-bar">
15+
<h1
16+
className={`h1-bold c-pointer ${page === 0 ? "c-black" : "c-grey"}`}
17+
onClick={() => {
18+
navigate("/admin/scriptManage");
19+
}}
20+
>
21+
작품 관리
22+
</h1>
23+
<h1
24+
className={`h1-bold c-pointer ${page === 1 ? "c-black" : "c-grey"}`}
25+
onClick={() => {
26+
navigate("/admin/orderManage");
27+
}}
28+
>
29+
주문 관리
30+
</h1>
31+
</div>
3132

32-
<div style={{ padding: "20px" }}>
33-
{page === 0 ? <AdminScriptManage /> : <AdminOrderManage />}
33+
<div style={{ padding: "20px" }}>
34+
{page === 0 ? <AdminScriptManage /> : <AdminOrderManage />}
35+
</div>
3436
</div>
35-
</div>
37+
</main>
3638
);
3739
};
3840

0 commit comments

Comments
 (0)