@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.
Files changed (58) hide show
  1. package/bin/create.js +10 -4
  2. package/package.json +8 -2
  3. package/template/.env.example +5 -0
  4. package/template/eslint.config.js +4 -1
  5. package/template/index.css +15 -2
  6. package/template/index.html +1 -1
  7. package/template/package.json +55 -41
  8. package/template/public/favicon.ico +0 -0
  9. package/template/public/mockServiceWorker.js +349 -0
  10. package/template/src/app/App.tsx +2 -0
  11. package/template/src/app/api/api.ts +178 -0
  12. package/template/src/app/api/queries.ts +321 -0
  13. package/template/src/app/api/queryKey.ts +7 -0
  14. package/template/src/app/api/token.ts +7 -0
  15. package/template/src/app/layout/Layout.tsx +33 -16
  16. package/template/src/app/layout/ListContents.tsx +9 -0
  17. package/template/src/app/layout/ListHeader.tsx +41 -0
  18. package/template/src/app/layout/MultiTabNav.tsx +101 -0
  19. package/template/src/app/layout/Sidebar.tsx +33 -53
  20. package/template/src/app/layout/UserInfo.tsx +94 -0
  21. package/template/src/app/layout/menu.ts +46 -21
  22. package/template/src/app/layout/tabSwitchStore.ts +11 -0
  23. package/template/src/app/router/Router.tsx +54 -28
  24. package/template/src/app/store/index.ts +26 -0
  25. package/template/src/index.tsx +21 -12
  26. package/template/src/mocks/browser.ts +17 -0
  27. package/template/src/mocks/handlers.ts +43 -0
  28. package/template/src/mocks/scenarios.ts +57 -0
  29. package/template/src/pages/dashboard/index.tsx +541 -8
  30. package/template/src/pages/error/Error.tsx +29 -17
  31. package/template/src/pages/error/NotFound.tsx +27 -17
  32. package/template/src/pages/login/index.tsx +317 -0
  33. package/template/src/pages/post/PostFormModal.tsx +128 -0
  34. package/template/src/pages/post/detail/index.tsx +548 -0
  35. package/template/src/pages/post/index.tsx +267 -0
  36. package/template/src/pages/sample/SampleFormModal.tsx +77 -0
  37. package/template/src/pages/sample/detail/index.tsx +424 -0
  38. package/template/src/pages/sample/index.tsx +269 -0
  39. package/template/src/pages/system/log/index.tsx +173 -0
  40. package/template/src/pages/user/config/columns.tsx +109 -0
  41. package/template/src/pages/user/config/schema.ts +54 -0
  42. package/template/src/pages/user/index.tsx +641 -0
  43. package/template/src/shared/components/CommentInput.tsx +243 -0
  44. package/template/src/shared/components/FilePreviewCard.tsx +70 -0
  45. package/template/src/shared/config/text.ts +27 -0
  46. package/template/src/shared/config/type.ts +40 -0
  47. package/template/src/shared/utils/format.ts +11 -0
  48. package/template/src/types/auth.ts +10 -0
  49. package/template/src/types/comment.ts +33 -0
  50. package/template/src/types/common.ts +19 -0
  51. package/template/src/types/dashboard.ts +53 -0
  52. package/template/src/types/index.ts +16 -0
  53. package/template/src/types/log.ts +21 -0
  54. package/template/src/types/post.ts +32 -0
  55. package/template/src/types/sample.ts +28 -0
  56. package/template/src/types/user.ts +51 -0
  57. package/template/src/vite-env.d.ts +10 -0
  58. package/template/gitignore +0 -32
@@ -0,0 +1,267 @@
1
+ import { useState } from "react";
2
+ import { useNavigate } from "react-router";
3
+ import { useQueryClient } from "@tanstack/react-query";
4
+ import { Badge, Button, confirmModal, PageFilter, Select, Table, toast } from "@farmzone/fz-react-ui";
5
+
6
+ import { useGetPosts, useDeletePosts } from "@/app/api/queries";
7
+ import type { Post } from "@/types";
8
+ import { useUserStore } from "@/app/store";
9
+ import { apiFormDataInstance } from "@/app/api/api";
10
+ import { POST_QUERY_KEY } from "@/app/api/queryKey";
11
+ import ListContents from "@/app/layout/ListContents";
12
+ import ListHeader from "@/app/layout/ListHeader";
13
+ import { COMMON_MESSAGES } from "@/shared/config/text";
14
+ import { formatDateTime } from "@/shared/utils/format";
15
+ import { PostFormModal, POST_FORM_DEFAULT_VALUES } from "./PostFormModal";
16
+ import type { PostFormData } from "./PostFormModal";
17
+
18
+ const PAGE_SIZE_OPTIONS = [
19
+ { label: "15", value: "15" },
20
+ { label: "30", value: "30" },
21
+ { label: "60", value: "60" },
22
+ { label: "100", value: "100" },
23
+ ];
24
+
25
+ interface PostFilterParams {
26
+ title: string;
27
+ noticeCategory: string;
28
+ }
29
+
30
+ const EMPTY_FILTER: PostFilterParams = { title: "", noticeCategory: "" };
31
+
32
+ const FILTER_CATEGORY_OPTIONS = [
33
+ { label: "일반", value: "BASIC" },
34
+ { label: "공지", value: "NOTICE" },
35
+ ];
36
+
37
+ export default function PostPage() {
38
+ const navigate = useNavigate();
39
+ const queryClient = useQueryClient();
40
+ const currentUser = useUserStore((s) => s.user);
41
+ const [page, setPage] = useState(0);
42
+ const [pageSize, setPageSize] = useState(15);
43
+ const [filterParams, setFilterParams] = useState<PostFilterParams>(EMPTY_FILTER);
44
+ const [submittedFilter, setSubmittedFilter] = useState<PostFilterParams>(EMPTY_FILTER);
45
+ const [isCreateOpen, setIsCreateOpen] = useState(false);
46
+ const [pendingFiles, setPendingFiles] = useState<Array<File>>([]);
47
+ const [isUploading, setIsUploading] = useState(false);
48
+ const [sortOption, setSortOption] = useState<{ sortKey: string; sortOrder: "asc" | "desc" } | undefined>(
49
+ undefined,
50
+ );
51
+
52
+ const { data, isLoading } = useGetPosts({
53
+ page,
54
+ size: pageSize,
55
+ title: submittedFilter.title || undefined,
56
+ noticeCategory: submittedFilter.noticeCategory || undefined,
57
+ sortKey: sortOption?.sortKey,
58
+ sortOrder: sortOption?.sortOrder,
59
+ });
60
+
61
+ const columns = [
62
+ {
63
+ key: "id",
64
+ title: "No",
65
+ width: "30px",
66
+ align: "center" as const,
67
+ render: (_: unknown, record: Post) => record.id,
68
+ },
69
+ {
70
+ key: "title",
71
+ title: "제목",
72
+ minWidth: 200,
73
+ sortable: true,
74
+ sort: (sortOption?.sortKey === "title" ? sortOption.sortOrder : null) as "asc" | "desc" | null,
75
+ },
76
+ {
77
+ key: "visible",
78
+ title: "노출 여부",
79
+ align: "center" as const,
80
+ width: "40px",
81
+ render: (_: unknown, record: Post) => (
82
+ <Badge
83
+ text={record.visible ? "O" : "X"}
84
+ className={`scale-90 ${record.visible ? "bg-green-100 text-green-700 border-green-100" : "bg-red-100 text-red-500 border-red-100"}`}
85
+ />
86
+ ),
87
+ },
88
+ {
89
+ key: "viewCount",
90
+ title: "조회수",
91
+ align: "center" as const,
92
+ width: "40px",
93
+ },
94
+ {
95
+ key: "createdAt",
96
+ title: "등록일시",
97
+ align: "center" as const,
98
+ width: "80px",
99
+ render: (_: unknown, record: Post) => formatDateTime(record.createdAt),
100
+ },
101
+ {
102
+ key: "updatedAt",
103
+ title: "수정일시",
104
+ align: "center" as const,
105
+ width: "80px",
106
+ render: (_: unknown, record: Post) => formatDateTime(record.updatedAt),
107
+ },
108
+ ];
109
+
110
+ const [selectedKeys, setSelectedKeys] = useState<Array<string | number>>([]);
111
+
112
+ const { mutateAsync: deletePosts } = useDeletePosts();
113
+
114
+ const totalElements = data?.totalElements ?? 0;
115
+ const totalPages = data?.totalPages ?? 0;
116
+ const content = data?.content ?? [];
117
+
118
+ const closeCreateModal = () => {
119
+ setIsCreateOpen(false);
120
+ setPendingFiles([]);
121
+ };
122
+
123
+ const handleCreateFormSubmit = async (data: PostFormData) => {
124
+ setIsUploading(true);
125
+ try {
126
+ const request = {
127
+ title: data.title,
128
+ content: data.content,
129
+ noticeCategory: data.noticeCategory,
130
+ visible: data.visible,
131
+ writer: currentUser?.userId ?? "",
132
+ };
133
+ const formData = new FormData();
134
+ formData.append("request", JSON.stringify(request));
135
+ pendingFiles.forEach((f) => formData.append("files", f));
136
+ await apiFormDataInstance.post("/posts", formData);
137
+ toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
138
+ void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
139
+ closeCreateModal();
140
+ } finally {
141
+ setIsUploading(false);
142
+ }
143
+ };
144
+
145
+ return (
146
+ <div className="p-6">
147
+ <ListHeader
148
+ title="게시글 관리"
149
+ rightArea={
150
+ <div className="flex items-center gap-2">
151
+ <Button variant="save" onClick={() => setIsCreateOpen(true)}>
152
+ 등록
153
+ </Button>
154
+ <Button
155
+ variant="delete"
156
+ disabled={selectedKeys.length === 0}
157
+ onClick={() => {
158
+ confirmModal({
159
+ content: `선택한 ${selectedKeys.length}개 항목을 삭제하시겠습니까?`,
160
+ onOk: async () => {
161
+ await deletePosts(selectedKeys.map(Number));
162
+ setSelectedKeys([]);
163
+ },
164
+ onCancel: () => {},
165
+ className: "max-w-100",
166
+ });
167
+ }}
168
+ >
169
+ 삭제
170
+ </Button>
171
+ </div>
172
+ }
173
+ />
174
+ <ListContents>
175
+ <PageFilter
176
+ values={filterParams}
177
+ onChange={(updates: Partial<PostFilterParams>) =>
178
+ setFilterParams((prev) => ({ ...prev, ...updates }))
179
+ }
180
+ onSubmit={() => {
181
+ setPage(0);
182
+ setSelectedKeys([]);
183
+ setSubmittedFilter(filterParams);
184
+ }}
185
+ onReset={() => {
186
+ setFilterParams(EMPTY_FILTER);
187
+ setSubmittedFilter(EMPTY_FILTER);
188
+ setPage(0);
189
+ setPageSize(15);
190
+ setSelectedKeys([]);
191
+ }}
192
+ rows={[
193
+ {
194
+ options: [
195
+ {
196
+ type: "select",
197
+ key: "noticeCategory",
198
+ label: "카테고리",
199
+ placeholder: "전체",
200
+ options: FILTER_CATEGORY_OPTIONS,
201
+ },
202
+ { type: "input", key: "title", label: "제목", placeholder: "제목 검색" },
203
+ ],
204
+ },
205
+ ]}
206
+ />
207
+ <Table
208
+ columns={columns}
209
+ data={content}
210
+ isLoading={isLoading}
211
+ rowKey="id"
212
+ sortVisibleType={"hovered"}
213
+ sortOption={sortOption}
214
+ onSortChange={(sortKey: string, sortOrder: "asc" | "desc") => {
215
+ setSortOption({ sortKey, sortOrder });
216
+ setPage(0);
217
+ }}
218
+ onRowClick={(post: Post) => navigate(`/post/${post.id}`)}
219
+ paginationInfo={{
220
+ page,
221
+ totalPages,
222
+ onPageChange: (newPage: number) => {
223
+ setPage(newPage);
224
+ setSelectedKeys([]);
225
+ },
226
+ }}
227
+ checkboxInfo={{
228
+ selectedKeys,
229
+ onSelectionChange: setSelectedKeys,
230
+ }}
231
+ renderFooter={{
232
+ renderLeft: (
233
+ <p className="text-sm text-gray-600">
234
+ 총 <span className="font-semibold text-gray-900">{totalElements}</span>건
235
+ </p>
236
+ ),
237
+ renderRight: (
238
+ <div className="flex items-center gap-2.5 pr-5">
239
+ <p className="text-sm font-medium text-gray-700">페이지 개수</p>
240
+ <Select
241
+ value={String(pageSize)}
242
+ options={PAGE_SIZE_OPTIONS}
243
+ onChange={(val: string) => {
244
+ setPageSize(Number(val));
245
+ setPage(0);
246
+ setSelectedKeys([]);
247
+ }}
248
+ />
249
+ </div>
250
+ ),
251
+ }}
252
+ />
253
+ </ListContents>
254
+
255
+ <PostFormModal
256
+ mode="create"
257
+ isOpen={isCreateOpen}
258
+ onClose={closeCreateModal}
259
+ defaultValues={POST_FORM_DEFAULT_VALUES}
260
+ onSubmit={handleCreateFormSubmit}
261
+ isPending={isUploading}
262
+ pendingFiles={pendingFiles}
263
+ onPendingFilesChange={setPendingFiles}
264
+ />
265
+ </div>
266
+ );
267
+ }
@@ -0,0 +1,77 @@
1
+ import { Button, Modal, ModalBody, ModalFooter, ModalIconHeader, SubmitForm } from "@farmzone/fz-react-ui";
2
+ import { z } from "zod";
3
+
4
+ export const sampleFormSchema = z.object({
5
+ name: z.string().min(1, "이름을 입력해 주세요."),
6
+ description: z.string().min(1, "설명을 입력해 주세요."),
7
+ category: z.string(),
8
+ active: z.boolean(),
9
+ });
10
+
11
+ export type SampleFormData = z.infer<typeof sampleFormSchema>;
12
+
13
+ export const SAMPLE_FORM_DEFAULT_VALUES: SampleFormData = {
14
+ name: "",
15
+ description: "",
16
+ category: "BASIC",
17
+ active: true,
18
+ };
19
+
20
+ const CATEGORY_OPTIONS = [
21
+ { label: "기본", value: "BASIC" },
22
+ { label: "고급", value: "ADVANCED" },
23
+ ];
24
+
25
+ interface SampleFormModalProps {
26
+ mode: "create" | "edit";
27
+ isOpen: boolean;
28
+ onClose: () => void;
29
+ defaultValues?: SampleFormData;
30
+ onSubmit: (data: SampleFormData) => Promise<void>;
31
+ isPending: boolean;
32
+ formKey?: string | number;
33
+ }
34
+
35
+ export function SampleFormModal({
36
+ mode,
37
+ isOpen,
38
+ onClose,
39
+ defaultValues,
40
+ onSubmit,
41
+ isPending,
42
+ formKey,
43
+ }: SampleFormModalProps) {
44
+ const formId = mode === "create" ? "sample-create-form" : "sample-edit-form";
45
+ const title = mode === "create" ? "샘플 등록" : "샘플 수정";
46
+ const submitLabel = mode === "create" ? "등록" : "수정";
47
+
48
+ return (
49
+ <Modal isOpen={isOpen} onClose={onClose} contentClassName="max-w-3xl rounded-xl bg-white">
50
+ <ModalIconHeader type={mode} title={title} onClose={onClose} />
51
+ <ModalBody className="px-6 py-5">
52
+ <div className="overflow-hidden rounded-lg border border-gray-200">
53
+ <SubmitForm
54
+ key={formKey}
55
+ formId={formId}
56
+ schema={sampleFormSchema}
57
+ defaultValues={defaultValues ?? SAMPLE_FORM_DEFAULT_VALUES}
58
+ onSubmit={onSubmit}
59
+ >
60
+ <SubmitForm.Row formKey="name" label="이름" required maxLength={100} />
61
+ <SubmitForm.Row formKey="description" formType="textarea" label="설명" required maxLength={500} />
62
+ <SubmitForm.Row formKey="category" formType="radio" label="카테고리" options={CATEGORY_OPTIONS} />
63
+ <SubmitForm.Row formKey="active" formType="switch" label="사용 여부" />
64
+ </SubmitForm>
65
+ </div>
66
+ </ModalBody>
67
+ <ModalFooter className="flex justify-end gap-2 border-t border-gray-200 bg-neutral-50 px-5 py-3">
68
+ <Button type="submit" form={formId} variant="save" disabled={isPending}>
69
+ {isPending ? `${submitLabel} 중...` : submitLabel}
70
+ </Button>
71
+ <Button variant="outline" onClick={onClose}>
72
+ 취소
73
+ </Button>
74
+ </ModalFooter>
75
+ </Modal>
76
+ );
77
+ }