@farmzone/fz-template-react 1.0.3 → 1.0.4

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.
Files changed (50) hide show
  1. package/package.json +1 -1
  2. package/template/.env.example +5 -5
  3. package/template/package.json +55 -55
  4. package/template/pnpm-lock.yaml +4214 -4214
  5. package/template/public/mockServiceWorker.js +349 -349
  6. package/template/src/app/api/api.ts +178 -178
  7. package/template/src/app/api/queries.ts +321 -321
  8. package/template/src/app/api/queryKey.ts +7 -7
  9. package/template/src/app/api/token.ts +7 -7
  10. package/template/src/app/layout/Layout.tsx +33 -33
  11. package/template/src/app/layout/ListContents.tsx +9 -9
  12. package/template/src/app/layout/ListHeader.tsx +41 -41
  13. package/template/src/app/layout/MultiTabNav.tsx +101 -101
  14. package/template/src/app/layout/Sidebar.tsx +33 -33
  15. package/template/src/app/layout/UserInfo.tsx +94 -94
  16. package/template/src/app/layout/tabSwitchStore.ts +11 -11
  17. package/template/src/app/router/Router.tsx +56 -56
  18. package/template/src/app/store/index.ts +26 -26
  19. package/template/src/index.tsx +21 -21
  20. package/template/src/mocks/browser.ts +17 -17
  21. package/template/src/mocks/handlers.ts +43 -43
  22. package/template/src/mocks/scenarios.ts +57 -57
  23. package/template/src/pages/dashboard/index.tsx +541 -541
  24. package/template/src/pages/error/Error.tsx +29 -29
  25. package/template/src/pages/error/NotFound.tsx +27 -27
  26. package/template/src/pages/login/index.tsx +317 -317
  27. package/template/src/pages/post/PostFormModal.tsx +128 -128
  28. package/template/src/pages/post/detail/index.tsx +548 -548
  29. package/template/src/pages/post/index.tsx +267 -267
  30. package/template/src/pages/sample/SampleFormModal.tsx +77 -77
  31. package/template/src/pages/sample/detail/index.tsx +424 -424
  32. package/template/src/pages/sample/index.tsx +269 -269
  33. package/template/src/pages/sample/modal/index.tsx +253 -253
  34. package/template/src/pages/system/log/index.tsx +173 -173
  35. package/template/src/pages/user/config/columns.tsx +109 -109
  36. package/template/src/pages/user/config/schema.ts +54 -54
  37. package/template/src/pages/user/index.tsx +641 -641
  38. package/template/src/shared/components/CommentInput.tsx +243 -243
  39. package/template/src/shared/config/text.ts +27 -27
  40. package/template/src/shared/utils/format.ts +11 -11
  41. package/template/src/types/auth.ts +10 -10
  42. package/template/src/types/comment.ts +33 -33
  43. package/template/src/types/common.ts +19 -19
  44. package/template/src/types/dashboard.ts +53 -53
  45. package/template/src/types/index.ts +16 -16
  46. package/template/src/types/log.ts +21 -21
  47. package/template/src/types/post.ts +32 -32
  48. package/template/src/types/sample.ts +28 -28
  49. package/template/src/types/user.ts +51 -51
  50. package/template/src/vite-env.d.ts +10 -10
@@ -1,424 +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
- }
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
+ }