@tager/admin-banners 0.2.1 → 0.3.3

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 (77) hide show
  1. package/dist/constants/menu.d.ts +4 -1
  2. package/dist/constants/paths.d.ts +8 -15
  3. package/dist/constants/routes.d.ts +3 -4
  4. package/dist/hooks/index.d.ts +2 -0
  5. package/dist/hooks/useFetchBanner.d.ts +8 -0
  6. package/dist/hooks/useFetchBanners.d.ts +6 -0
  7. package/dist/hooks/useFetchZones.d.ts +6 -0
  8. package/dist/index.esm.js +3207 -891
  9. package/dist/index.umd.js +3221 -902
  10. package/dist/locales/en.d.ts +39 -0
  11. package/dist/locales/ru.d.ts +3 -0
  12. package/dist/{index.d.ts → main.d.ts} +1 -0
  13. package/dist/router/index.d.ts +4 -0
  14. package/dist/services/requests.d.ts +22 -35
  15. package/dist/typings/banners.d.ts +40 -0
  16. package/dist/typings/common.d.ts +1 -0
  17. package/dist/typings/model.d.ts +103 -15
  18. package/dist/typings/zones.d.ts +5 -0
  19. package/dist/utils/common.d.ts +2 -0
  20. package/dist/views/Banners/BannerForm/BannerForm.helpers.d.ts +5 -0
  21. package/dist/views/Banners/BannerForm/BannerForm.vue.d.ts +81 -0
  22. package/dist/views/Banners/BannerForm/index.d.ts +1 -0
  23. package/dist/views/Banners/BannerList/BannerList.helpers.d.ts +5 -0
  24. package/dist/views/Banners/BannerList/BannerList.vue.d.ts +55 -0
  25. package/dist/views/Banners/BannerList/hooks/index.d.ts +1 -0
  26. package/dist/views/Banners/BannerList/hooks/useAdvancedSearch.d.ts +21 -0
  27. package/dist/views/Banners/BannerList/index.d.ts +1 -0
  28. package/dist/views/Zones/ZoneList/ZoneList.helpers.d.ts +5 -0
  29. package/dist/views/Zones/ZoneList/ZoneList.vue.d.ts +28 -0
  30. package/dist/views/Zones/ZoneList/index.d.ts +1 -0
  31. package/package.json +32 -23
  32. package/src/config/config.json +1 -1
  33. package/src/constants/menu.ts +24 -9
  34. package/src/constants/paths.ts +10 -27
  35. package/src/constants/routes.ts +27 -49
  36. package/src/dev.ts +22 -34
  37. package/src/hooks/index.ts +2 -0
  38. package/src/hooks/useFetchBanner.ts +41 -0
  39. package/src/hooks/useFetchBanners.ts +23 -0
  40. package/src/hooks/useFetchZones.ts +23 -0
  41. package/src/locales/en.ts +43 -0
  42. package/src/locales/ru.ts +45 -0
  43. package/src/main.ts +12 -0
  44. package/src/router/index.ts +38 -0
  45. package/src/services/requests.ts +35 -86
  46. package/src/typings/banners.ts +44 -0
  47. package/src/typings/common.ts +1 -0
  48. package/src/typings/model.ts +119 -16
  49. package/src/typings/shims-vue.d.ts +1 -0
  50. package/src/typings/translate.d.ts +10 -0
  51. package/src/typings/zones.ts +5 -0
  52. package/src/utils/common.ts +13 -0
  53. package/src/views/App.vue +7 -7
  54. package/src/views/Banners/BannerForm/BannerForm.helpers.ts +38 -0
  55. package/src/views/Banners/BannerForm/BannerForm.vue +236 -0
  56. package/src/views/Banners/BannerForm/index.ts +1 -0
  57. package/src/views/Banners/BannerList/BannerList.helpers.ts +93 -0
  58. package/src/views/Banners/BannerList/BannerList.vue +233 -0
  59. package/src/views/Banners/BannerList/hooks/index.ts +1 -0
  60. package/src/views/Banners/BannerList/hooks/useAdvancedSearch.ts +152 -0
  61. package/src/views/Banners/BannerList/index.ts +1 -0
  62. package/src/views/Home.vue +37 -0
  63. package/src/views/Zones/ZoneList/ZoneList.helpers.ts +34 -0
  64. package/src/views/Zones/ZoneList/ZoneList.vue +75 -0
  65. package/src/views/Zones/ZoneList/index.ts +1 -0
  66. package/dist/views/BannerAreaForm.vue.d.ts +0 -22
  67. package/dist/views/BannerAreaList.vue.d.ts +0 -17
  68. package/dist/views/BannerItemForm.vue.d.ts +0 -27
  69. package/dist/views/BannerItemList.vue.d.ts +0 -22
  70. package/src/index.ts +0 -3
  71. package/src/locales/en.js +0 -3
  72. package/src/locales/ru.js +0 -3
  73. package/src/views/BannerAreaForm.vue +0 -173
  74. package/src/views/BannerAreaList.vue +0 -176
  75. package/src/views/BannerItemForm.vue +0 -231
  76. package/src/views/BannerItemList.vue +0 -221
  77. package/typings/index.d.ts +0 -15
@@ -1,173 +0,0 @@
1
- <template>
2
- <page
3
- :title="isCreation ? 'Create Banner Area' : 'Update Banner Area'"
4
- :is-content-loading="isContentLoading"
5
- :footer="{ onSubmit: submitForm, backHref: getAreaListUrl() }"
6
- >
7
- <template v-slot:content>
8
- <form novalidate @submit.prevent="submitForm">
9
- <form-field
10
- v-model="values.alias"
11
- name="alias"
12
- label="Alias"
13
- :error="errors.alias"
14
- />
15
-
16
- <form-field
17
- v-model="values.label"
18
- name="label"
19
- label="Label"
20
- :error="errors.label"
21
- />
22
-
23
- <form-field
24
- v-model="values.scenario"
25
- name="scenario"
26
- label="Scenario"
27
- :error="errors.scenario"
28
- />
29
- </form>
30
- </template>
31
- </page>
32
- </template>
33
-
34
- <script lang="ts">
35
- import Vue from 'vue';
36
- import { convertRequestErrorToMap } from '@tager/admin-services';
37
-
38
- import {
39
- BannerAreaCreatePayload,
40
- createBannerArea,
41
- getBannerAreaById,
42
- updateBannerArea,
43
- } from '../services/requests';
44
- import { BannerArea } from '../typings/model';
45
- import { getBannerAreaListUrl } from '../constants/paths';
46
-
47
- type FormValues = {
48
- alias: string;
49
- label: string;
50
- scenario: string;
51
- };
52
-
53
- const initialValues: FormValues = {
54
- alias: '',
55
- label: '',
56
- scenario: '',
57
- };
58
-
59
- export default Vue.extend({
60
- name: 'BannerAreaForm',
61
- data(): {
62
- values: FormValues;
63
- errors: Record<string, string>;
64
- isContentLoading: boolean;
65
- } {
66
- return {
67
- values: { ...initialValues },
68
- errors: {},
69
- isContentLoading: false,
70
- };
71
- },
72
- computed: {
73
- areaId(): string {
74
- return this.$route.params.areaId;
75
- },
76
- isCreation(): boolean {
77
- return this.areaId === 'create';
78
- },
79
- },
80
- watch: {
81
- areaId() {
82
- this.updateValues();
83
- },
84
- },
85
- mounted(): void {
86
- this.updateValues();
87
- },
88
- methods: {
89
- convertReviewToInitialValues(bannerArea: BannerArea): FormValues {
90
- return {
91
- alias: bannerArea.alias,
92
- label: bannerArea.label,
93
- scenario: bannerArea.scenario,
94
- };
95
- },
96
- updateValues() {
97
- if (this.isCreation) {
98
- this.values = { ...initialValues };
99
- } else {
100
- this.isContentLoading = true;
101
-
102
- getBannerAreaById(this.areaId)
103
- .then((response) => {
104
- this.values = this.convertReviewToInitialValues(response.data);
105
- })
106
- .catch(console.error)
107
- .finally(() => {
108
- this.isContentLoading = false;
109
- });
110
- }
111
- },
112
- submitForm() {
113
- const body: BannerAreaCreatePayload = {
114
- label: this.values.label,
115
- alias: this.values.alias,
116
- scenario: this.values.scenario,
117
- };
118
-
119
- const requestPromise = this.isCreation
120
- ? createBannerArea(body)
121
- : updateBannerArea(this.areaId, body);
122
-
123
- requestPromise
124
- .then(() => {
125
- this.errors = {};
126
- this.$router.push(getBannerAreaListUrl());
127
-
128
- this.$toast({
129
- variant: 'success',
130
- title: 'Success',
131
- body: `Banner Area was successfully ${
132
- this.isCreation ? 'created' : 'updated'
133
- }`,
134
- });
135
- })
136
- .catch((error) => {
137
- console.error(error);
138
- this.errors = convertRequestErrorToMap(error);
139
- this.$toast({
140
- variant: 'danger',
141
- title: 'Error',
142
- body: `Blog bannerArea ${
143
- this.isCreation ? 'creation' : 'update'
144
- } was failed`,
145
- });
146
- });
147
- },
148
- getAreaListUrl: getBannerAreaListUrl,
149
- },
150
- });
151
- </script>
152
-
153
- <style scoped lang="scss">
154
- .bottom {
155
- display: flex;
156
- justify-content: space-between;
157
- align-items: center;
158
- }
159
-
160
- .save-button {
161
- min-width: 100px;
162
- }
163
-
164
- .alias-field-inner {
165
- display: flex;
166
- align-items: center;
167
-
168
- span {
169
- font-size: 0.9em;
170
- margin-right: 10px;
171
- }
172
- }
173
- </style>
@@ -1,176 +0,0 @@
1
- <template>
2
- <page
3
- title="Banner Areas"
4
- :header-buttons="[
5
- { text: 'New banner area', href: getBannerAreaUrl('create') },
6
- ]"
7
- >
8
- <template v-slot:content>
9
- <base-table
10
- :column-defs="columnDefs"
11
- :row-data="rowData"
12
- :loading="isRowDataLoading"
13
- :error-message="errorMessage"
14
- >
15
- <template v-slot:cell(link-to-banner-items)="{ row }">
16
- <base-button
17
- :href="getLinkToBannerItems(row.alias)"
18
- variant="outline-secondary"
19
- >
20
- Banner Items
21
- </base-button>
22
- </template>
23
-
24
- <template v-slot:cell(actions)="{ row }">
25
- <base-button
26
- variant="icon"
27
- title="Edit"
28
- :disabled="deletingBannerAreaIdList.includes(row.id)"
29
- :href="getBannerAreaUrl(row.id)"
30
- >
31
- <svg-icon name="edit"></svg-icon>
32
- </base-button>
33
- <base-button
34
- variant="icon"
35
- title="Remove"
36
- :disabled="deletingBannerAreaIdList.includes(row.id)"
37
- @click="handleBannerAreaDelete(row)"
38
- >
39
- <svg-icon name="delete"></svg-icon>
40
- </base-button>
41
- </template>
42
- </base-table>
43
- </template>
44
- </page>
45
- </template>
46
-
47
- <script lang="ts">
48
- import Vue from 'vue';
49
- import { ColumnDefinition } from '@tager/admin-ui';
50
- import { getMessageFromError, Nullable } from '@tager/admin-services';
51
-
52
- import { BannerArea } from '../typings/model';
53
- import { deleteBannerArea, getBannerAreaList } from '../services/requests';
54
- import { getBannerAreaFormUrl, getBannerItemListUrl } from '../constants/paths';
55
-
56
- const COLUMN_DEFS: Array<ColumnDefinition<BannerArea>> = [
57
- {
58
- id: 1,
59
- name: 'ID',
60
- field: 'id',
61
- style: { width: '50px', textAlign: 'center' },
62
- headStyle: { width: '50px', textAlign: 'center' },
63
- },
64
- { id: 2, name: 'Alias', field: 'alias' },
65
- { id: 3, name: 'Label', field: 'label' },
66
- { id: 4, name: 'Scenario', field: 'scenario' },
67
- {
68
- id: 6,
69
- name: 'Banner Items',
70
- field: 'linkToBannerItems',
71
- style: { whiteSpace: 'nowrap', width: '120px', textAlign: 'center' },
72
- headStyle: { whiteSpace: 'nowrap', width: '120px', textAlign: 'center' },
73
- },
74
- {
75
- id: 8,
76
- name: 'Actions',
77
- field: 'actions',
78
- style: { whiteSpace: 'nowrap', width: '110px', textAlign: 'center' },
79
- headStyle: { whiteSpace: 'nowrap', width: '110px', textAlign: 'center' },
80
- },
81
- ];
82
-
83
- export default Vue.extend({
84
- name: 'BannerAreaList',
85
- data(): {
86
- columnDefs: Array<ColumnDefinition<BannerArea>>;
87
- rowData: Array<BannerArea>;
88
- deletingBannerAreaIdList: Array<number>;
89
- isRowDataLoading: boolean;
90
- errorMessage: Nullable<string>;
91
- } {
92
- return {
93
- columnDefs: COLUMN_DEFS,
94
- rowData: [],
95
- deletingBannerAreaIdList: [],
96
- isRowDataLoading: false,
97
- errorMessage: null,
98
- };
99
- },
100
- mounted(): void {
101
- this.refreshBannerAreaList();
102
- },
103
- methods: {
104
- getBannerAreaUrl(areaId: number | string): string {
105
- return getBannerAreaFormUrl({ areaId });
106
- },
107
- refreshBannerAreaList(): Promise<void> {
108
- this.isRowDataLoading = true;
109
-
110
- return getBannerAreaList()
111
- .then((response) => {
112
- this.rowData = response.data;
113
- this.errorMessage = null;
114
- })
115
- .catch((error) => {
116
- console.error(error);
117
- this.rowData = [];
118
- this.errorMessage = getMessageFromError(error);
119
- })
120
- .finally(() => {
121
- this.isRowDataLoading = false;
122
- });
123
- },
124
- handleBannerAreaDelete(bannerArea: BannerArea) {
125
- const shouldDeleteBannerArea = confirm(
126
- `Are you sure you want to delete banner area "${bannerArea.label}"`
127
- );
128
-
129
- if (!shouldDeleteBannerArea) return;
130
-
131
- this.deletingBannerAreaIdList.push(bannerArea.id);
132
-
133
- deleteBannerArea(bannerArea.id)
134
- .then((response) => {
135
- if (response.success) {
136
- this.refreshBannerAreaList().then(() => {
137
- this.deletingBannerAreaIdList.filter(
138
- (id) => id !== bannerArea.id
139
- );
140
- });
141
- this.$toast({
142
- variant: 'success',
143
- title: 'Success',
144
- body: 'Banner area was successfully removed',
145
- });
146
- } else {
147
- this.$toast({
148
- variant: 'danger',
149
- title: 'Error',
150
- body: 'Banner area deletion was failed',
151
- });
152
- }
153
- })
154
- .catch((error) => {
155
- console.error(error);
156
- this.$toast({
157
- variant: 'danger',
158
- title: 'Error',
159
- body: 'Banner area deletion was failed',
160
- });
161
- });
162
- },
163
- getLinkToBannerItems(areaAlias: string) {
164
- return getBannerItemListUrl({ areaAlias });
165
- },
166
- },
167
- });
168
- </script>
169
-
170
- <style scoped lang="scss">
171
- .actions-cell {
172
- button:not(:last-child) {
173
- margin-right: 0.5rem;
174
- }
175
- }
176
- </style>
@@ -1,231 +0,0 @@
1
- <template>
2
- <page
3
- :title="isCreation ? 'Create Banner Item' : 'Update Banner Item'"
4
- :is-content-loading="isContentLoading"
5
- :footer="{ onSubmit: submitForm, backHref: bannerItemListUrl }"
6
- >
7
- <template v-slot:content>
8
- <form novalidate @submit.prevent>
9
- <form-field
10
- v-model="values.title"
11
- name="title"
12
- label="Title"
13
- :error="errors.title"
14
- type="textarea"
15
- />
16
-
17
- <form-field-rich-text-input
18
- v-model="values.text"
19
- name="text"
20
- label="Text"
21
- :error="errors.text"
22
- />
23
-
24
- <form-field-file-input
25
- v-model="values.image"
26
- label="Image"
27
- name="image"
28
- file-type="image"
29
- />
30
-
31
- <form-field
32
- v-model="values.buttonLabel"
33
- name="buttonLabel"
34
- label="Button: Label"
35
- :error="errors.buttonLabel"
36
- />
37
-
38
- <form-field
39
- v-model="values.buttonLink"
40
- name="buttonLink"
41
- label="Button: Link"
42
- :error="errors.buttonLink"
43
- />
44
-
45
- <form-field-checkbox
46
- v-model="values.buttonIsNewTab"
47
- name="buttonIsNewTab"
48
- label="Button: Is new tab?"
49
- :error="errors.buttonIsNewTab"
50
- />
51
- </form>
52
- </template>
53
- </page>
54
- </template>
55
-
56
- <script lang="ts">
57
- import Vue from 'vue';
58
- import {
59
- convertRequestErrorToMap,
60
- FileType,
61
- Nullable,
62
- } from '@tager/admin-services';
63
-
64
- import {
65
- BannerItemCreatePayload,
66
- createBannerItem,
67
- getBannerAreaByAlias,
68
- getBannerItemById,
69
- updateBannerItem,
70
- } from '../services/requests';
71
- import { BannerArea, BannerItem } from '../typings/model';
72
- import { getBannerItemListUrl } from '../constants/paths';
73
-
74
- type FormValues = {
75
- title: string;
76
- text: string;
77
- buttonLink: string;
78
- buttonLabel: string;
79
- buttonIsNewTab: boolean;
80
- image: Nullable<FileType>;
81
- };
82
-
83
- const INITIAL_VALUES: FormValues = {
84
- title: '',
85
- text: '',
86
- buttonLink: '',
87
- buttonLabel: '',
88
- buttonIsNewTab: false,
89
- image: null,
90
- };
91
-
92
- export default Vue.extend({
93
- name: 'BannerItemForm',
94
- data(): {
95
- values: FormValues;
96
- errors: Record<string, string>;
97
- isContentLoading: boolean;
98
- bannerArea: Nullable<BannerArea>;
99
- } {
100
- return {
101
- values: { ...INITIAL_VALUES },
102
- errors: {},
103
- isContentLoading: false,
104
- bannerArea: null,
105
- };
106
- },
107
- computed: {
108
- itemId(): string {
109
- return this.$route.params.itemId;
110
- },
111
- areaAlias(): string {
112
- return this.$route.params.areaAlias;
113
- },
114
- isCreation(): boolean {
115
- return this.itemId === 'create';
116
- },
117
- bannerItemListUrl(): string {
118
- return getBannerItemListUrl({
119
- areaAlias: this.bannerArea?.alias ?? 'unknown',
120
- });
121
- },
122
- },
123
- watch: {
124
- itemId() {
125
- this.updateValues();
126
- },
127
- areaAlias() {
128
- this.updateValues();
129
- },
130
- },
131
- mounted(): void {
132
- this.updateValues();
133
- },
134
- methods: {
135
- updateValues(): void {
136
- this.isContentLoading = true;
137
-
138
- Promise.all([
139
- getBannerAreaByAlias(this.areaAlias)
140
- .then((response) => {
141
- this.bannerArea = response.data;
142
- })
143
- .catch(console.error),
144
- this.isCreation
145
- ? new Promise((resolve) => {
146
- this.values = { ...INITIAL_VALUES };
147
- resolve();
148
- })
149
- : getBannerItemById(this.itemId)
150
- .then((response) => {
151
- this.values = this.convertReviewToInitialValues(response.data);
152
- })
153
- .catch(console.error),
154
- ]).finally(() => {
155
- this.isContentLoading = false;
156
- });
157
- },
158
- convertReviewToInitialValues(bannerItem: BannerItem): FormValues {
159
- return {
160
- title: bannerItem.title,
161
- text: bannerItem.text,
162
- buttonLink: bannerItem.buttonLink ?? '',
163
- buttonLabel: bannerItem.buttonLabel,
164
- buttonIsNewTab: bannerItem.buttonIsNewTab,
165
- image: bannerItem.image,
166
- };
167
- },
168
- submitForm() {
169
- const creationBody: BannerItemCreatePayload = {
170
- title: this.values.title,
171
- text: this.values.text,
172
- buttonLink: this.values.buttonLink.trim() || null,
173
- buttonLabel: this.values.buttonLabel,
174
- buttonIsNewTab: this.values.buttonIsNewTab,
175
- image: this.values.image?.id ?? null,
176
- };
177
-
178
- const requestPromise = this.isCreation
179
- ? createBannerItem(this.bannerArea?.id ?? 'unknown', creationBody)
180
- : updateBannerItem(this.itemId, creationBody);
181
-
182
- requestPromise
183
- .then(() => {
184
- this.errors = {};
185
- this.$router.push(this.bannerItemListUrl);
186
-
187
- this.$toast({
188
- variant: 'success',
189
- title: 'Success',
190
- body: `Banner item has been successfully ${
191
- this.isCreation ? 'created' : 'updated'
192
- }`,
193
- });
194
- })
195
- .catch((error) => {
196
- console.error(error);
197
- this.errors = convertRequestErrorToMap(error);
198
- this.$toast({
199
- variant: 'danger',
200
- title: 'Error',
201
- body: `Banner item ${
202
- this.isCreation ? 'creation' : 'update'
203
- } has been failed`,
204
- });
205
- });
206
- },
207
- },
208
- });
209
- </script>
210
-
211
- <style scoped lang="scss">
212
- .bottom {
213
- display: flex;
214
- justify-content: space-between;
215
- align-items: center;
216
- }
217
-
218
- .save-button {
219
- min-width: 100px;
220
- }
221
-
222
- .alias-field-inner {
223
- display: flex;
224
- align-items: center;
225
-
226
- span {
227
- font-size: 0.9em;
228
- margin-right: 10px;
229
- }
230
- }
231
- </style>