@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,321 +1,321 @@
1
- import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
- import { toast } from "@farmzone/fz-react-ui";
3
-
4
- import { apiInstance, apiFormDataInstance } from "@/app/api/api";
5
- import {
6
- COMMENT_QUERY_KEY,
7
- DASHBOARD_QUERY_KEY,
8
- LOG_QUERY_KEY,
9
- POST_QUERY_KEY,
10
- SAMPLE_QUERY_KEY,
11
- USER_QUERY_KEY,
12
- } from "@/app/api/queryKey";
13
- import { COMMON_MESSAGES } from "@/shared/config/text";
14
- import type {
15
- LoginResponse,
16
- PageResponse,
17
- Sample,
18
- GetSamplesParams,
19
- SampleForm,
20
- Post,
21
- GetPostsParams,
22
- PostForm,
23
- Comment,
24
- CommentForm,
25
- CommentTargetType,
26
- CommentEditForm,
27
- User,
28
- GetUsersParams,
29
- UserForm,
30
- UserEditForm,
31
- ActionLog,
32
- GetLogsParams,
33
- UserDashboardResponse,
34
- } from "@/types";
35
-
36
- // --- Auth ---
37
-
38
- export const usePostLogin = () => {
39
- return useMutation({
40
- mutationFn: (params: { userId: string; password: string }) =>
41
- apiInstance.post<LoginResponse>("/auth/login", params).then((res) => res.data),
42
- onSuccess: () => {
43
- toast.success("로그인 성공", { duration: 1500 });
44
- },
45
- });
46
- };
47
-
48
- // --- Sample ---
49
-
50
- export const useGetSamples = (params: GetSamplesParams) => {
51
- return useQuery({
52
- queryKey: [SAMPLE_QUERY_KEY, "list", params],
53
- queryFn: () => apiInstance.get<PageResponse<Sample>>("/samples", { params }).then((r) => r.data),
54
- });
55
- };
56
-
57
- export const useGetSample = (id: number | null) => {
58
- return useQuery({
59
- queryKey: [SAMPLE_QUERY_KEY, "detail", id],
60
- queryFn: () => apiInstance.get<Sample>(`/samples/${id}`).then((r) => r.data),
61
- enabled: id !== null,
62
- });
63
- };
64
-
65
- export const usePostSample = () => {
66
- const queryClient = useQueryClient();
67
- return useMutation({
68
- mutationFn: (data: SampleForm) => apiInstance.post<Sample>("/samples", data).then((r) => r.data),
69
- onSuccess: () => {
70
- void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
71
- toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
72
- },
73
- });
74
- };
75
-
76
- export const usePutSample = () => {
77
- const queryClient = useQueryClient();
78
- return useMutation({
79
- mutationFn: ({ id, data }: { id: number; data: SampleForm }) =>
80
- apiInstance.put<Sample>(`/samples/${id}`, data).then((r) => r.data),
81
- onSuccess: () => {
82
- void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
83
- toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
84
- },
85
- });
86
- };
87
-
88
- export const useDeleteSample = () => {
89
- const queryClient = useQueryClient();
90
- return useMutation({
91
- mutationFn: (id: number) => apiInstance.delete(`/samples/${id}`),
92
- onSuccess: () => {
93
- void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
94
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
95
- },
96
- });
97
- };
98
-
99
- export const useDeleteSamples = () => {
100
- const queryClient = useQueryClient();
101
- return useMutation({
102
- mutationFn: (ids: Array<number>) =>
103
- apiInstance.delete("/samples", {
104
- params: { ids },
105
- paramsSerializer: { indexes: null },
106
- }),
107
- onSuccess: () => {
108
- void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
109
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
110
- },
111
- });
112
- };
113
-
114
- // --- Post ---
115
-
116
- export const useGetPosts = (params: GetPostsParams) => {
117
- return useQuery({
118
- queryKey: [POST_QUERY_KEY, "list", params],
119
- queryFn: () => apiInstance.get<PageResponse<Post>>("/posts", { params }).then((r) => r.data),
120
- });
121
- };
122
-
123
- export const useGetPost = (id: number | null) => {
124
- return useQuery({
125
- queryKey: [POST_QUERY_KEY, "detail", id],
126
- queryFn: () => apiInstance.get<Post>(`/posts/${id}`).then((r) => r.data),
127
- enabled: id !== null,
128
- });
129
- };
130
-
131
- export const usePostPost = () => {
132
- const queryClient = useQueryClient();
133
- return useMutation({
134
- mutationFn: (data: PostForm) => apiInstance.post<Post>("/posts", data).then((r) => r.data),
135
- onSuccess: () => {
136
- void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
137
- toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
138
- },
139
- });
140
- };
141
-
142
- export const usePutPost = () => {
143
- const queryClient = useQueryClient();
144
- return useMutation({
145
- mutationFn: ({ id, data }: { id: number; data: PostForm }) =>
146
- apiInstance.put<Post>(`/posts/${id}`, data).then((r) => r.data),
147
- onSuccess: () => {
148
- void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
149
- toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
150
- },
151
- });
152
- };
153
-
154
- export const useDeletePost = () => {
155
- const queryClient = useQueryClient();
156
- return useMutation({
157
- mutationFn: (id: number) => apiInstance.delete(`/posts/${id}`),
158
- onSuccess: () => {
159
- void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
160
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
161
- },
162
- });
163
- };
164
-
165
- export const useDeletePosts = () => {
166
- const queryClient = useQueryClient();
167
- return useMutation({
168
- mutationFn: (ids: Array<number>) =>
169
- apiInstance.delete("/posts", {
170
- params: { ids },
171
- paramsSerializer: { indexes: null },
172
- }),
173
- onSuccess: () => {
174
- void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
175
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
176
- },
177
- });
178
- };
179
-
180
- // --- Comment ---
181
-
182
- export const useGetComments = (targetType: CommentTargetType, targetId: number) => {
183
- return useQuery({
184
- queryKey: [COMMENT_QUERY_KEY, targetType, targetId],
185
- queryFn: () =>
186
- apiInstance.get<Array<Comment>>("/comments", { params: { targetType, targetId } }).then((r) => r.data),
187
- });
188
- };
189
-
190
- export const usePostComment = () => {
191
- const queryClient = useQueryClient();
192
- return useMutation({
193
- mutationFn: (data: CommentForm) => apiInstance.post<Comment>("/comments", data).then((r) => r.data),
194
- onSuccess: () => {
195
- void queryClient.invalidateQueries({ queryKey: [COMMENT_QUERY_KEY] });
196
- toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
197
- },
198
- });
199
- };
200
-
201
- export const usePutComment = () => {
202
- const queryClient = useQueryClient();
203
- return useMutation({
204
- mutationFn: ({ commentId, data }: { commentId: number; data: CommentEditForm }) =>
205
- apiInstance.put<Comment>(`/comments/${commentId}`, data).then((r) => r.data),
206
- onSuccess: () => {
207
- void queryClient.invalidateQueries({ queryKey: [COMMENT_QUERY_KEY] });
208
- toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
209
- },
210
- });
211
- };
212
-
213
- export const useDeleteComment = () => {
214
- const queryClient = useQueryClient();
215
- return useMutation({
216
- mutationFn: (commentId: number) => apiInstance.delete(`/comments/${commentId}`),
217
- onSuccess: () => {
218
- void queryClient.invalidateQueries({ queryKey: [COMMENT_QUERY_KEY] });
219
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
220
- },
221
- });
222
- };
223
-
224
- // --- User ---
225
-
226
- export const checkUserIdAvailable = (userId: string): Promise<boolean> =>
227
- apiInstance.get<boolean>("/users/check/id", { params: { userId } }).then((r) => r.data);
228
-
229
- export const useGetUsers = (params: GetUsersParams) => {
230
- return useQuery({
231
- queryKey: [USER_QUERY_KEY, "list", params],
232
- queryFn: () => apiInstance.get<PageResponse<User>>("/users", { params }).then((r) => r.data),
233
- });
234
- };
235
-
236
- export const useGetUser = (id: number | null) => {
237
- return useQuery({
238
- queryKey: [USER_QUERY_KEY, "detail", id],
239
- queryFn: () => apiInstance.get<User>(`/users/${id}`).then((r) => r.data),
240
- enabled: id !== null,
241
- });
242
- };
243
-
244
- export const usePostUser = () => {
245
- const queryClient = useQueryClient();
246
- return useMutation({
247
- mutationFn: async ({ data, file }: { data: UserForm; file?: File }) => {
248
- const formData = new FormData();
249
- formData.append("request", JSON.stringify(data));
250
- if (file) formData.append("files", file);
251
- return (await apiFormDataInstance.post<User>("/users", formData)).data;
252
- },
253
- onSuccess: () => {
254
- void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
255
- toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
256
- },
257
- });
258
- };
259
-
260
- export const usePutUser = () => {
261
- const queryClient = useQueryClient();
262
- return useMutation({
263
- mutationFn: async ({ id, data, file }: { id: number; data: UserEditForm; file?: File }) => {
264
- const formData = new FormData();
265
- formData.append("request", JSON.stringify(data));
266
- if (file) formData.append("files", file);
267
- return (await apiFormDataInstance.put<User>(`/users/${id}`, formData)).data;
268
- },
269
- onSuccess: () => {
270
- void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
271
- toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
272
- },
273
- });
274
- };
275
-
276
- export const useDeleteUser = () => {
277
- const queryClient = useQueryClient();
278
- return useMutation({
279
- mutationFn: (id: number) => apiInstance.delete(`/users/${id}`),
280
- onSuccess: () => {
281
- void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
282
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
283
- },
284
- });
285
- };
286
-
287
- export const useDeleteUsers = () => {
288
- const queryClient = useQueryClient();
289
- return useMutation({
290
- mutationFn: (ids: Array<number>) =>
291
- apiInstance.delete("/users", {
292
- params: { ids },
293
- paramsSerializer: { indexes: null },
294
- }),
295
- onSuccess: () => {
296
- void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
297
- toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
298
- },
299
- });
300
- };
301
-
302
- // --- Action Log ---
303
-
304
- export const useGetLogs = (params: GetLogsParams) => {
305
- return useQuery({
306
- queryKey: [LOG_QUERY_KEY, "list", params],
307
- queryFn: () => apiInstance.get<PageResponse<ActionLog>>("/action-logs", { params }).then((r) => r.data),
308
- });
309
- };
310
-
311
- // --- Dashboard ---
312
-
313
- export const useGetUserDashboard = (period = "30d") => {
314
- return useQuery({
315
- queryKey: [DASHBOARD_QUERY_KEY, period],
316
- queryFn: () =>
317
- apiInstance
318
- .get<UserDashboardResponse>("/users/dashboard", { params: { period } })
319
- .then((r) => r.data),
320
- });
321
- };
1
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
+ import { toast } from "@farmzone/fz-react-ui";
3
+
4
+ import { apiInstance, apiFormDataInstance } from "@/app/api/api";
5
+ import {
6
+ COMMENT_QUERY_KEY,
7
+ DASHBOARD_QUERY_KEY,
8
+ LOG_QUERY_KEY,
9
+ POST_QUERY_KEY,
10
+ SAMPLE_QUERY_KEY,
11
+ USER_QUERY_KEY,
12
+ } from "@/app/api/queryKey";
13
+ import { COMMON_MESSAGES } from "@/shared/config/text";
14
+ import type {
15
+ LoginResponse,
16
+ PageResponse,
17
+ Sample,
18
+ GetSamplesParams,
19
+ SampleForm,
20
+ Post,
21
+ GetPostsParams,
22
+ PostForm,
23
+ Comment,
24
+ CommentForm,
25
+ CommentTargetType,
26
+ CommentEditForm,
27
+ User,
28
+ GetUsersParams,
29
+ UserForm,
30
+ UserEditForm,
31
+ ActionLog,
32
+ GetLogsParams,
33
+ UserDashboardResponse,
34
+ } from "@/types";
35
+
36
+ // --- Auth ---
37
+
38
+ export const usePostLogin = () => {
39
+ return useMutation({
40
+ mutationFn: (params: { userId: string; password: string }) =>
41
+ apiInstance.post<LoginResponse>("/auth/login", params).then((res) => res.data),
42
+ onSuccess: () => {
43
+ toast.success("로그인 성공", { duration: 1500 });
44
+ },
45
+ });
46
+ };
47
+
48
+ // --- Sample ---
49
+
50
+ export const useGetSamples = (params: GetSamplesParams) => {
51
+ return useQuery({
52
+ queryKey: [SAMPLE_QUERY_KEY, "list", params],
53
+ queryFn: () => apiInstance.get<PageResponse<Sample>>("/samples", { params }).then((r) => r.data),
54
+ });
55
+ };
56
+
57
+ export const useGetSample = (id: number | null) => {
58
+ return useQuery({
59
+ queryKey: [SAMPLE_QUERY_KEY, "detail", id],
60
+ queryFn: () => apiInstance.get<Sample>(`/samples/${id}`).then((r) => r.data),
61
+ enabled: id !== null,
62
+ });
63
+ };
64
+
65
+ export const usePostSample = () => {
66
+ const queryClient = useQueryClient();
67
+ return useMutation({
68
+ mutationFn: (data: SampleForm) => apiInstance.post<Sample>("/samples", data).then((r) => r.data),
69
+ onSuccess: () => {
70
+ void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
71
+ toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
72
+ },
73
+ });
74
+ };
75
+
76
+ export const usePutSample = () => {
77
+ const queryClient = useQueryClient();
78
+ return useMutation({
79
+ mutationFn: ({ id, data }: { id: number; data: SampleForm }) =>
80
+ apiInstance.put<Sample>(`/samples/${id}`, data).then((r) => r.data),
81
+ onSuccess: () => {
82
+ void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
83
+ toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
84
+ },
85
+ });
86
+ };
87
+
88
+ export const useDeleteSample = () => {
89
+ const queryClient = useQueryClient();
90
+ return useMutation({
91
+ mutationFn: (id: number) => apiInstance.delete(`/samples/${id}`),
92
+ onSuccess: () => {
93
+ void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
94
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
95
+ },
96
+ });
97
+ };
98
+
99
+ export const useDeleteSamples = () => {
100
+ const queryClient = useQueryClient();
101
+ return useMutation({
102
+ mutationFn: (ids: Array<number>) =>
103
+ apiInstance.delete("/samples", {
104
+ params: { ids },
105
+ paramsSerializer: { indexes: null },
106
+ }),
107
+ onSuccess: () => {
108
+ void queryClient.invalidateQueries({ queryKey: [SAMPLE_QUERY_KEY] });
109
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
110
+ },
111
+ });
112
+ };
113
+
114
+ // --- Post ---
115
+
116
+ export const useGetPosts = (params: GetPostsParams) => {
117
+ return useQuery({
118
+ queryKey: [POST_QUERY_KEY, "list", params],
119
+ queryFn: () => apiInstance.get<PageResponse<Post>>("/posts", { params }).then((r) => r.data),
120
+ });
121
+ };
122
+
123
+ export const useGetPost = (id: number | null) => {
124
+ return useQuery({
125
+ queryKey: [POST_QUERY_KEY, "detail", id],
126
+ queryFn: () => apiInstance.get<Post>(`/posts/${id}`).then((r) => r.data),
127
+ enabled: id !== null,
128
+ });
129
+ };
130
+
131
+ export const usePostPost = () => {
132
+ const queryClient = useQueryClient();
133
+ return useMutation({
134
+ mutationFn: (data: PostForm) => apiInstance.post<Post>("/posts", data).then((r) => r.data),
135
+ onSuccess: () => {
136
+ void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
137
+ toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
138
+ },
139
+ });
140
+ };
141
+
142
+ export const usePutPost = () => {
143
+ const queryClient = useQueryClient();
144
+ return useMutation({
145
+ mutationFn: ({ id, data }: { id: number; data: PostForm }) =>
146
+ apiInstance.put<Post>(`/posts/${id}`, data).then((r) => r.data),
147
+ onSuccess: () => {
148
+ void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
149
+ toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
150
+ },
151
+ });
152
+ };
153
+
154
+ export const useDeletePost = () => {
155
+ const queryClient = useQueryClient();
156
+ return useMutation({
157
+ mutationFn: (id: number) => apiInstance.delete(`/posts/${id}`),
158
+ onSuccess: () => {
159
+ void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
160
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
161
+ },
162
+ });
163
+ };
164
+
165
+ export const useDeletePosts = () => {
166
+ const queryClient = useQueryClient();
167
+ return useMutation({
168
+ mutationFn: (ids: Array<number>) =>
169
+ apiInstance.delete("/posts", {
170
+ params: { ids },
171
+ paramsSerializer: { indexes: null },
172
+ }),
173
+ onSuccess: () => {
174
+ void queryClient.invalidateQueries({ queryKey: [POST_QUERY_KEY] });
175
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
176
+ },
177
+ });
178
+ };
179
+
180
+ // --- Comment ---
181
+
182
+ export const useGetComments = (targetType: CommentTargetType, targetId: number) => {
183
+ return useQuery({
184
+ queryKey: [COMMENT_QUERY_KEY, targetType, targetId],
185
+ queryFn: () =>
186
+ apiInstance.get<Array<Comment>>("/comments", { params: { targetType, targetId } }).then((r) => r.data),
187
+ });
188
+ };
189
+
190
+ export const usePostComment = () => {
191
+ const queryClient = useQueryClient();
192
+ return useMutation({
193
+ mutationFn: (data: CommentForm) => apiInstance.post<Comment>("/comments", data).then((r) => r.data),
194
+ onSuccess: () => {
195
+ void queryClient.invalidateQueries({ queryKey: [COMMENT_QUERY_KEY] });
196
+ toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
197
+ },
198
+ });
199
+ };
200
+
201
+ export const usePutComment = () => {
202
+ const queryClient = useQueryClient();
203
+ return useMutation({
204
+ mutationFn: ({ commentId, data }: { commentId: number; data: CommentEditForm }) =>
205
+ apiInstance.put<Comment>(`/comments/${commentId}`, data).then((r) => r.data),
206
+ onSuccess: () => {
207
+ void queryClient.invalidateQueries({ queryKey: [COMMENT_QUERY_KEY] });
208
+ toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
209
+ },
210
+ });
211
+ };
212
+
213
+ export const useDeleteComment = () => {
214
+ const queryClient = useQueryClient();
215
+ return useMutation({
216
+ mutationFn: (commentId: number) => apiInstance.delete(`/comments/${commentId}`),
217
+ onSuccess: () => {
218
+ void queryClient.invalidateQueries({ queryKey: [COMMENT_QUERY_KEY] });
219
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
220
+ },
221
+ });
222
+ };
223
+
224
+ // --- User ---
225
+
226
+ export const checkUserIdAvailable = (userId: string): Promise<boolean> =>
227
+ apiInstance.get<boolean>("/users/check/id", { params: { userId } }).then((r) => r.data);
228
+
229
+ export const useGetUsers = (params: GetUsersParams) => {
230
+ return useQuery({
231
+ queryKey: [USER_QUERY_KEY, "list", params],
232
+ queryFn: () => apiInstance.get<PageResponse<User>>("/users", { params }).then((r) => r.data),
233
+ });
234
+ };
235
+
236
+ export const useGetUser = (id: number | null) => {
237
+ return useQuery({
238
+ queryKey: [USER_QUERY_KEY, "detail", id],
239
+ queryFn: () => apiInstance.get<User>(`/users/${id}`).then((r) => r.data),
240
+ enabled: id !== null,
241
+ });
242
+ };
243
+
244
+ export const usePostUser = () => {
245
+ const queryClient = useQueryClient();
246
+ return useMutation({
247
+ mutationFn: async ({ data, file }: { data: UserForm; file?: File }) => {
248
+ const formData = new FormData();
249
+ formData.append("request", JSON.stringify(data));
250
+ if (file) formData.append("files", file);
251
+ return (await apiFormDataInstance.post<User>("/users", formData)).data;
252
+ },
253
+ onSuccess: () => {
254
+ void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
255
+ toast.success(COMMON_MESSAGES.SAVE_SUCCESS);
256
+ },
257
+ });
258
+ };
259
+
260
+ export const usePutUser = () => {
261
+ const queryClient = useQueryClient();
262
+ return useMutation({
263
+ mutationFn: async ({ id, data, file }: { id: number; data: UserEditForm; file?: File }) => {
264
+ const formData = new FormData();
265
+ formData.append("request", JSON.stringify(data));
266
+ if (file) formData.append("files", file);
267
+ return (await apiFormDataInstance.put<User>(`/users/${id}`, formData)).data;
268
+ },
269
+ onSuccess: () => {
270
+ void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
271
+ toast.success(COMMON_MESSAGES.UPDATE_SUCCESS);
272
+ },
273
+ });
274
+ };
275
+
276
+ export const useDeleteUser = () => {
277
+ const queryClient = useQueryClient();
278
+ return useMutation({
279
+ mutationFn: (id: number) => apiInstance.delete(`/users/${id}`),
280
+ onSuccess: () => {
281
+ void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
282
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
283
+ },
284
+ });
285
+ };
286
+
287
+ export const useDeleteUsers = () => {
288
+ const queryClient = useQueryClient();
289
+ return useMutation({
290
+ mutationFn: (ids: Array<number>) =>
291
+ apiInstance.delete("/users", {
292
+ params: { ids },
293
+ paramsSerializer: { indexes: null },
294
+ }),
295
+ onSuccess: () => {
296
+ void queryClient.invalidateQueries({ queryKey: [USER_QUERY_KEY] });
297
+ toast.success(COMMON_MESSAGES.DELETE_SUCCESS);
298
+ },
299
+ });
300
+ };
301
+
302
+ // --- Action Log ---
303
+
304
+ export const useGetLogs = (params: GetLogsParams) => {
305
+ return useQuery({
306
+ queryKey: [LOG_QUERY_KEY, "list", params],
307
+ queryFn: () => apiInstance.get<PageResponse<ActionLog>>("/action-logs", { params }).then((r) => r.data),
308
+ });
309
+ };
310
+
311
+ // --- Dashboard ---
312
+
313
+ export const useGetUserDashboard = (period = "30d") => {
314
+ return useQuery({
315
+ queryKey: [DASHBOARD_QUERY_KEY, period],
316
+ queryFn: () =>
317
+ apiInstance
318
+ .get<UserDashboardResponse>("/users/dashboard", { params: { period } })
319
+ .then((r) => r.data),
320
+ });
321
+ };
@@ -1,7 +1,7 @@
1
- export const AUTH_QUERY_KEY = "auth";
2
- export const SAMPLE_QUERY_KEY = "sample";
3
- export const POST_QUERY_KEY = "post";
4
- export const COMMENT_QUERY_KEY = "comment";
5
- export const USER_QUERY_KEY = "user";
6
- export const LOG_QUERY_KEY = "log";
7
- export const DASHBOARD_QUERY_KEY = "dashboard";
1
+ export const AUTH_QUERY_KEY = "auth";
2
+ export const SAMPLE_QUERY_KEY = "sample";
3
+ export const POST_QUERY_KEY = "post";
4
+ export const COMMENT_QUERY_KEY = "comment";
5
+ export const USER_QUERY_KEY = "user";
6
+ export const LOG_QUERY_KEY = "log";
7
+ export const DASHBOARD_QUERY_KEY = "dashboard";
@@ -1,7 +1,7 @@
1
- import Cookies from "js-cookie";
2
-
3
- export const clearUserToken = () => {
4
- Cookies.remove("AccessToken");
5
- Cookies.remove("RefreshToken");
6
- localStorage.removeItem("currentId");
7
- };
1
+ import Cookies from "js-cookie";
2
+
3
+ export const clearUserToken = () => {
4
+ Cookies.remove("AccessToken");
5
+ Cookies.remove("RefreshToken");
6
+ localStorage.removeItem("currentId");
7
+ };