@hedhog/setting 0.0.6 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. package/dist/index.d.ts +1 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/setting/dto/create.dto.d.ts +8 -0
  6. package/dist/setting/dto/create.dto.d.ts.map +1 -0
  7. package/dist/setting/dto/create.dto.js +36 -0
  8. package/dist/setting/dto/create.dto.js.map +1 -0
  9. package/dist/setting/dto/delete.dto.d.ts.map +1 -0
  10. package/dist/setting/dto/delete.dto.js.map +1 -0
  11. package/dist/setting/dto/setting-user.dto.d.ts +4 -0
  12. package/dist/setting/dto/setting-user.dto.d.ts.map +1 -0
  13. package/dist/{dto/create.dto.js → setting/dto/setting-user.dto.js} +6 -7
  14. package/dist/setting/dto/setting-user.dto.js.map +1 -0
  15. package/dist/setting/dto/setting.dto.d.ts +9 -0
  16. package/dist/setting/dto/setting.dto.d.ts.map +1 -0
  17. package/dist/setting/dto/setting.dto.js +34 -0
  18. package/dist/setting/dto/setting.dto.js.map +1 -0
  19. package/dist/setting/dto/update.dto.d.ts +6 -0
  20. package/dist/setting/dto/update.dto.d.ts.map +1 -0
  21. package/dist/{dto → setting/dto}/update.dto.js +2 -1
  22. package/dist/setting/dto/update.dto.js.map +1 -0
  23. package/dist/setting/setting.controller.d.ts +25 -0
  24. package/dist/setting/setting.controller.d.ts.map +1 -0
  25. package/dist/setting/setting.controller.js +149 -0
  26. package/dist/setting/setting.controller.js.map +1 -0
  27. package/dist/setting/setting.service.d.ts +28 -0
  28. package/dist/setting/setting.service.d.ts.map +1 -0
  29. package/dist/setting/setting.service.js +296 -0
  30. package/dist/setting/setting.service.js.map +1 -0
  31. package/dist/setting.module.d.ts +3 -0
  32. package/dist/setting.module.d.ts.map +1 -0
  33. package/dist/{settings.module.js → setting.module.js} +8 -8
  34. package/dist/setting.module.js.map +1 -0
  35. package/frontend/setting/components/create-panel.tsx +83 -0
  36. package/frontend/setting/components/setting.screen.tsx +105 -0
  37. package/frontend/setting/components/update-panel.tsx +96 -0
  38. package/frontend/setting/locales/en/setting.setting.json +11 -0
  39. package/frontend/setting/locales/pt/setting.setting.json +11 -0
  40. package/frontend/setting/react-query/handlers.ts +28 -0
  41. package/frontend/setting/react-query/requests.ts +55 -0
  42. package/frontend/setting-group/components/create-panel.tsx +62 -0
  43. package/frontend/setting-group/components/setting-group.screen.tsx +107 -0
  44. package/frontend/setting-group/components/update-panel.tsx +76 -0
  45. package/frontend/setting-group/locales/en/setting.setting-group.json +11 -0
  46. package/frontend/setting-group/locales/pt/setting.setting-group.json +11 -0
  47. package/frontend/setting-group/react-query/handlers.ts +28 -0
  48. package/frontend/setting-group/react-query/requests.ts +58 -0
  49. package/frontend/setting-user/components/create-panel.tsx +71 -0
  50. package/frontend/setting-user/components/setting-user.screen.tsx +107 -0
  51. package/frontend/setting-user/components/update-panel.tsx +85 -0
  52. package/frontend/setting-user/locales/en/setting.setting-user.json +11 -0
  53. package/frontend/setting-user/locales/pt/setting.setting-user.json +11 -0
  54. package/frontend/setting-user/react-query/handlers.ts +28 -0
  55. package/frontend/setting-user/react-query/requests.ts +57 -0
  56. package/hedhog.yaml +380 -0
  57. package/package.json +37 -29
  58. package/README.md +0 -108
  59. package/dist/dto/create.dto.d.ts +0 -4
  60. package/dist/dto/create.dto.d.ts.map +0 -1
  61. package/dist/dto/create.dto.js.map +0 -1
  62. package/dist/dto/delete.dto.d.ts.map +0 -1
  63. package/dist/dto/delete.dto.js.map +0 -1
  64. package/dist/dto/update.dto.d.ts +0 -4
  65. package/dist/dto/update.dto.d.ts.map +0 -1
  66. package/dist/dto/update.dto.js.map +0 -1
  67. package/dist/migrations/index.d.ts +0 -6
  68. package/dist/migrations/index.d.ts.map +0 -1
  69. package/dist/migrations/index.js +0 -67
  70. package/dist/migrations/index.js.map +0 -1
  71. package/dist/settings.controller.d.ts +0 -14
  72. package/dist/settings.controller.d.ts.map +0 -1
  73. package/dist/settings.controller.js +0 -95
  74. package/dist/settings.controller.js.map +0 -1
  75. package/dist/settings.module.d.ts +0 -3
  76. package/dist/settings.module.d.ts.map +0 -1
  77. package/dist/settings.module.js.map +0 -1
  78. package/dist/settings.service.d.ts +0 -19
  79. package/dist/settings.service.d.ts.map +0 -1
  80. package/dist/settings.service.js +0 -70
  81. package/dist/settings.service.js.map +0 -1
  82. package/src/dto/create.dto.ts +0 -7
  83. package/src/dto/delete.dto.ts +0 -8
  84. package/src/dto/update.dto.ts +0 -3
  85. package/src/index.ts +0 -2
  86. package/src/migrations/index.ts +0 -78
  87. package/src/settings.controller.ts +0 -65
  88. package/src/settings.module.ts +0 -18
  89. package/src/settings.service.ts +0 -75
  90. package/tsconfig.lib.json +0 -9
  91. package/tsconfig.production.json +0 -20
  92. /package/dist/{dto → setting/dto}/delete.dto.d.ts +0 -0
  93. /package/dist/{dto → setting/dto}/delete.dto.js +0 -0
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SettingService = void 0;
16
+ const pagination_1 = require("@hedhog/pagination");
17
+ const prisma_1 = require("@hedhog/prisma");
18
+ const utils_1 = require("@hedhog/utils");
19
+ const common_1 = require("@nestjs/common");
20
+ let SettingService = class SettingService {
21
+ constructor(prismaService, paginationService) {
22
+ this.prismaService = prismaService;
23
+ this.paginationService = paginationService;
24
+ }
25
+ async setManySettings(data) {
26
+ const transaction = [];
27
+ for (const { slug, value } of data.setting) {
28
+ transaction.push(this.prismaService.setting.updateMany({
29
+ where: {
30
+ slug,
31
+ },
32
+ data: {
33
+ value,
34
+ },
35
+ }));
36
+ }
37
+ await this.prismaService.$transaction(transaction);
38
+ const hasAppearance = await this.prismaService.setting.count({
39
+ where: {
40
+ slug: {
41
+ in: data.setting.map((setting) => setting.slug),
42
+ },
43
+ setting_group: {
44
+ slug: 'appearance',
45
+ },
46
+ },
47
+ });
48
+ return { success: true };
49
+ }
50
+ async getSettingFromGroup(locale, paginationParams, slug) {
51
+ const fields = ['slug', 'value'];
52
+ paginationParams.pageSize = 100;
53
+ const OR = this.prismaService.createInsensitiveSearch(fields, paginationParams);
54
+ const result = await this.paginationService.paginate(this.prismaService.setting, paginationParams, {
55
+ where: {
56
+ AND: {
57
+ setting_group: {
58
+ slug,
59
+ },
60
+ OR,
61
+ },
62
+ },
63
+ include: {
64
+ setting_group: {
65
+ include: {
66
+ setting_group_locale: {
67
+ where: {
68
+ locale: {
69
+ code: locale,
70
+ },
71
+ },
72
+ select: {
73
+ name: true,
74
+ description: true,
75
+ },
76
+ },
77
+ },
78
+ },
79
+ setting_locale: {
80
+ where: {
81
+ locale: {
82
+ code: locale,
83
+ },
84
+ },
85
+ select: {
86
+ name: true,
87
+ description: true,
88
+ },
89
+ },
90
+ },
91
+ }, 'setting_locale');
92
+ result.data = result.data.map((setting) => {
93
+ setting.setting_group = (0, utils_1.itemTranslations)('setting_group_locale', setting.setting_group);
94
+ return setting;
95
+ });
96
+ return result;
97
+ }
98
+ async listSettingGroups(locale, paginationParams) {
99
+ const fields = ['slug', 'icon'];
100
+ paginationParams.pageSize = 100;
101
+ const OR = this.prismaService.createInsensitiveSearch(fields, paginationParams);
102
+ const result = await this.paginationService.paginate(this.prismaService.setting_group, paginationParams, {
103
+ where: {
104
+ OR,
105
+ },
106
+ include: {
107
+ setting_group_locale: {
108
+ where: {
109
+ locale: {
110
+ code: locale,
111
+ },
112
+ },
113
+ select: {
114
+ name: true,
115
+ description: true,
116
+ },
117
+ },
118
+ },
119
+ }, 'setting_group_locale');
120
+ return result;
121
+ }
122
+ async listSettings(locale, paginationParams) {
123
+ const fields = ['slug', 'value'];
124
+ const OR = this.prismaService.createInsensitiveSearch(fields, paginationParams);
125
+ const result = await this.paginationService.paginate(this.prismaService.setting, paginationParams, {
126
+ where: {
127
+ OR,
128
+ },
129
+ include: {
130
+ setting_group: {
131
+ include: {
132
+ setting_group_locale: {
133
+ where: {
134
+ locale: {
135
+ code: locale,
136
+ },
137
+ },
138
+ select: {
139
+ name: true,
140
+ description: true,
141
+ },
142
+ },
143
+ },
144
+ },
145
+ setting_locale: {
146
+ where: {
147
+ locale: {
148
+ code: locale,
149
+ },
150
+ },
151
+ select: {
152
+ name: true,
153
+ description: true,
154
+ },
155
+ },
156
+ },
157
+ }, 'setting_locale');
158
+ result.data = result.data.map((setting) => {
159
+ setting.setting_group = (0, utils_1.itemTranslations)('setting_group_locale', setting.setting_group);
160
+ return setting;
161
+ });
162
+ return result;
163
+ }
164
+ async get(settingId) {
165
+ return this.prismaService.setting.findUnique({
166
+ where: { id: settingId },
167
+ });
168
+ }
169
+ async create({}) {
170
+ return this.prismaService.setting.create({
171
+ data: {},
172
+ });
173
+ }
174
+ async update({ id, data }) {
175
+ return this.prismaService.setting.update({
176
+ where: { id },
177
+ data,
178
+ });
179
+ }
180
+ async updateFromSlug(slug, data) {
181
+ const { id } = await this.prismaService.setting.findFirst({
182
+ where: {
183
+ slug,
184
+ },
185
+ });
186
+ if (!id) {
187
+ throw new common_1.BadRequestException(`Setting with slug ${slug} not found.`);
188
+ }
189
+ return this.update({
190
+ id,
191
+ data,
192
+ });
193
+ }
194
+ async delete({ ids }) {
195
+ if (ids == undefined || ids == null) {
196
+ throw new common_1.BadRequestException(`You must select at least one setting to delete.`);
197
+ }
198
+ return this.prismaService.setting.deleteMany({
199
+ where: {
200
+ id: {
201
+ in: ids,
202
+ },
203
+ },
204
+ });
205
+ }
206
+ async setSettingUserValue(user_id, slug, value) {
207
+ const user = await this.prismaService.user.findUnique({
208
+ where: {
209
+ id: user_id,
210
+ },
211
+ select: {
212
+ id: true,
213
+ },
214
+ });
215
+ if (!user) {
216
+ throw new common_1.BadRequestException(`User with id ${user_id} not found.`);
217
+ }
218
+ const setting = await this.prismaService.setting.findFirst({
219
+ where: {
220
+ slug,
221
+ user_override: true,
222
+ },
223
+ });
224
+ if (!setting) {
225
+ throw new common_1.BadRequestException(`Setting with slug ${slug} not found or user can not override.`);
226
+ }
227
+ return await this.prismaService.setting_user.upsert({
228
+ where: {
229
+ user_id_setting_id: {
230
+ setting_id: setting.id,
231
+ user_id: user.id,
232
+ },
233
+ },
234
+ create: {
235
+ setting_id: setting.id,
236
+ value,
237
+ user_id: user.id,
238
+ },
239
+ update: {
240
+ value,
241
+ },
242
+ select: {
243
+ setting_id: true,
244
+ user_id: true,
245
+ value: true,
246
+ },
247
+ });
248
+ }
249
+ async getSettingValues(slug) {
250
+ slug = Array.isArray(slug) ? slug : [slug];
251
+ let setting = await this.prismaService.setting.findMany({
252
+ where: {
253
+ slug: {
254
+ in: slug,
255
+ },
256
+ },
257
+ select: {
258
+ id: true,
259
+ value: true,
260
+ slug: true,
261
+ type: true,
262
+ user_override: true,
263
+ },
264
+ });
265
+ const slugUserOverride = setting.filter((setting) => setting.userOverride);
266
+ const settingUser = await this.prismaService.setting_user.findMany({
267
+ where: {
268
+ setting_id: {
269
+ in: slugUserOverride.map((setting) => setting.id),
270
+ },
271
+ },
272
+ select: {
273
+ value: true,
274
+ setting_id: true,
275
+ },
276
+ });
277
+ const data = {};
278
+ setting.forEach((setting) => {
279
+ data[setting.slug] = setting.value;
280
+ });
281
+ settingUser.forEach((setting) => {
282
+ data[slugUserOverride.find((s) => s.id === setting.setting_id).slug] =
283
+ setting.value;
284
+ });
285
+ return data;
286
+ }
287
+ };
288
+ exports.SettingService = SettingService;
289
+ exports.SettingService = SettingService = __decorate([
290
+ (0, common_1.Injectable)(),
291
+ __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => prisma_1.PrismaService))),
292
+ __param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => pagination_1.PaginationService))),
293
+ __metadata("design:paramtypes", [prisma_1.PrismaService,
294
+ pagination_1.PaginationService])
295
+ ], SettingService);
296
+ //# sourceMappingURL=setting.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.service.js","sourceRoot":"","sources":["../../src/setting/setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mDAAsE;AACtE,2CAA+C;AAC/C,yCAAiD;AACjD,2CAKwB;AAQjB,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAEmB,aAA4B,EAE5B,iBAAoC;QAFpC,kBAAa,GAAb,aAAa,CAAe;QAE5B,sBAAiB,GAAjB,iBAAiB,CAAmB;IACpD,CAAC;IAEJ,KAAK,CAAC,eAAe,CAAC,IAAgB;QACpC,MAAM,WAAW,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3C,WAAW,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC;gBACpC,KAAK,EAAE;oBACL,IAAI;iBACL;gBACD,IAAI,EAAE;oBACJ,KAAK;iBACN;aACF,CAAC,CACH,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAEnD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC;YAC3D,KAAK,EAAE;gBACL,IAAI,EAAE;o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,CAAC,QAAQ,CAAC;YACjE,KAAK,EAAE;gBACL,UAAU,EAAE;oBACV,EAAE,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;iBAClD;aACF;YACD,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI;gBACX,UAAU,EAAE,IAAI;aACjB;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,GAAwB,EAAE,CAAC;QAErC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;gBAClE,OAAO,CAAC,KAAK,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3VY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,sBAAa,CAAC,CAAC,CAAA;IAEvC,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,8BAAiB,CAAC,CAAC,CAAA;qCADZ,sBAAa;QAET,8BAAiB;GAL5C,cAAc,CA2V1B"}
@@ -0,0 +1,3 @@
1
+ export declare class SettingModule {
2
+ }
3
+ //# sourceMappingURL=setting.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.module.d.ts","sourceRoot":"","sources":["../src/setting.module.ts"],"names":[],"mappings":"AAOA,qBAUa,aAAa;CAAG"}
@@ -7,25 +7,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SettingModule = void 0;
10
- const auth_1 = require("@hedhog/auth");
10
+ const file_1 = require("@hedhog/file");
11
11
  const pagination_1 = require("@hedhog/pagination");
12
12
  const prisma_1 = require("@hedhog/prisma");
13
13
  const common_1 = require("@nestjs/common");
14
- const settings_controller_1 = require("./settings.controller");
15
- const settings_service_1 = require("./settings.service");
14
+ const setting_controller_1 = require("./setting/setting.controller");
15
+ const setting_service_1 = require("./setting/setting.service");
16
16
  let SettingModule = class SettingModule {
17
17
  };
18
18
  exports.SettingModule = SettingModule;
19
19
  exports.SettingModule = SettingModule = __decorate([
20
20
  (0, common_1.Module)({
21
- providers: [settings_service_1.SettingsService],
22
- exports: [settings_service_1.SettingsService],
23
- controllers: [settings_controller_1.SettingsController],
21
+ providers: [setting_service_1.SettingService],
22
+ exports: [setting_service_1.SettingService],
23
+ controllers: [setting_controller_1.SettingsController],
24
24
  imports: [
25
- (0, common_1.forwardRef)(() => auth_1.AuthModule),
26
25
  (0, common_1.forwardRef)(() => prisma_1.PrismaModule),
27
26
  (0, common_1.forwardRef)(() => pagination_1.PaginationModule),
27
+ (0, common_1.forwardRef)(() => file_1.FileModule),
28
28
  ],
29
29
  })
30
30
  ], SettingModule);
31
- //# sourceMappingURL=settings.module.js.map
31
+ //# sourceMappingURL=setting.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.module.js","sourceRoot":"","sources":["../src/setting.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAA0C;AAC1C,mDAAsD;AACtD,2CAA8C;AAC9C,2CAAoD;AACpD,qEAAkE;AAClE,+DAA2D;AAYpD,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IAVzB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,gCAAc,CAAC;QAC3B,OAAO,EAAE,CAAC,gCAAc,CAAC;QACzB,WAAW,EAAE,CAAC,uCAAkB,CAAC;QACjC,OAAO,EAAE;YACP,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,qBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,6BAAgB,CAAC;YAClC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,iBAAU,CAAC;SAC7B;KACF,CAAC;GACW,aAAa,CAAG"}
@@ -0,0 +1,83 @@
1
+ import FormPanel, {
2
+ FormPanelRef,
3
+ getFieldsLocale,
4
+ } from "@/components/panels/form-panel";
5
+ import { EnumFieldType } from "@/enums/EnumFieldType";
6
+ import { useSettingCreate } from "@/features/blog/setting";
7
+ import { Setting } from "@/types/models";
8
+ import { forwardRef, useImperativeHandle, useRef } from "react";
9
+ import { useTranslation } from "react-i18next";
10
+
11
+ export type SettingCreatePanelRef = {
12
+ submit: () => void;
13
+ };
14
+
15
+ export type SettingCreatePanelProps = {
16
+ onCreated?: (data: Setting) => void;
17
+ };
18
+
19
+ const SettingCreatePanel = forwardRef(
20
+ ({ onCreated }: SettingCreatePanelProps, ref) => {
21
+ const formRef = useRef<FormPanelRef>(null);
22
+ const { t } = useTranslation(["actions"]);
23
+ const { mutateAsync: createSetting } = useSettingCreate();
24
+
25
+ useImperativeHandle(
26
+ ref,
27
+ () => ({
28
+ submit: () => {
29
+ formRef.current?.submit();
30
+ },
31
+ }),
32
+ [formRef],
33
+ );
34
+
35
+ return (
36
+ <FormPanel
37
+ ref={formRef}
38
+ fields={[
39
+ {
40
+ name: "group_id",
41
+ label: { text: t("group_id", { ns: "translation" }) },
42
+ type: EnumFieldType.TEXT,
43
+ required: true,
44
+ },
45
+
46
+ {
47
+ name: "type",
48
+ label: { text: t("type", { ns: "translation" }) },
49
+ type: EnumFieldType.TEXT,
50
+ required: true,
51
+ },
52
+
53
+ {
54
+ name: "value",
55
+ label: { text: t("value", { ns: "translation" }) },
56
+ type: EnumFieldType.TEXT,
57
+ required: true,
58
+ },
59
+
60
+ {
61
+ name: "user_override",
62
+ label: { text: t("user_override", { ns: "translation" }) },
63
+ type: EnumFieldType.TEXT,
64
+ required: true,
65
+ },
66
+
67
+ ...getFieldsLocale([{ name: "name" }]),
68
+ ]}
69
+ button={{ text: t("create", { ns: "actions" }) }}
70
+ onSubmit={async (data) => {
71
+ const createdData = await createSetting(data);
72
+ if (typeof onCreated === "function") {
73
+ onCreated(createdData);
74
+ }
75
+ }}
76
+ />
77
+ );
78
+ },
79
+ );
80
+
81
+ SettingCreatePanel.displayName = "SettingCreatePanel";
82
+
83
+ export default SettingCreatePanel;
@@ -0,0 +1,105 @@
1
+ import { PageTitle } from "@/components/custom/page-title";
2
+ import DataPanel from "@/components/panels/data-panel";
3
+ import { useSettingDelete } from "@/features/blog/setting";
4
+ import { useApp } from "@/hooks/use-app";
5
+ import { isPlural } from "@/lib/utils";
6
+ import { Setting } from "@/types/models";
7
+ import { IconEdit, IconPlus, IconTrash } from "@tabler/icons-react";
8
+ import { useState } from "react";
9
+ import { useTranslation } from "react-i18next";
10
+ import SettingCreatePanel from "./components/setting-create-panel";
11
+ import SettingUpdatePanel from "./components/setting-update-panel";
12
+
13
+ export default function Page() {
14
+ const [selectedItems, setSelectedItems] = useState<Setting[]>([]);
15
+ const { mutate: deleteSetting } = useSettingDelete();
16
+ const { openSheet, confirm, closeSheet } = useApp();
17
+ const { t } = useTranslation(["setting", "modules", "actions"]);
18
+
19
+ const openCreate = () => {
20
+ const id = openSheet({
21
+ title: t("create", { ns: "actions" }),
22
+ description: t("createText", { ns: "setting" }),
23
+ children: () => <SettingCreatePanel onCreated={() => closeSheet(id)} />,
24
+ });
25
+
26
+ return id;
27
+ };
28
+
29
+ const openDelete = (items: Setting[]) => {
30
+ return confirm({
31
+ title: `${t("delete", { ns: "actions" })} ${items.length} ${isPlural(items.length) ? t("items", { ns: "actions" }) : t("item", { ns: "actions" })}`,
32
+ description: t("deleteText", { ns: "setting" }),
33
+ })
34
+ .then(() =>
35
+ deleteSetting(
36
+ items.map((item) => item.id).filter((id) => id !== undefined),
37
+ ),
38
+ )
39
+ .catch(() => setSelectedItems(items));
40
+ };
41
+
42
+ const openUpdate = (item: Setting) => {
43
+ const id = openSheet({
44
+ children: () => (
45
+ <SettingUpdatePanel data={item} onUpdated={() => closeSheet(id)} />
46
+ ),
47
+ title: t("edit", { ns: "setting" }),
48
+ description: t("editText", { ns: "setting" }),
49
+ });
50
+
51
+ return id;
52
+ };
53
+
54
+ return (
55
+ <>
56
+ <PageTitle title={t("setting", { ns: "modules" })} />
57
+ <DataPanel
58
+ url="/setting"
59
+ layout="table"
60
+ id="setting"
61
+ selectable
62
+ columns={[
63
+ { key: "id", header: "ID", width: 64 },
64
+ { key: "name", header: t("name", { ns: "setting" }) },
65
+ ]}
66
+ selected={selectedItems as Setting[]}
67
+ multiple
68
+ hasSearch
69
+ sortable
70
+ onItemDoubleClick={(item) => openUpdate(item)}
71
+ menuActions={[
72
+ {
73
+ icon: <IconEdit className="mr-1 w-8 cursor-pointer" />,
74
+ label: t("edit", { ns: "actions" }),
75
+ tooltip: t("editTooltip", { ns: "setting" }),
76
+ handler: (items: Setting[]) => {
77
+ if (items.length === 1) openUpdate(items[0]);
78
+ },
79
+ show: "once",
80
+ },
81
+ {
82
+ icon: <IconTrash className="mr-1 w-8 cursor-pointer" />,
83
+ label: t("delete", { ns: "actions" }),
84
+ tooltip: t("deleteTooltip", { ns: "setting" }),
85
+ variant: "destructive",
86
+ handler: (items: Setting[]) => {
87
+ openDelete(items);
88
+ },
89
+ show: "some",
90
+ },
91
+ {
92
+ icon: <IconPlus className="mr-1 w-8 cursor-pointer" />,
93
+ label: t("create", { ns: "actions" }),
94
+ tooltip: t("createTooltip", { ns: "setting" }),
95
+ variant: "default",
96
+ handler: () => {
97
+ openCreate();
98
+ },
99
+ show: "none",
100
+ },
101
+ ]}
102
+ />
103
+ </>
104
+ );
105
+ }
@@ -0,0 +1,96 @@
1
+ import FormPanel, {
2
+ FormPanelRef,
3
+ getFieldsLocale,
4
+ } from "@/components/panels/form-panel";
5
+ import { Overlay } from "@/components/custom/overlay";
6
+ import { TabPanel } from "@/components/panels/tab-panel";
7
+ import { EnumFieldType } from "@/enums/EnumFieldType";
8
+ import { useSettingGet, useSettingUpdate } from "@/features/blog/setting";
9
+ import useEffectAfterFirstUpdate from "@/hooks/use-effect-after-first-update";
10
+ import { Setting } from "@/types/models";
11
+ import { forwardRef, useImperativeHandle, useRef } from "react";
12
+ import { useTranslation } from "react-i18next";
13
+
14
+ export type SettingUpdatePanelProps = {
15
+ data: Setting;
16
+ onUpdated?: (data: Setting) => void;
17
+ };
18
+
19
+ const SettingUpdatePanel = forwardRef(
20
+ ({ data, onUpdated }: SettingUpdatePanelProps, ref) => {
21
+ const { t } = useTranslation(["actions"]);
22
+ const { data: item, isLoading } = useSettingGet(data.id as number);
23
+ const { mutate: settingUpdate } = useSettingUpdate();
24
+ const formRef = useRef<FormPanelRef>(null);
25
+
26
+ useEffectAfterFirstUpdate(() => {
27
+ if (item && formRef.current) {
28
+ formRef.current.setValuesFromItem(item);
29
+ }
30
+ }, [item]);
31
+
32
+ useImperativeHandle(ref, () => ({}));
33
+
34
+ return (
35
+ <TabPanel
36
+ activeTabIndex={0}
37
+ tabs={[
38
+ {
39
+ title: t("details", { ns: "actions" }),
40
+ children: (
41
+ <Overlay loading={isLoading}>
42
+ <FormPanel
43
+ ref={formRef}
44
+ fields={[
45
+ {
46
+ name: "group_id",
47
+ label: { text: t("group_id", { ns: "translation" }) },
48
+ type: EnumFieldType.TEXT,
49
+ required: true,
50
+ },
51
+
52
+ {
53
+ name: "type",
54
+ label: { text: t("type", { ns: "translation" }) },
55
+ type: EnumFieldType.TEXT,
56
+ required: true,
57
+ },
58
+
59
+ {
60
+ name: "value",
61
+ label: { text: t("value", { ns: "translation" }) },
62
+ type: EnumFieldType.TEXT,
63
+ required: true,
64
+ },
65
+
66
+ {
67
+ name: "user_override",
68
+ label: {
69
+ text: t("user_override", { ns: "translation" }),
70
+ },
71
+ type: EnumFieldType.TEXT,
72
+ required: true,
73
+ },
74
+
75
+ ...getFieldsLocale([{ name: "name" }]),
76
+ ]}
77
+ button={{ text: t("save", { ns: "actions" }) }}
78
+ onSubmit={(data) => {
79
+ settingUpdate({ id: data.id, data });
80
+ if (typeof onUpdated === "function") {
81
+ onUpdated(data);
82
+ }
83
+ }}
84
+ />
85
+ </Overlay>
86
+ ),
87
+ },
88
+ ]}
89
+ />
90
+ );
91
+ },
92
+ );
93
+
94
+ SettingUpdatePanel.displayName = "SettingUpdatePanel";
95
+
96
+ export default SettingUpdatePanel;
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": "Create setting",
3
+ "createText": "Fill the setting informations.",
4
+ "createTooltip": "Create new setting",
5
+ "delete": "Delete setting",
6
+ "deleteText": "Are you sure to delete these setting?",
7
+ "deleteTooltip": "Delete the selected setting",
8
+ "edit": "Edit setting",
9
+ "editText": "View and edit setting information.",
10
+ "editTooltip": "Edit the selected setting"
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": "Criar configuração",
3
+ "createText": "Preencha as informações da configuração.",
4
+ "createTooltip": "Criar nova configuração",
5
+ "delete": "Deletar configuração",
6
+ "deleteText": "Você tem certeza de que deseja deletar estas configurações?",
7
+ "deleteTooltip": "Deletar a configuração selecionada",
8
+ "edit": "Editar configuração",
9
+ "editText": "Ver e editar informações da configuração.",
10
+ "editTooltip": "Editar a configuração selecionada"
11
+ }