@farmzone/fz-template-react 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/create.js +10 -4
- package/package.json +8 -2
- package/template/.env.example +5 -0
- package/template/eslint.config.js +4 -1
- package/template/index.css +15 -2
- package/template/index.html +1 -1
- package/template/package.json +55 -41
- package/template/public/favicon.ico +0 -0
- package/template/public/mockServiceWorker.js +349 -0
- package/template/src/app/App.tsx +2 -0
- package/template/src/app/api/api.ts +178 -0
- package/template/src/app/api/queries.ts +321 -0
- package/template/src/app/api/queryKey.ts +7 -0
- package/template/src/app/api/token.ts +7 -0
- package/template/src/app/layout/Layout.tsx +33 -16
- package/template/src/app/layout/ListContents.tsx +9 -0
- package/template/src/app/layout/ListHeader.tsx +41 -0
- package/template/src/app/layout/MultiTabNav.tsx +101 -0
- package/template/src/app/layout/Sidebar.tsx +33 -53
- package/template/src/app/layout/UserInfo.tsx +94 -0
- package/template/src/app/layout/menu.ts +46 -21
- package/template/src/app/layout/tabSwitchStore.ts +11 -0
- package/template/src/app/router/Router.tsx +54 -28
- package/template/src/app/store/index.ts +26 -0
- package/template/src/index.tsx +21 -12
- package/template/src/mocks/browser.ts +17 -0
- package/template/src/mocks/handlers.ts +43 -0
- package/template/src/mocks/scenarios.ts +57 -0
- package/template/src/pages/dashboard/index.tsx +541 -8
- package/template/src/pages/error/Error.tsx +29 -17
- package/template/src/pages/error/NotFound.tsx +27 -17
- package/template/src/pages/login/index.tsx +317 -0
- package/template/src/pages/post/PostFormModal.tsx +128 -0
- package/template/src/pages/post/detail/index.tsx +548 -0
- package/template/src/pages/post/index.tsx +267 -0
- package/template/src/pages/sample/SampleFormModal.tsx +77 -0
- package/template/src/pages/sample/detail/index.tsx +424 -0
- package/template/src/pages/sample/index.tsx +269 -0
- package/template/src/pages/system/log/index.tsx +173 -0
- package/template/src/pages/user/config/columns.tsx +109 -0
- package/template/src/pages/user/config/schema.ts +54 -0
- package/template/src/pages/user/index.tsx +641 -0
- package/template/src/shared/components/CommentInput.tsx +243 -0
- package/template/src/shared/components/FilePreviewCard.tsx +70 -0
- package/template/src/shared/config/text.ts +27 -0
- package/template/src/shared/config/type.ts +40 -0
- package/template/src/shared/utils/format.ts +11 -0
- package/template/src/types/auth.ts +10 -0
- package/template/src/types/comment.ts +33 -0
- package/template/src/types/common.ts +19 -0
- package/template/src/types/dashboard.ts +53 -0
- package/template/src/types/index.ts +16 -0
- package/template/src/types/log.ts +21 -0
- package/template/src/types/post.ts +32 -0
- package/template/src/types/sample.ts +28 -0
- package/template/src/types/user.ts +51 -0
- package/template/src/vite-env.d.ts +10 -0
- package/template/gitignore +0 -32
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useNavigate, useParams } from "react-router";
|
|
3
|
+
import { Badge, Button, confirmModal, toast } from "@farmzone/fz-react-ui";
|
|
4
|
+
import { CornerDownRight, Pencil, Trash2 } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
useDeleteComment,
|
|
8
|
+
useDeleteSample,
|
|
9
|
+
useGetComments,
|
|
10
|
+
useGetSample,
|
|
11
|
+
usePutComment,
|
|
12
|
+
usePutSample,
|
|
13
|
+
} from "@/app/api/queries";
|
|
14
|
+
import { useUserStore } from "@/app/store";
|
|
15
|
+
import type { Comment } from "@/types";
|
|
16
|
+
import ListHeader from "@/app/layout/ListHeader";
|
|
17
|
+
import CommentInput from "@/shared/components/CommentInput";
|
|
18
|
+
import { formatDateTime } from "@/shared/utils/format";
|
|
19
|
+
import ListContents from "@/app/layout/ListContents";
|
|
20
|
+
import { SampleFormModal } from "../SampleFormModal";
|
|
21
|
+
import type { SampleFormData } from "../SampleFormModal";
|
|
22
|
+
|
|
23
|
+
function countComments(list: Array<Comment>): number {
|
|
24
|
+
return list.reduce((sum, c) => {
|
|
25
|
+
const depth2 = c.replies ?? [];
|
|
26
|
+
const depth3Count = depth2.reduce((s, r) => s + (r.replies?.length ?? 0), 0);
|
|
27
|
+
return sum + 1 + depth2.length + depth3Count;
|
|
28
|
+
}, 0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function SampleDetailPage() {
|
|
32
|
+
const { id } = useParams<{ id: string }>();
|
|
33
|
+
const sampleId = Number(id);
|
|
34
|
+
const navigate = useNavigate();
|
|
35
|
+
const currentUser = useUserStore((s) => s.user);
|
|
36
|
+
|
|
37
|
+
const [isEditOpen, setIsEditOpen] = useState(false);
|
|
38
|
+
const [replyingToId, setReplyingToId] = useState<number | null>(null);
|
|
39
|
+
const [editingCommentId, setEditingCommentId] = useState<number | null>(null);
|
|
40
|
+
|
|
41
|
+
const { data: sample, isLoading } = useGetSample(sampleId);
|
|
42
|
+
const { data: comments = [] } = useGetComments("SAMPLE", sampleId);
|
|
43
|
+
const { mutateAsync: putSample, isPending: isUpdating } = usePutSample();
|
|
44
|
+
const { mutateAsync: deleteSample } = useDeleteSample();
|
|
45
|
+
const { mutateAsync: deleteComment } = useDeleteComment();
|
|
46
|
+
const { mutateAsync: putComment, isPending: isCommentUpdating } = usePutComment();
|
|
47
|
+
|
|
48
|
+
const topComments = comments.filter((c) => c.parentCommentId === null);
|
|
49
|
+
const totalCommentCount = countComments(topComments);
|
|
50
|
+
|
|
51
|
+
const openEditModal = () => setIsEditOpen(true);
|
|
52
|
+
const closeEditModal = () => setIsEditOpen(false);
|
|
53
|
+
|
|
54
|
+
const handleEdit = async (data: SampleFormData) => {
|
|
55
|
+
await putSample({
|
|
56
|
+
id: sampleId,
|
|
57
|
+
data: {
|
|
58
|
+
name: data.name,
|
|
59
|
+
description: data.description,
|
|
60
|
+
category: data.category as "BASIC" | "ADVANCED",
|
|
61
|
+
active: data.active,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
closeEditModal();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleDelete = () => {
|
|
68
|
+
if (!sample) return;
|
|
69
|
+
confirmModal({
|
|
70
|
+
content: `"${sample.name}"을(를) 삭제하시겠습니까?`,
|
|
71
|
+
onOk: async () => {
|
|
72
|
+
await deleteSample(sampleId);
|
|
73
|
+
navigate("/sample");
|
|
74
|
+
},
|
|
75
|
+
onCancel: () => {},
|
|
76
|
+
className: "max-w-100",
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const isCommentOwner = (commentUserId: number | null) =>
|
|
81
|
+
commentUserId !== null && String(commentUserId) === currentUser?.id;
|
|
82
|
+
|
|
83
|
+
const handleCommentEditStart = (comment: Comment) => {
|
|
84
|
+
if (!isCommentOwner(comment.userId)) {
|
|
85
|
+
toast.error("본인의 댓글만 수정할 수 있습니다.");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
setEditingCommentId(comment.id);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const handleCommentDelete = (commentId: number, commentUserId: number | null) => {
|
|
92
|
+
if (!isCommentOwner(commentUserId)) {
|
|
93
|
+
toast.error("본인의 댓글만 삭제할 수 있습니다.");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
confirmModal({
|
|
97
|
+
content: "댓글을 삭제하시겠습니까?",
|
|
98
|
+
onOk: async () => {
|
|
99
|
+
await deleteComment(commentId);
|
|
100
|
+
},
|
|
101
|
+
onCancel: () => {},
|
|
102
|
+
className: "max-w-100",
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const handleCommentSave = async (commentId: number, content: string, mentionUserIds: Array<number>) => {
|
|
107
|
+
await putComment({
|
|
108
|
+
commentId,
|
|
109
|
+
data: { content, mentionUserIds: mentionUserIds.length > 0 ? mentionUserIds : undefined },
|
|
110
|
+
});
|
|
111
|
+
setEditingCommentId(null);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const renderCommentActions = (comment: Comment) => {
|
|
115
|
+
if (!isCommentOwner(comment.userId)) return null;
|
|
116
|
+
return (
|
|
117
|
+
<div className="flex shrink-0 items-center gap-0.5">
|
|
118
|
+
<Button
|
|
119
|
+
type="button"
|
|
120
|
+
variant="ghost"
|
|
121
|
+
size="icon-sm"
|
|
122
|
+
onClick={() => handleCommentEditStart(comment)}
|
|
123
|
+
className="cursor-pointer rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-blue-500"
|
|
124
|
+
aria-label="댓글 수정"
|
|
125
|
+
>
|
|
126
|
+
<Pencil size={14} />
|
|
127
|
+
</Button>
|
|
128
|
+
<Button
|
|
129
|
+
type="button"
|
|
130
|
+
variant="ghost"
|
|
131
|
+
size="icon-sm"
|
|
132
|
+
onClick={() => handleCommentDelete(comment.id, comment.userId)}
|
|
133
|
+
className="cursor-pointer rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-red-500"
|
|
134
|
+
aria-label="댓글 삭제"
|
|
135
|
+
>
|
|
136
|
+
<Trash2 size={14} />
|
|
137
|
+
</Button>
|
|
138
|
+
</div>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const editDefaultValues: SampleFormData | undefined = sample
|
|
143
|
+
? { name: sample.name, description: sample.description, category: sample.category, active: sample.active }
|
|
144
|
+
: undefined;
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div className="p-6">
|
|
148
|
+
<ListHeader
|
|
149
|
+
title="샘플 상세"
|
|
150
|
+
rightArea={
|
|
151
|
+
<div className="flex items-center gap-2">
|
|
152
|
+
<Button variant="outline" onClick={() => navigate("/sample")}>
|
|
153
|
+
목록
|
|
154
|
+
</Button>
|
|
155
|
+
{sample && (
|
|
156
|
+
<>
|
|
157
|
+
<Button variant="save" onClick={openEditModal}>
|
|
158
|
+
수정
|
|
159
|
+
</Button>
|
|
160
|
+
<Button variant="delete" onClick={handleDelete}>
|
|
161
|
+
삭제
|
|
162
|
+
</Button>
|
|
163
|
+
</>
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
}
|
|
167
|
+
/>
|
|
168
|
+
|
|
169
|
+
<ListContents>
|
|
170
|
+
{/* 샘플 상세 */}
|
|
171
|
+
<div className="overflow-hidden rounded-xl border border-gray-200 bg-white">
|
|
172
|
+
{isLoading ? (
|
|
173
|
+
<div className="p-8 text-center text-sm text-gray-400">불러오는 중...</div>
|
|
174
|
+
) : sample ? (
|
|
175
|
+
<>
|
|
176
|
+
<div className="border-b border-gray-100 bg-gray-50/50 px-6 py-5">
|
|
177
|
+
<h2 className="mb-3 text-xl font-bold leading-tight text-gray-900">{sample.name}</h2>
|
|
178
|
+
<div className="flex items-center gap-3 text-xs text-gray-500">
|
|
179
|
+
<Badge
|
|
180
|
+
text={sample.category === "BASIC" ? "기본" : "고급"}
|
|
181
|
+
className={`scale-90 ${
|
|
182
|
+
sample.category === "BASIC"
|
|
183
|
+
? "bg-blue-100 text-blue-700 border-blue-100"
|
|
184
|
+
: "bg-purple-100 text-purple-700 border-purple-100"
|
|
185
|
+
}`}
|
|
186
|
+
/>
|
|
187
|
+
<Badge
|
|
188
|
+
text={sample.active ? "사용" : "미사용"}
|
|
189
|
+
className={`scale-90 ${
|
|
190
|
+
sample.active
|
|
191
|
+
? "bg-green-100 text-green-700 border-green-100"
|
|
192
|
+
: "bg-red-100 text-red-500 border-red-100"
|
|
193
|
+
}`}
|
|
194
|
+
/>
|
|
195
|
+
<span className="text-gray-300">|</span>
|
|
196
|
+
<span>우선순위 {sample.priority}</span>
|
|
197
|
+
<span className="text-gray-300">|</span>
|
|
198
|
+
<span>등록일 {formatDateTime(sample.createdAt)}</span>
|
|
199
|
+
<span className="text-gray-300">|</span>
|
|
200
|
+
<span>수정일 {formatDateTime(sample.updatedAt)}</span>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
<div className="min-h-44 px-6 py-6">
|
|
205
|
+
<p className="whitespace-pre-wrap text-sm leading-7 text-gray-800">{sample.description}</p>
|
|
206
|
+
</div>
|
|
207
|
+
</>
|
|
208
|
+
) : (
|
|
209
|
+
<div className="p-8 text-center text-sm text-gray-400">샘플을 찾을 수 없습니다.</div>
|
|
210
|
+
)}
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
{/* 댓글 섹션 */}
|
|
214
|
+
<div className="rounded-xl border border-gray-200 bg-white">
|
|
215
|
+
<div className="border-b border-gray-100 px-5 py-3">
|
|
216
|
+
<h3 className="text-sm font-semibold text-gray-700">댓글 {totalCommentCount}개</h3>
|
|
217
|
+
</div>
|
|
218
|
+
|
|
219
|
+
{topComments.length > 0 ? (
|
|
220
|
+
<ul className="divide-y divide-gray-100">
|
|
221
|
+
{topComments.map((comment) => {
|
|
222
|
+
const depth2Replies = comment.replies ?? [];
|
|
223
|
+
const isReplying = replyingToId === comment.id;
|
|
224
|
+
const isEditing = editingCommentId === comment.id;
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<li key={comment.id}>
|
|
228
|
+
{/* depth 1: 원댓글 */}
|
|
229
|
+
<div className="flex items-start gap-3 px-5 py-4">
|
|
230
|
+
<div className="flex-1 space-y-1">
|
|
231
|
+
<div className="flex items-center gap-2">
|
|
232
|
+
<span className="text-sm font-semibold text-gray-800">
|
|
233
|
+
{comment.userName || "알수없음"}
|
|
234
|
+
</span>
|
|
235
|
+
<span className="text-xs text-gray-400">{formatDateTime(comment.createdAt)}</span>
|
|
236
|
+
</div>
|
|
237
|
+
{isEditing ? (
|
|
238
|
+
<CommentInput
|
|
239
|
+
initialContent={comment.content}
|
|
240
|
+
initialMentionUserIds={comment.mentionUserIds ?? []}
|
|
241
|
+
onSave={(content, mentionUserIds) =>
|
|
242
|
+
handleCommentSave(comment.id, content, mentionUserIds)
|
|
243
|
+
}
|
|
244
|
+
isSaving={isCommentUpdating}
|
|
245
|
+
saveLabel="저장"
|
|
246
|
+
onCancel={() => setEditingCommentId(null)}
|
|
247
|
+
/>
|
|
248
|
+
) : (
|
|
249
|
+
<>
|
|
250
|
+
<p className="whitespace-pre-wrap text-sm text-gray-700">{comment.content}</p>
|
|
251
|
+
{!comment.deletedAt && (
|
|
252
|
+
<button
|
|
253
|
+
type="button"
|
|
254
|
+
onClick={() => setReplyingToId(isReplying ? null : comment.id)}
|
|
255
|
+
className="mt-0.5 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-blue-500"
|
|
256
|
+
>
|
|
257
|
+
<CornerDownRight size={11} />
|
|
258
|
+
{isReplying ? "취소" : "답글"}
|
|
259
|
+
</button>
|
|
260
|
+
)}
|
|
261
|
+
</>
|
|
262
|
+
)}
|
|
263
|
+
</div>
|
|
264
|
+
{!isEditing && renderCommentActions(comment)}
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
{/* depth 2: 대댓글 목록 */}
|
|
268
|
+
{depth2Replies.length > 0 && (
|
|
269
|
+
<ul className="border-t border-gray-50 bg-gray-50/60">
|
|
270
|
+
{depth2Replies.map((reply) => {
|
|
271
|
+
const depth3Replies = reply.replies ?? [];
|
|
272
|
+
const isReplyingToReply = replyingToId === reply.id;
|
|
273
|
+
const isEditingReply = editingCommentId === reply.id;
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<li key={reply.id} className="border-b border-gray-100 last:border-0">
|
|
277
|
+
<div className="flex items-start gap-2.5 py-3 pl-10 pr-5">
|
|
278
|
+
<CornerDownRight size={13} className="mt-0.5 shrink-0 text-gray-300" />
|
|
279
|
+
<div className="flex-1 space-y-0.5">
|
|
280
|
+
<div className="flex items-center gap-2">
|
|
281
|
+
<span className="text-sm font-semibold text-gray-800">
|
|
282
|
+
{reply.userName}
|
|
283
|
+
</span>
|
|
284
|
+
<span className="text-xs text-gray-400">
|
|
285
|
+
{formatDateTime(reply.createdAt)}
|
|
286
|
+
</span>
|
|
287
|
+
</div>
|
|
288
|
+
{isEditingReply ? (
|
|
289
|
+
<CommentInput
|
|
290
|
+
initialContent={reply.content}
|
|
291
|
+
initialMentionUserIds={reply.mentionUserIds ?? []}
|
|
292
|
+
onSave={(content, mentionUserIds) =>
|
|
293
|
+
handleCommentSave(reply.id, content, mentionUserIds)
|
|
294
|
+
}
|
|
295
|
+
isSaving={isCommentUpdating}
|
|
296
|
+
saveLabel="저장"
|
|
297
|
+
onCancel={() => setEditingCommentId(null)}
|
|
298
|
+
/>
|
|
299
|
+
) : (
|
|
300
|
+
<>
|
|
301
|
+
<p className="whitespace-pre-wrap text-sm text-gray-600">
|
|
302
|
+
{reply.content}
|
|
303
|
+
</p>
|
|
304
|
+
{reply.content !== "삭제된 댓글입니다." && (
|
|
305
|
+
<button
|
|
306
|
+
type="button"
|
|
307
|
+
onClick={() => setReplyingToId(isReplyingToReply ? null : reply.id)}
|
|
308
|
+
className="mt-0.5 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-blue-500"
|
|
309
|
+
>
|
|
310
|
+
<CornerDownRight size={11} />
|
|
311
|
+
{isReplyingToReply ? "취소" : "답글"}
|
|
312
|
+
</button>
|
|
313
|
+
)}
|
|
314
|
+
</>
|
|
315
|
+
)}
|
|
316
|
+
</div>
|
|
317
|
+
{!isEditingReply && renderCommentActions(reply)}
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
{/* depth 3: 대대댓글 목록 (답글 버튼 없음) */}
|
|
321
|
+
{depth3Replies.length > 0 && (
|
|
322
|
+
<ul className="bg-gray-100/50">
|
|
323
|
+
{depth3Replies.map((deepReply) => {
|
|
324
|
+
const isEditingDeepReply = editingCommentId === deepReply.id;
|
|
325
|
+
return (
|
|
326
|
+
<li
|
|
327
|
+
key={deepReply.id}
|
|
328
|
+
className="flex items-start gap-2.5 border-b border-gray-100 py-3 pl-16 pr-5 last:border-0"
|
|
329
|
+
>
|
|
330
|
+
<CornerDownRight
|
|
331
|
+
size={13}
|
|
332
|
+
className="mt-0.5 shrink-0 text-gray-200"
|
|
333
|
+
/>
|
|
334
|
+
<div className="flex-1 space-y-0.5">
|
|
335
|
+
<div className="flex items-center gap-2">
|
|
336
|
+
<span className="text-sm font-semibold text-gray-800">
|
|
337
|
+
{deepReply.userName}
|
|
338
|
+
</span>
|
|
339
|
+
<span className="text-xs text-gray-400">
|
|
340
|
+
{formatDateTime(deepReply.createdAt)}
|
|
341
|
+
</span>
|
|
342
|
+
</div>
|
|
343
|
+
{isEditingDeepReply ? (
|
|
344
|
+
<CommentInput
|
|
345
|
+
initialContent={deepReply.content}
|
|
346
|
+
initialMentionUserIds={deepReply.mentionUserIds ?? []}
|
|
347
|
+
onSave={(content, mentionUserIds) =>
|
|
348
|
+
handleCommentSave(deepReply.id, content, mentionUserIds)
|
|
349
|
+
}
|
|
350
|
+
isSaving={isCommentUpdating}
|
|
351
|
+
saveLabel="저장"
|
|
352
|
+
onCancel={() => setEditingCommentId(null)}
|
|
353
|
+
/>
|
|
354
|
+
) : (
|
|
355
|
+
<p className="whitespace-pre-wrap text-sm text-gray-600">
|
|
356
|
+
{deepReply.content}
|
|
357
|
+
</p>
|
|
358
|
+
)}
|
|
359
|
+
</div>
|
|
360
|
+
{!isEditingDeepReply && renderCommentActions(deepReply)}
|
|
361
|
+
</li>
|
|
362
|
+
);
|
|
363
|
+
})}
|
|
364
|
+
</ul>
|
|
365
|
+
)}
|
|
366
|
+
|
|
367
|
+
{/* depth 2 답글 입력창 */}
|
|
368
|
+
{isReplyingToReply && !isEditingReply && (
|
|
369
|
+
<div className="border-t border-blue-50 bg-blue-50/30 py-3 pl-10 pr-5">
|
|
370
|
+
<CommentInput
|
|
371
|
+
targetType="SAMPLE"
|
|
372
|
+
targetId={sampleId}
|
|
373
|
+
parentCommentId={reply.id}
|
|
374
|
+
placeholder="답글을 입력하세요. @를 입력하면 사용자를 멘션할 수 있습니다."
|
|
375
|
+
onSuccess={() => setReplyingToId(null)}
|
|
376
|
+
/>
|
|
377
|
+
</div>
|
|
378
|
+
)}
|
|
379
|
+
</li>
|
|
380
|
+
);
|
|
381
|
+
})}
|
|
382
|
+
</ul>
|
|
383
|
+
)}
|
|
384
|
+
|
|
385
|
+
{/* depth 1 답글 입력창 */}
|
|
386
|
+
{isReplying && !isEditing && (
|
|
387
|
+
<div className="border-t border-blue-50 bg-blue-50/30 py-3 pl-10 pr-5">
|
|
388
|
+
<CommentInput
|
|
389
|
+
targetType="SAMPLE"
|
|
390
|
+
targetId={sampleId}
|
|
391
|
+
parentCommentId={comment.id}
|
|
392
|
+
placeholder="답글을 입력하세요. @를 입력하면 사용자를 멘션할 수 있습니다."
|
|
393
|
+
onSuccess={() => setReplyingToId(null)}
|
|
394
|
+
/>
|
|
395
|
+
</div>
|
|
396
|
+
)}
|
|
397
|
+
</li>
|
|
398
|
+
);
|
|
399
|
+
})}
|
|
400
|
+
</ul>
|
|
401
|
+
) : (
|
|
402
|
+
<div className="px-5 py-6 text-center text-sm text-gray-400">등록된 댓글이 없습니다.</div>
|
|
403
|
+
)}
|
|
404
|
+
|
|
405
|
+
{/* 최상위 댓글 입력창 */}
|
|
406
|
+
<div className="border-t border-gray-100 px-5 py-4">
|
|
407
|
+
<CommentInput targetType="SAMPLE" targetId={sampleId} parentCommentId={null} />
|
|
408
|
+
</div>
|
|
409
|
+
</div>
|
|
410
|
+
</ListContents>
|
|
411
|
+
|
|
412
|
+
{/* 수정 모달 */}
|
|
413
|
+
<SampleFormModal
|
|
414
|
+
mode="edit"
|
|
415
|
+
isOpen={isEditOpen}
|
|
416
|
+
onClose={closeEditModal}
|
|
417
|
+
defaultValues={editDefaultValues}
|
|
418
|
+
onSubmit={handleEdit}
|
|
419
|
+
isPending={isUpdating}
|
|
420
|
+
formKey={sampleId}
|
|
421
|
+
/>
|
|
422
|
+
</div>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useNavigate } from "react-router";
|
|
3
|
+
import { Badge, Button, confirmModal, PageFilter, Select, Table } from "@farmzone/fz-react-ui";
|
|
4
|
+
|
|
5
|
+
import { useDeleteSamples, useGetSamples, usePostSample, usePutSample } from "@/app/api/queries";
|
|
6
|
+
import type { Sample } from "@/types";
|
|
7
|
+
import ListContents from "@/app/layout/ListContents";
|
|
8
|
+
import ListHeader from "@/app/layout/ListHeader";
|
|
9
|
+
import { formatDateTime } from "@/shared/utils/format";
|
|
10
|
+
import { SampleFormModal, SAMPLE_FORM_DEFAULT_VALUES } from "./SampleFormModal";
|
|
11
|
+
import type { SampleFormData } from "./SampleFormModal";
|
|
12
|
+
|
|
13
|
+
const PAGE_SIZE_OPTIONS = [
|
|
14
|
+
{ label: "15", value: "15" },
|
|
15
|
+
{ label: "30", value: "30" },
|
|
16
|
+
{ label: "60", value: "60" },
|
|
17
|
+
{ label: "100", value: "100" },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
interface SampleFilterParams {
|
|
21
|
+
name: string;
|
|
22
|
+
category: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const FILTER_RESET: SampleFilterParams = { name: "", category: "" };
|
|
26
|
+
|
|
27
|
+
const CATEGORY_FILTER_OPTIONS = [
|
|
28
|
+
{ label: "기본", value: "BASIC" },
|
|
29
|
+
{ label: "고급", value: "PREMIUM" },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export default function SamplePage() {
|
|
33
|
+
const navigate = useNavigate();
|
|
34
|
+
const [page, setPage] = useState(0);
|
|
35
|
+
const [pageSize, setPageSize] = useState(15);
|
|
36
|
+
const [filterParams, setFilterParams] = useState<SampleFilterParams>(FILTER_RESET);
|
|
37
|
+
const [submittedFilter, setSubmittedFilter] = useState<SampleFilterParams>(FILTER_RESET);
|
|
38
|
+
|
|
39
|
+
const [modalMode, setModalMode] = useState<"create" | "edit" | null>(null);
|
|
40
|
+
const [selectedSample, setSelectedSample] = useState<Sample | null>(null);
|
|
41
|
+
const [editDefaultValues, setEditDefaultValues] = useState<SampleFormData | undefined>(undefined);
|
|
42
|
+
const [selectedKeys, setSelectedKeys] = useState<Array<string | number>>([]);
|
|
43
|
+
const [sortOption, setSortOption] = useState<{ sortKey: string; sortOrder: "asc" | "desc" } | undefined>(
|
|
44
|
+
undefined,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const { data, isLoading } = useGetSamples({
|
|
48
|
+
page,
|
|
49
|
+
size: pageSize,
|
|
50
|
+
name: submittedFilter.name || undefined,
|
|
51
|
+
category: submittedFilter.category || undefined,
|
|
52
|
+
sortKey: sortOption?.sortKey,
|
|
53
|
+
sortOrder: sortOption?.sortOrder,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const { mutateAsync: postSample, isPending: isCreating } = usePostSample();
|
|
57
|
+
const { mutateAsync: putSample, isPending: isUpdating } = usePutSample();
|
|
58
|
+
const { mutateAsync: deleteSamples } = useDeleteSamples();
|
|
59
|
+
|
|
60
|
+
const totalElements = data?.totalElements ?? 0;
|
|
61
|
+
const totalPages = data?.totalPages ?? 0;
|
|
62
|
+
const content = data?.content ?? [];
|
|
63
|
+
|
|
64
|
+
const openCreate = () => {
|
|
65
|
+
setEditDefaultValues(undefined);
|
|
66
|
+
setSelectedSample(null);
|
|
67
|
+
setModalMode("create");
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const closeModal = () => {
|
|
71
|
+
setModalMode(null);
|
|
72
|
+
setSelectedSample(null);
|
|
73
|
+
setEditDefaultValues(undefined);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleSubmit = async (data: SampleFormData) => {
|
|
77
|
+
if (modalMode === "create") {
|
|
78
|
+
await postSample({
|
|
79
|
+
name: data.name,
|
|
80
|
+
description: data.description,
|
|
81
|
+
category: data.category as "BASIC" | "ADVANCED",
|
|
82
|
+
active: data.active,
|
|
83
|
+
});
|
|
84
|
+
} else if (modalMode === "edit" && selectedSample) {
|
|
85
|
+
await putSample({
|
|
86
|
+
id: selectedSample.id,
|
|
87
|
+
data: {
|
|
88
|
+
name: data.name,
|
|
89
|
+
description: data.description,
|
|
90
|
+
category: data.category as "BASIC" | "ADVANCED",
|
|
91
|
+
active: data.active,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
closeModal();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const columns = [
|
|
99
|
+
{
|
|
100
|
+
key: "index",
|
|
101
|
+
title: "No",
|
|
102
|
+
width: "30px",
|
|
103
|
+
align: "center" as const,
|
|
104
|
+
render: (_: unknown, __: unknown, index: number) => totalElements - page * pageSize - index,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: "name",
|
|
108
|
+
title: "이름",
|
|
109
|
+
sortable: true,
|
|
110
|
+
sort: sortOption?.sortKey === "name" ? sortOption.sortOrder : null,
|
|
111
|
+
},
|
|
112
|
+
{ key: "description", title: "설명", minWidth: 200 },
|
|
113
|
+
{
|
|
114
|
+
key: "category",
|
|
115
|
+
title: "카테고리",
|
|
116
|
+
align: "center" as const,
|
|
117
|
+
width: "40px",
|
|
118
|
+
render: (_: unknown, record: Sample) => (
|
|
119
|
+
<Badge
|
|
120
|
+
text={record.category === "BASIC" ? "기본" : "고급"}
|
|
121
|
+
className={`scale-90 ${record.category === "BASIC" ? "bg-blue-100 text-blue-700 border-blue-100" : "bg-purple-100 text-purple-700 border-purple-100"}`}
|
|
122
|
+
/>
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
key: "priority",
|
|
127
|
+
title: "우선순위",
|
|
128
|
+
align: "center" as const,
|
|
129
|
+
width: "30px",
|
|
130
|
+
render: (_: unknown, record: Sample) => (
|
|
131
|
+
<span className="text-sm font-medium text-gray-700">{record.priority}</span>
|
|
132
|
+
),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
key: "active",
|
|
136
|
+
title: "사용여부",
|
|
137
|
+
align: "center" as const,
|
|
138
|
+
width: "30px",
|
|
139
|
+
render: (_: unknown, record: Sample) => (
|
|
140
|
+
<Badge
|
|
141
|
+
text={record.active ? "O" : "X"}
|
|
142
|
+
className={`scale-90 ${record.active ? "bg-green-100 text-green-700 border-green-100" : "bg-red-100 text-red-500 border-red-100"}`}
|
|
143
|
+
/>
|
|
144
|
+
),
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
key: "createdAt",
|
|
148
|
+
title: "등록일시",
|
|
149
|
+
align: "center" as const,
|
|
150
|
+
width: "80px",
|
|
151
|
+
render: (_: unknown, record: Sample) => formatDateTime(record.createdAt),
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div className="p-6">
|
|
157
|
+
<ListHeader
|
|
158
|
+
title="샘플 관리"
|
|
159
|
+
rightArea={
|
|
160
|
+
<div className="flex items-center gap-2">
|
|
161
|
+
<Button variant="save" onClick={openCreate}>
|
|
162
|
+
등록
|
|
163
|
+
</Button>
|
|
164
|
+
<Button
|
|
165
|
+
variant="delete"
|
|
166
|
+
disabled={selectedKeys.length === 0}
|
|
167
|
+
onClick={() => {
|
|
168
|
+
confirmModal({
|
|
169
|
+
content: `선택한 ${selectedKeys.length}개 항목을 삭제하시겠습니까?`,
|
|
170
|
+
onOk: async () => {
|
|
171
|
+
await deleteSamples(selectedKeys.map(Number));
|
|
172
|
+
setSelectedKeys([]);
|
|
173
|
+
},
|
|
174
|
+
onCancel: () => {},
|
|
175
|
+
className: "max-w-100",
|
|
176
|
+
});
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
삭제
|
|
180
|
+
</Button>
|
|
181
|
+
</div>
|
|
182
|
+
}
|
|
183
|
+
/>
|
|
184
|
+
<ListContents>
|
|
185
|
+
<PageFilter
|
|
186
|
+
values={filterParams}
|
|
187
|
+
onChange={(updates: Partial<SampleFilterParams>) =>
|
|
188
|
+
setFilterParams((prev) => ({ ...prev, ...updates }))
|
|
189
|
+
}
|
|
190
|
+
onSubmit={() => {
|
|
191
|
+
setPage(0);
|
|
192
|
+
setSelectedKeys([]);
|
|
193
|
+
setSubmittedFilter(filterParams);
|
|
194
|
+
}}
|
|
195
|
+
onReset={() => {
|
|
196
|
+
setFilterParams(FILTER_RESET);
|
|
197
|
+
setSubmittedFilter(FILTER_RESET);
|
|
198
|
+
setPage(0);
|
|
199
|
+
setPageSize(15);
|
|
200
|
+
setSelectedKeys([]);
|
|
201
|
+
}}
|
|
202
|
+
rows={[
|
|
203
|
+
{
|
|
204
|
+
options: [
|
|
205
|
+
{ type: "select", key: "category", label: "카테고리", options: CATEGORY_FILTER_OPTIONS },
|
|
206
|
+
{ type: "input", key: "name", label: "이름", placeholder: "이름 검색" },
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
]}
|
|
210
|
+
/>
|
|
211
|
+
<Table
|
|
212
|
+
rowKey="id"
|
|
213
|
+
columns={columns}
|
|
214
|
+
data={content}
|
|
215
|
+
isLoading={isLoading}
|
|
216
|
+
sortOption={sortOption}
|
|
217
|
+
onSortChange={(sortKey: string, sortOrder: "asc" | "desc") => {
|
|
218
|
+
setSortOption({ sortKey, sortOrder });
|
|
219
|
+
setPage(0);
|
|
220
|
+
}}
|
|
221
|
+
onRowClick={(record: Sample) => navigate(`/sample/${record.id}`)}
|
|
222
|
+
paginationInfo={{
|
|
223
|
+
page,
|
|
224
|
+
totalPages,
|
|
225
|
+
onPageChange: (newPage: number) => {
|
|
226
|
+
setPage(newPage);
|
|
227
|
+
setSelectedKeys([]);
|
|
228
|
+
},
|
|
229
|
+
}}
|
|
230
|
+
checkboxInfo={{
|
|
231
|
+
selectedKeys,
|
|
232
|
+
onSelectionChange: setSelectedKeys,
|
|
233
|
+
}}
|
|
234
|
+
renderFooter={{
|
|
235
|
+
renderLeft: (
|
|
236
|
+
<p className="text-sm text-gray-600">
|
|
237
|
+
총 <span className="font-semibold text-gray-900">{totalElements}</span>건
|
|
238
|
+
</p>
|
|
239
|
+
),
|
|
240
|
+
renderRight: (
|
|
241
|
+
<div className="flex items-center gap-2.5 pr-5">
|
|
242
|
+
<p className="text-sm font-medium text-gray-700">페이지 개수</p>
|
|
243
|
+
<Select
|
|
244
|
+
value={String(pageSize)}
|
|
245
|
+
options={PAGE_SIZE_OPTIONS}
|
|
246
|
+
onChange={(val: string) => {
|
|
247
|
+
setPageSize(Number(val));
|
|
248
|
+
setPage(0);
|
|
249
|
+
setSelectedKeys([]);
|
|
250
|
+
}}
|
|
251
|
+
/>
|
|
252
|
+
</div>
|
|
253
|
+
),
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
256
|
+
</ListContents>
|
|
257
|
+
|
|
258
|
+
<SampleFormModal
|
|
259
|
+
mode={modalMode ?? "create"}
|
|
260
|
+
isOpen={modalMode !== null}
|
|
261
|
+
onClose={closeModal}
|
|
262
|
+
defaultValues={editDefaultValues ?? SAMPLE_FORM_DEFAULT_VALUES}
|
|
263
|
+
onSubmit={handleSubmit}
|
|
264
|
+
isPending={isCreating || isUpdating}
|
|
265
|
+
formKey={selectedSample?.id}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
}
|