@tager/admin-blog 0.3.21 → 0.3.25

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 (86) hide show
  1. package/dist/index.esm.js +3452 -612
  2. package/dist/index.umd.js +3454 -619
  3. package/package.json +13 -7
  4. package/src/constants/menu.ts +0 -2
  5. package/src/constants/paths.ts +0 -5
  6. package/src/constants/routes.ts +5 -18
  7. package/src/constants/scopes.ts +11 -0
  8. package/src/dev.ts +11 -44
  9. package/src/hooks/index.ts +6 -0
  10. package/src/hooks/useBlogCategoryList.ts +3 -5
  11. package/src/hooks/useBlogPostList.ts +2 -4
  12. package/src/hooks/useModuleConfig.ts +4 -8
  13. package/src/hooks/useStore.ts +8 -0
  14. package/src/hooks/useUserPermission.ts +16 -0
  15. package/src/hooks/useUserProfile.ts +13 -0
  16. package/src/locales/en.ts +17 -5
  17. package/src/locales/ru.ts +17 -4
  18. package/src/router/index.ts +39 -0
  19. package/src/services/requests.ts +33 -43
  20. package/src/store/index.ts +21 -0
  21. package/src/store/user.ts +109 -0
  22. package/src/typings/common.ts +1 -0
  23. package/src/typings/model.ts +62 -38
  24. package/src/utils/common.ts +23 -0
  25. package/src/views/App.vue +10 -4
  26. package/src/views/{BlogCategoryForm/BlogCategoryForm.helpers.ts → Categories/CategoryForm/CategoryForm.helpers.ts} +22 -7
  27. package/src/views/{BlogCategoryForm/BlogCategoryForm.vue → Categories/CategoryForm/CategoryForm.vue} +140 -63
  28. package/src/views/Categories/CategoryForm/index.ts +1 -0
  29. package/src/views/Categories/CategoryList/CategoryList.helpers.ts +91 -0
  30. package/src/views/Categories/CategoryList/CategoryList.vue +269 -0
  31. package/src/views/Categories/CategoryList/hooks/index.ts +1 -0
  32. package/src/views/Categories/CategoryList/hooks/useAdvancedSearch.ts +95 -0
  33. package/src/views/Categories/CategoryList/index.ts +1 -0
  34. package/src/views/Home.vue +2 -9
  35. package/src/views/Posts/PostForm/PostForm.helpers.ts +150 -0
  36. package/src/views/Posts/PostForm/PostForm.vue +550 -0
  37. package/src/views/{BlogPostForm → Posts/PostForm}/components/TabList/TabList.types.ts +0 -0
  38. package/src/views/{BlogPostForm → Posts/PostForm}/components/TabList/TabList.vue +1 -1
  39. package/src/views/{BlogPostForm → Posts/PostForm}/components/TabList/index.ts +0 -0
  40. package/src/views/Posts/PostForm/index.ts +1 -0
  41. package/src/views/{BlogPostList/BlogPostList.helpers.ts → Posts/PostList/PostList.helpers.ts} +10 -18
  42. package/src/views/Posts/PostList/PostList.vue +361 -0
  43. package/src/views/Posts/PostList/hooks/index.ts +1 -0
  44. package/src/views/Posts/PostList/hooks/useAdvancedSearch.ts +250 -0
  45. package/src/views/Posts/PostList/index.ts +1 -0
  46. package/dist/constants/menu.d.ts +0 -5
  47. package/dist/constants/paths.d.ts +0 -16
  48. package/dist/constants/routes.d.ts +0 -6
  49. package/dist/dev.d.ts +0 -3
  50. package/dist/hooks/useBlogCategoryList.d.ts +0 -7
  51. package/dist/hooks/useBlogPostList.d.ts +0 -7
  52. package/dist/hooks/useModuleConfig.d.ts +0 -7
  53. package/dist/locales/en.d.ts +0 -63
  54. package/dist/locales/ru.d.ts +0 -3
  55. package/dist/main.d.ts +0 -4
  56. package/dist/services/requests.d.ts +0 -68
  57. package/dist/typings/model.d.ts +0 -74
  58. package/dist/views/BlogCategoryForm/BlogCategoryForm.helpers.d.ts +0 -16
  59. package/dist/views/BlogCategoryForm/BlogCategoryForm.vue.d.ts +0 -86
  60. package/dist/views/BlogCategoryForm/index.d.ts +0 -1
  61. package/dist/views/BlogCategoryList/BlogCategoryList.helpers.d.ts +0 -6
  62. package/dist/views/BlogCategoryList/BlogCategoryList.vue.d.ts +0 -3
  63. package/dist/views/BlogCategoryList/index.d.ts +0 -1
  64. package/dist/views/BlogPostForm/BlogPostForm.helpers.d.ts +0 -27
  65. package/dist/views/BlogPostForm/BlogPostForm.vue.d.ts +0 -9320
  66. package/dist/views/BlogPostForm/components/TabList/TabList.types.d.ts +0 -5
  67. package/dist/views/BlogPostForm/components/TabList/index.d.ts +0 -2
  68. package/dist/views/BlogPostForm/index.d.ts +0 -1
  69. package/dist/views/BlogPostList/BlogPostList.helpers.d.ts +0 -6
  70. package/dist/views/BlogPostList/BlogPostList.vue.d.ts +0 -45
  71. package/dist/views/BlogPostList/index.d.ts +0 -1
  72. package/dist/views/BlogSettings/BlogSettings.helpers.d.ts +0 -6
  73. package/dist/views/BlogSettings/BlogSettings.vue.d.ts +0 -9132
  74. package/dist/views/BlogSettings/index.d.ts +0 -1
  75. package/src/views/BlogCategoryForm/index.ts +0 -1
  76. package/src/views/BlogCategoryList/BlogCategoryList.helpers.ts +0 -82
  77. package/src/views/BlogCategoryList/BlogCategoryList.vue +0 -196
  78. package/src/views/BlogCategoryList/index.ts +0 -1
  79. package/src/views/BlogPostForm/BlogPostForm.helpers.ts +0 -152
  80. package/src/views/BlogPostForm/BlogPostForm.vue +0 -534
  81. package/src/views/BlogPostForm/index.ts +0 -1
  82. package/src/views/BlogPostList/BlogPostList.vue +0 -174
  83. package/src/views/BlogPostList/index.ts +0 -1
  84. package/src/views/BlogSettings/BlogSettings.helpers.ts +0 -25
  85. package/src/views/BlogSettings/BlogSettings.vue +0 -110
  86. package/src/views/BlogSettings/index.ts +0 -1
@@ -0,0 +1,550 @@
1
+ <template>
2
+ <page
3
+ :title="isCreation ? $t('blog:createPost') : $t('blog:updatePost')"
4
+ :is-content-loading="isContentLoading"
5
+ :header-buttons="headerButtonList"
6
+ :footer="{
7
+ backHref: postListUrl,
8
+ onSubmit: submitForm,
9
+ isSubmitting: isSubmitting,
10
+ }"
11
+ >
12
+ <template v-slot:content>
13
+ <form novalidate @submit.prevent="submitForm">
14
+ <tab-list
15
+ :tab-list="tabList"
16
+ :selected-tab-id="selectedTabId"
17
+ @tab:update="selectedTabId = $event.tabId"
18
+ />
19
+
20
+ <template v-if="selectedTabId === 'common'">
21
+ <form-field-select
22
+ v-if="isCreation && isLangSpecific"
23
+ v-model="values.language"
24
+ name="language"
25
+ :label="$t('blog:language')"
26
+ :options="languageOptionList"
27
+ :error="errors.language"
28
+ />
29
+
30
+ <form-field
31
+ v-model="values.title"
32
+ name="title"
33
+ :label="$t('blog:title')"
34
+ :error="errors.title"
35
+ @input="handleTitleChange"
36
+ />
37
+
38
+ <form-field-url-alias-input
39
+ id="urlAlias"
40
+ v-model="values.urlAlias"
41
+ name="urlAlias"
42
+ :label="$t('blog:URLAlias')"
43
+ :url-template="urlAliasTemplate"
44
+ :error="errors.urlAlias"
45
+ @change="handleAliasChange"
46
+ />
47
+
48
+ <form-field
49
+ v-model="values.excerpt"
50
+ name="excerpt"
51
+ :label="$t('blog:excerpt')"
52
+ type="textarea"
53
+ :error="errors.excerpt"
54
+ />
55
+ <form-field-rich-text-input
56
+ v-model="values.body"
57
+ name="body"
58
+ :label="$t('blog:body')"
59
+ :error="errors.body"
60
+ :get-upload-adapter-options="getUploadAdapterOptions"
61
+ />
62
+ <ShortCodeConstructor
63
+ :short-code-config-list="
64
+ moduleConfig ? moduleConfig.shortcodes : []
65
+ "
66
+ />
67
+
68
+ <form-field
69
+ v-model="values.date"
70
+ name="date"
71
+ :label="$t('blog:date')"
72
+ type="date"
73
+ :error="errors.date"
74
+ />
75
+ </template>
76
+
77
+ <template v-if="selectedTabId === 'images'">
78
+ <form-field-file-input
79
+ v-model="values.coverImage"
80
+ :label="$t('blog:coverImage')"
81
+ name="coverImage"
82
+ file-type="image"
83
+ :scenario="moduleConfig ? moduleConfig.fileScenarios.cover : null"
84
+ />
85
+
86
+ <form-field-file-input
87
+ v-model="values.image"
88
+ name="image"
89
+ :label="$t('blog:innerImage')"
90
+ file-type="image"
91
+ :scenario="moduleConfig ? moduleConfig.fileScenarios.image : null"
92
+ />
93
+
94
+ <form-field-file-input
95
+ v-model="values.imageMobile"
96
+ name="imageMobile"
97
+ :label="$t('blog:innerImageMobile')"
98
+ file-type="image"
99
+ :scenario="
100
+ moduleConfig ? moduleConfig.fileScenarios.imageMobile : null
101
+ "
102
+ />
103
+ </template>
104
+
105
+ <template v-if="selectedTabId === 'relations'">
106
+ <form-field
107
+ v-model="values.tags"
108
+ name="tags"
109
+ :label="$t('blog:tags')"
110
+ :error="errors.tags"
111
+ />
112
+
113
+ <form-field-multi-select
114
+ v-model="values.categories"
115
+ name="categories"
116
+ :label="$t('blog:categories')"
117
+ :options="categoryOptionList"
118
+ :error="errors.categories"
119
+ />
120
+
121
+ <form-field-multi-select
122
+ v-model="values.relatedPosts"
123
+ name="relatedPosts"
124
+ :label="$t('blog:relatedPosts')"
125
+ :options="postOptionList"
126
+ :error="errors.relatedPosts"
127
+ :searchable="true"
128
+ />
129
+ </template>
130
+
131
+ <template v-if="selectedTabId === 'additional'">
132
+ <DynamicField
133
+ v-for="field of values.additionalFields"
134
+ :key="field.name"
135
+ :field="field"
136
+ />
137
+ </template>
138
+
139
+ <template v-if="selectedTabId === 'seo'">
140
+ <seo-field-group
141
+ :title="values.pageTitle"
142
+ :title-error-message="errors.pageTitle"
143
+ :title-label="$t('blog:pageTitle')"
144
+ :description="values.pageDescription"
145
+ :description-error-message="errors.pageDescription"
146
+ :description-label="$t('blog:pageDescription')"
147
+ :image="values.openGraphImage"
148
+ :image-error-message="errors.openGraphImage"
149
+ :image-label="$t('blog:openGraphImage')"
150
+ :image-scenario="
151
+ moduleConfig ? moduleConfig.fileScenarios.openGraph : null
152
+ "
153
+ @change="handleSeoFieldGroupChange"
154
+ />
155
+ </template>
156
+ </form>
157
+ </template>
158
+
159
+ <template v-slot:footer>
160
+ <FormFooter
161
+ :back-href="postListUrl"
162
+ :on-submit="submitForm"
163
+ :is-submitting="isSubmitting"
164
+ :is-creation="isCreation"
165
+ :can-create-another="isCreation"
166
+ />
167
+ </template>
168
+ </page>
169
+ </template>
170
+
171
+ <script lang="ts">
172
+ import {
173
+ computed,
174
+ defineComponent,
175
+ onMounted,
176
+ ref,
177
+ watch,
178
+ } from '@vue/composition-api';
179
+
180
+ import {
181
+ convertRequestErrorToMap,
182
+ isNotNullish,
183
+ Nullable,
184
+ useResource,
185
+ urlTranslit,
186
+ } from '@tager/admin-services';
187
+ import {
188
+ createTabErrorFinder,
189
+ OptionType,
190
+ TabType,
191
+ ShortCodeConstructor,
192
+ SeoChangeEvent,
193
+ FormFooter,
194
+ TagerFormSubmitEvent,
195
+ } from '@tager/admin-ui';
196
+ import { DynamicField } from '@tager/admin-dynamic-field';
197
+
198
+ import {
199
+ createBlogPost,
200
+ getBlogPost,
201
+ updateBlogPost,
202
+ } from '@/services/requests';
203
+ import { Language, PostFull } from '@/typings/model';
204
+ import { getBlogPostFormUrl, getBlogPostListUrl } from '@/constants/paths';
205
+
206
+ import {
207
+ useModuleConfig,
208
+ useBlogCategoryList,
209
+ useBlogPostList,
210
+ } from '../../../hooks';
211
+
212
+ import {
213
+ convertCategoryListToOptions,
214
+ convertFormValuesToCreationPayload,
215
+ convertFormValuesToUpdatePayload,
216
+ convertPostToFormValues,
217
+ FormValues,
218
+ } from './PostForm.helpers';
219
+
220
+ export default defineComponent({
221
+ name: 'BlogPostForm',
222
+ components: { DynamicField, ShortCodeConstructor, FormFooter },
223
+ setup(props, context) {
224
+ const postId = computed<string>(() => context.root.$route.params.postId);
225
+ const isCreation = computed<boolean>(() => postId.value === 'create');
226
+
227
+ const urlAliasChanged = ref<boolean>(false);
228
+
229
+ /** Fetch module config */
230
+ const {
231
+ data: moduleConfig,
232
+ loading: isModuleConfigLoading,
233
+ } = useModuleConfig({ context });
234
+
235
+ const languageList = computed<Language[]>(
236
+ () => moduleConfig.value?.languages ?? []
237
+ );
238
+
239
+ const languageOptionList = computed<OptionType[]>(() =>
240
+ languageList.value.map(({ id, name }) => ({
241
+ value: id,
242
+ label: name,
243
+ }))
244
+ );
245
+
246
+ const isLangSpecific = computed(() => languageOptionList.value.length > 0);
247
+
248
+ /** Fetch category list */
249
+ const {
250
+ data: categoryList,
251
+ loading: isCategoryListLoading,
252
+ } = useBlogCategoryList({ context });
253
+
254
+ /** Fetch Post */
255
+
256
+ const [fetchPost, { data: post, loading: isPostLoading }] = useResource<
257
+ Nullable<PostFull>
258
+ >({
259
+ fetchResource: () => getBlogPost(postId.value),
260
+ initialValue: null,
261
+ context,
262
+ resourceName: 'Post',
263
+ });
264
+
265
+ onMounted(() => {
266
+ if (isCreation.value) return;
267
+
268
+ fetchPost();
269
+ });
270
+
271
+ watch(postId, () => {
272
+ if (isCreation.value) return;
273
+
274
+ fetchPost();
275
+ });
276
+
277
+ /** Fetch post list */
278
+ const { data: postList, loading: isPostListLoading } = useBlogPostList({
279
+ context,
280
+ });
281
+
282
+ const postOptionList = computed<OptionType<number>[]>(() =>
283
+ postList.value
284
+ .filter((relatedPost) => relatedPost.id !== post.value?.id)
285
+ .map((post) => ({
286
+ value: post.id,
287
+ label: post.title,
288
+ }))
289
+ );
290
+
291
+ /** Form State */
292
+ const values = ref<FormValues>(
293
+ convertPostToFormValues(
294
+ post.value,
295
+ languageOptionList.value,
296
+ postOptionList.value,
297
+ moduleConfig.value?.fields ?? []
298
+ )
299
+ );
300
+ const errors = ref<Record<string, string>>({});
301
+ const isSubmitting = ref<boolean>(false);
302
+
303
+ watch([post, languageOptionList, postOptionList, moduleConfig], () => {
304
+ values.value = convertPostToFormValues(
305
+ post.value,
306
+ languageOptionList.value,
307
+ postOptionList.value,
308
+ moduleConfig.value?.fields ?? []
309
+ );
310
+ });
311
+
312
+ function submitForm(event: TagerFormSubmitEvent) {
313
+ isSubmitting.value = true;
314
+
315
+ const creationBody = convertFormValuesToCreationPayload(values.value);
316
+ const updateBody = convertFormValuesToUpdatePayload(values.value);
317
+
318
+ const requestPromise = isCreation.value
319
+ ? createBlogPost(creationBody)
320
+ : updateBlogPost(postId.value, updateBody);
321
+
322
+ requestPromise
323
+ .then(({ data }) => {
324
+ errors.value = {};
325
+
326
+ if (event.type === 'create') {
327
+ context.root.$router.push(
328
+ getBlogPostFormUrl({ postId: String(data.id) })
329
+ );
330
+ }
331
+
332
+ if (event.type === 'create_exit' || event.type === 'save_exit') {
333
+ if (context.root.$previousRoute) {
334
+ context.root.$router.back();
335
+ } else {
336
+ context.root.$router.push(getBlogPostListUrl());
337
+ }
338
+ }
339
+
340
+ if (event.type === 'create_create-another') {
341
+ values.value = convertPostToFormValues(
342
+ null,
343
+ languageOptionList.value,
344
+ postOptionList.value,
345
+ moduleConfig.value?.fields ?? []
346
+ );
347
+ }
348
+
349
+ context.root.$toast({
350
+ variant: 'success',
351
+ title: context.root.$t('blog:success'),
352
+ body: isCreation.value
353
+ ? context.root.$t('blog:blogPostWasSuccessfullyCreated')
354
+ : context.root.$t('blog:blogPostWasSuccessfullyUpdated'),
355
+ });
356
+ })
357
+ .catch((error) => {
358
+ console.error(error);
359
+ errors.value = convertRequestErrorToMap(error);
360
+ context.root.$toast({
361
+ variant: 'danger',
362
+ title: context.root.$t('blog:error'),
363
+ body: isCreation.value
364
+ ? context.root.$t('blog:blogPostCreationWasFailed')
365
+ : context.root.$t('blog:blogPostUpdateWasFailed'),
366
+ });
367
+ })
368
+ .finally(() => {
369
+ isSubmitting.value = false;
370
+ });
371
+ }
372
+
373
+ /** Category Options */
374
+
375
+ const categoryOptionList = computed<OptionType<number>[]>(() =>
376
+ convertCategoryListToOptions(
377
+ categoryList.value,
378
+ values.value.language?.value ?? null
379
+ )
380
+ );
381
+
382
+ watch([categoryOptionList, moduleConfig], () => {
383
+ function isOptionExist(
384
+ selectedCategoryOption: OptionType<number>
385
+ ): boolean {
386
+ return categoryOptionList.value.some(
387
+ (option) => option.value === selectedCategoryOption.value
388
+ );
389
+ }
390
+
391
+ if (isCreation.value) {
392
+ if (moduleConfig?.value?.defaultCategories) {
393
+ const defaultIds = moduleConfig.value.defaultCategories.map(
394
+ (item: { id: number }) => item.id
395
+ );
396
+ values.value.categories = categoryOptionList.value.filter(
397
+ (item: OptionType<number>) => {
398
+ return defaultIds.indexOf(item.value) !== -1;
399
+ }
400
+ );
401
+ }
402
+ }
403
+
404
+ values.value.categories = values.value.categories.filter(isOptionExist);
405
+ });
406
+
407
+ /** Misc */
408
+
409
+ const isContentLoading = computed<boolean>(
410
+ () =>
411
+ isPostLoading.value ||
412
+ isCategoryListLoading.value ||
413
+ isPostListLoading.value ||
414
+ isModuleConfigLoading.value
415
+ );
416
+
417
+ function getUploadAdapterOptions() {
418
+ return { uploadScenario: moduleConfig.value?.fileScenarios.content };
419
+ }
420
+
421
+ const blogPagePath = computed<string>(() => {
422
+ const origin = process.env.VUE_APP_WEBSITE_URL || window.location.origin;
423
+ return origin + (post.value?.urlTemplate ?? '');
424
+ });
425
+
426
+ const tabList = computed<TabType[]>(() => {
427
+ const hasErrors = createTabErrorFinder(errors.value);
428
+ return [
429
+ {
430
+ id: 'common',
431
+ label: context.root.$t('blog:common'),
432
+ hasErrors: hasErrors([
433
+ 'title',
434
+ 'language',
435
+ 'urlAlias',
436
+ 'excerpt',
437
+ 'body',
438
+ 'date',
439
+ ]),
440
+ },
441
+ {
442
+ id: 'images',
443
+ label: context.root.$t('blog:images'),
444
+ hasErrors: hasErrors(['coverImage', 'image']),
445
+ },
446
+ {
447
+ id: 'relations',
448
+ label: context.root.$t('blog:relations'),
449
+ hasErrors: hasErrors(['categories', 'relatedPosts', 'tags']),
450
+ },
451
+ values.value.additionalFields.length > 0
452
+ ? {
453
+ id: 'additional',
454
+ label: context.root.$t('blog:additionalFields'),
455
+ hasErrors: hasErrors([]),
456
+ }
457
+ : null,
458
+ {
459
+ id: 'seo',
460
+ label: 'SEO',
461
+ hasErrors: hasErrors([
462
+ 'pageTitle',
463
+ 'pageDescription',
464
+ 'openGraphImage',
465
+ ]),
466
+ },
467
+ ].filter(isNotNullish);
468
+ });
469
+
470
+ const selectedTabId = ref<string>(tabList.value[0].id);
471
+
472
+ const headerButtonList = computed<
473
+ { text: string; href: string; target?: string }[]
474
+ >(() =>
475
+ [
476
+ post.value
477
+ ? {
478
+ text: context.root.$t('blog:viewPost'),
479
+ href: process.env.VUE_APP_WEBSITE_URL + post.value.url,
480
+ target: '_blank',
481
+ }
482
+ : null,
483
+ ].filter(isNotNullish)
484
+ );
485
+
486
+ function handleSeoFieldGroupChange({
487
+ title,
488
+ description,
489
+ image,
490
+ }: SeoChangeEvent) {
491
+ values.value.pageTitle = title;
492
+ values.value.pageDescription = description;
493
+ values.value.openGraphImage = image;
494
+ }
495
+
496
+ function handleTitleChange(value: string) {
497
+ if (urlAliasChanged.value === false) {
498
+ values.value.urlAlias = urlTranslit(value);
499
+ }
500
+ }
501
+
502
+ function handleAliasChange() {
503
+ urlAliasChanged.value = true;
504
+ }
505
+
506
+ const urlAliasTemplate = computed<string>(() => {
507
+ if (!moduleConfig.value || !moduleConfig.value.urlPostTemplate) {
508
+ return '';
509
+ }
510
+
511
+ let result = moduleConfig.value.urlPostTemplate;
512
+
513
+ if (values.value.language) {
514
+ result = result.replace('{language}', values.value.language.value);
515
+ }
516
+
517
+ if (postId.value !== 'create') {
518
+ result = result.replace('{id}', postId.value);
519
+ }
520
+
521
+ return result;
522
+ });
523
+
524
+ return {
525
+ isCreation,
526
+ postId,
527
+ pagePath: blogPagePath,
528
+ categoryOptionList,
529
+ values,
530
+ errors,
531
+ isContentLoading,
532
+ postListUrl: getBlogPostListUrl(),
533
+ submitForm,
534
+ isLangSpecific,
535
+ languageOptionList,
536
+ isSubmitting,
537
+ moduleConfig,
538
+ postOptionList,
539
+ getUploadAdapterOptions,
540
+ tabList,
541
+ selectedTabId,
542
+ headerButtonList,
543
+ handleSeoFieldGroupChange,
544
+ handleTitleChange,
545
+ handleAliasChange,
546
+ urlAliasTemplate,
547
+ };
548
+ },
549
+ });
550
+ </script>
@@ -24,7 +24,7 @@ export default Vue.extend({
24
24
  name: 'TabList',
25
25
  props: {
26
26
  tabList: {
27
- type: Array as () => Array<TabType>,
27
+ type: Array as () => TabType[],
28
28
  required: true,
29
29
  },
30
30
  selectedTabId: {
@@ -0,0 +1 @@
1
+ export { default } from './PostForm.vue';
@@ -3,31 +3,23 @@ import { TFunction } from 'i18next';
3
3
  import { notEmpty, Nullable } from '@tager/admin-services';
4
4
  import { ColumnDefinition } from '@tager/admin-ui';
5
5
 
6
- import {
7
- BlogCategory,
8
- BlogModuleConfigType,
9
- PostShort,
10
- } from '../../typings/model';
11
- import { getBlogPostFormUrl } from '../../constants/paths';
6
+ import { Category, ModuleConfig, Language, PostShort } from '@/typings/model';
7
+ import { getBlogPostFormUrl } from '@/constants/paths';
12
8
 
13
9
  export function convertPostList(
14
- postList: Array<PostShort>,
15
- selectedCategory: Nullable<BlogCategory>,
16
- languages: BlogModuleConfigType['languages']
17
- ): Array<PostShort> {
10
+ postList: PostShort[],
11
+ selectedCategory: Nullable<Category>,
12
+ languages: Language[]
13
+ ): PostShort[] {
18
14
  return postList
19
15
  .filter((post) =>
20
16
  selectedCategory
21
- ? post.categories.some(
22
- (category) => category.id === selectedCategory.id
23
- )
17
+ ? post.categories.some(({ id }) => id === selectedCategory.id)
24
18
  : true
25
19
  )
26
20
  .map((post) => {
27
21
  if (languages.length > 0) {
28
- const foundLanguage = languages.find(
29
- (lang) => post.language === lang.id
30
- );
22
+ const foundLanguage = languages.find(({ id }) => id === post.language);
31
23
 
32
24
  return {
33
25
  ...post,
@@ -40,9 +32,9 @@ export function convertPostList(
40
32
  }
41
33
 
42
34
  export function getPostTableColumnDefs(
43
- moduleConfig: Nullable<BlogModuleConfigType>,
35
+ moduleConfig: Nullable<ModuleConfig>,
44
36
  t: TFunction
45
- ): Array<ColumnDefinition<PostShort>> {
37
+ ): ColumnDefinition<PostShort>[] {
46
38
  const isLangSpecific = moduleConfig
47
39
  ? moduleConfig.languages.length > 0
48
40
  : false;