@tager/admin-banners 0.3.2 → 0.3.6

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.
@@ -1,86 +1,97 @@
1
1
  <template>
2
2
  <page
3
- :title="
3
+ :title="
4
4
  isCreation ? $t('banners:createBanner') : $t('banners:updateBanner')
5
5
  "
6
- :is-content-loading="isContentLoading"
6
+ :is-content-loading="isContentLoading"
7
7
  >
8
8
  <template v-slot:content>
9
9
  <form novalidate @submit.prevent="submitForm">
10
- <form-field-select
11
- v-model="values.bannerZone"
12
- name="bannerZone"
13
- :label="$t('banners:zone')"
14
- :options="zonesOptionList"
15
- :error="errors.bannerZone"
16
- />
17
-
18
- <form-field-file-input
19
- v-model="values.image"
20
- name="image"
21
- file-type="image"
22
- :label="$t('banners:image')"
23
- :error="errors.file"
24
- />
25
-
26
- <form-field
27
- v-model="values.link"
28
- name="link"
29
- :label="$t('banners:link')"
30
- :error="errors.name"
31
- />
10
+ <div class="zone">
11
+ <form-field-select
12
+ v-model="values.bannerZone"
13
+ name="bannerZone"
14
+ :label="$t('banners:zone')"
15
+ :options="zonesOptionList"
16
+ :error="errors.bannerZone"
17
+ />
32
18
 
33
- <form-field-checkbox
34
- v-model="values.openNewTab"
35
- name="openNewTab"
36
- :label="$t('banners:openNewTab')"
37
- :error="errors.openNewTab"
38
- />
19
+ <form-field
20
+ v-model="values.priority"
21
+ name="priority"
22
+ :label="$t('banners:priority')"
23
+ :error="errors.priority"
24
+ />
25
+ </div>
39
26
 
40
27
  <input-label>{{ $t('banners:period') }}</input-label>
41
28
 
42
29
  <div class="date">
43
30
  <form-field
44
- v-model="values.dateStart"
45
- :label="$t('banners:from')"
46
- name="dateStart"
47
- type="date"
48
- :max="values.dateEnd"
31
+ v-model="values.dateStart"
32
+ :label="$t('banners:from')"
33
+ name="dateStart"
34
+ type="date"
35
+ :max="values.dateEnd"
49
36
  />
50
37
 
51
38
  <form-field
52
- v-model="values.dateEnd"
53
- :label="$t('banners:to')"
54
- name="dateEnd"
55
- type="date"
56
- :min="values.dateStart"
39
+ v-model="values.dateEnd"
40
+ :label="$t('banners:to')"
41
+ name="dateEnd"
42
+ type="date"
43
+ :min="values.dateStart"
57
44
  />
58
45
  </div>
59
46
 
60
47
  <form-field-checkbox
61
- v-model="values.disabled"
62
- name="disabled"
63
- :label="$t('banners:disabled')"
64
- :error="errors.disabled"
48
+ v-model="values.disabled"
49
+ name="disabled"
50
+ :label="$t('banners:disabled')"
51
+ :error="errors.disabled"
52
+ />
53
+
54
+ <div class="link">
55
+ <form-field
56
+ v-model="values.link"
57
+ name="link"
58
+ :label="$t('banners:link')"
59
+ :error="errors.name"
60
+ />
61
+
62
+ <form-field-checkbox
63
+ v-model="values.openNewTab"
64
+ name="openNewTab"
65
+ :label="$t('banners:openNewTab')"
66
+ :error="errors.openNewTab"
67
+ />
68
+ </div>
69
+
70
+ <form-field-file-input
71
+ v-model="values.image"
72
+ name="image"
73
+ file-type="image"
74
+ :label="$t('banners:image')"
75
+ :error="errors.file"
65
76
  />
66
77
 
67
78
  <form-field
68
- v-model="values.comment"
69
- name="comment"
70
- type="textarea"
71
- :label="$t('banners:comment')"
72
- :error="errors.comment"
79
+ v-model="values.comment"
80
+ name="comment"
81
+ type="textarea"
82
+ :label="$t('banners:comment')"
83
+ :error="errors.comment"
73
84
  />
74
85
  </form>
75
86
  </template>
76
87
 
77
88
  <template v-slot:footer>
78
89
  <FormFooter
79
- :back-href="bannerListUrl"
80
- :on-submit="submitForm"
81
- :is-submitting="isSubmitting"
82
- :is-creation="isCreation"
83
- :can-create-another="isCreation"
90
+ :back-href="bannerListUrl"
91
+ :on-submit="submitForm"
92
+ :is-submitting="isSubmitting"
93
+ :is-creation="isCreation"
94
+ :can-create-another="isCreation"
84
95
  />
85
96
  </template>
86
97
  </page>
@@ -95,17 +106,17 @@ import {
95
106
  watch,
96
107
  } from '@vue/composition-api';
97
108
 
98
- import { FormFooter, OptionType, TagerFormSubmitEvent } from '@tager/admin-ui';
99
- import { convertRequestErrorToMap } from '@tager/admin-services';
109
+ import {FormFooter, OptionType, TagerFormSubmitEvent} from '@tager/admin-ui';
110
+ import {convertRequestErrorToMap} from '@tager/admin-services';
100
111
 
101
- import { useFetchZones } from '../../../hooks';
102
- import { BannerFormValues } from '../../../typings/banners';
103
- import { useFetchBanner } from '../../../hooks/useFetchBanner';
112
+ import {useFetchZones} from '../../../hooks';
113
+ import {BannerFormValues} from '../../../typings/banners';
114
+ import {useFetchBanner} from '../../../hooks/useFetchBanner';
104
115
  import {
105
116
  getBannersBannerFormUrl,
106
117
  getBannersBannerListUrl,
107
118
  } from '../../../constants/paths';
108
- import { createBanner, updateBanner } from '../../../services/requests';
119
+ import {createBanner, updateBanner} from '../../../services/requests';
109
120
 
110
121
  import {
111
122
  convertBannerFormValuesToPayload,
@@ -114,27 +125,27 @@ import {
114
125
 
115
126
  export default defineComponent({
116
127
  name: 'BannerForm',
117
- components: { FormFooter },
128
+ components: {FormFooter},
118
129
  setup(props, context: SetupContext) {
119
130
  const bannerId = computed<string>(
120
- () => context.root.$route.params.bannerId
131
+ () => context.root.$route.params.bannerId
121
132
  );
122
133
  const isCreation = computed<boolean>(() => bannerId.value === 'create');
123
134
 
124
135
  /** Zones **/
125
136
 
126
- const { data: zones, loading: isZonesLoading } = useFetchZones({ context });
137
+ const {data: zones, loading: isZonesLoading} = useFetchZones({context});
127
138
 
128
139
  const zonesOptionList = computed<OptionType[]>(() =>
129
- zones.value.map<OptionType>((zone) => ({
130
- value: zone.id,
131
- label: zone.name,
132
- }))
140
+ zones.value.map<OptionType>((zone) => ({
141
+ value: zone.id,
142
+ label: zone.name,
143
+ }))
133
144
  );
134
145
 
135
146
  /** Banner **/
136
147
 
137
- const { data: banner, loading: isBannerLoading } = useFetchBanner({
148
+ const {data: banner, loading: isBannerLoading} = useFetchBanner({
138
149
  context,
139
150
  bannerId,
140
151
  isCreation,
@@ -144,14 +155,14 @@ export default defineComponent({
144
155
 
145
156
  const isSubmitting = ref<boolean>(false);
146
157
  const values = ref<BannerFormValues>(
147
- convertBannerToFormValues(banner.value, zonesOptionList.value)
158
+ convertBannerToFormValues(banner.value, zonesOptionList.value)
148
159
  );
149
160
  const errors = ref<Record<string, string>>({});
150
161
 
151
162
  watch([banner, zones], () => {
152
163
  values.value = convertBannerToFormValues(
153
- banner.value,
154
- zonesOptionList.value
164
+ banner.value,
165
+ zonesOptionList.value
155
166
  );
156
167
  });
157
168
 
@@ -161,56 +172,56 @@ export default defineComponent({
161
172
  const body = convertBannerFormValuesToPayload(values.value);
162
173
 
163
174
  const requestPromise = isCreation.value
164
- ? createBanner(body)
165
- : updateBanner(bannerId.value, body);
175
+ ? createBanner(body)
176
+ : updateBanner(bannerId.value, body);
166
177
 
167
178
  requestPromise
168
- .then(({ data }) => {
169
- errors.value = {};
170
-
171
- if (event.type === 'create') {
172
- context.root.$router.push(
173
- getBannersBannerFormUrl({ bannerId: String(data.id) })
174
- );
175
- }
176
-
177
- if (event.type === 'create_exit' || event.type === 'save_exit') {
178
- context.root.$router.push(getBannersBannerListUrl());
179
- }
180
-
181
- if (event.type === 'create_create-another') {
182
- values.value = convertBannerToFormValues(
183
- null,
184
- zonesOptionList.value
185
- );
186
- }
187
-
188
- context.root.$toast({
189
- variant: 'success',
190
- title: context.root.$t('banners:success'),
191
- body: isCreation.value
192
- ? context.root.$t('banners:bannerWasSuccessfullyCreated')
193
- : context.root.$t('banners:bannerWasSuccessfullyUpdated'),
179
+ .then(({data}) => {
180
+ errors.value = {};
181
+
182
+ if (event.type === 'create') {
183
+ context.root.$router.push(
184
+ getBannersBannerFormUrl({bannerId: String(data.id)})
185
+ );
186
+ }
187
+
188
+ if (event.type === 'create_exit' || event.type === 'save_exit') {
189
+ context.root.$router.push(getBannersBannerListUrl());
190
+ }
191
+
192
+ if (event.type === 'create_create-another') {
193
+ values.value = convertBannerToFormValues(
194
+ null,
195
+ zonesOptionList.value
196
+ );
197
+ }
198
+
199
+ context.root.$toast({
200
+ variant: 'success',
201
+ title: context.root.$t('banners:success'),
202
+ body: isCreation.value
203
+ ? context.root.$t('banners:bannerWasSuccessfullyCreated')
204
+ : context.root.$t('banners:bannerWasSuccessfullyUpdated'),
205
+ });
206
+ })
207
+ .catch((error) => {
208
+ console.error(error);
209
+ errors.value = convertRequestErrorToMap(error);
210
+ context.root.$toast({
211
+ variant: 'danger',
212
+ title: context.root.$t('banners:error'),
213
+ body: isCreation.value
214
+ ? context.root.$t('banners:bannerCreationWasFailed')
215
+ : context.root.$t('banners:bannerUpdateWasFailed'),
216
+ });
217
+ })
218
+ .finally(() => {
219
+ isSubmitting.value = false;
194
220
  });
195
- })
196
- .catch((error) => {
197
- console.error(error);
198
- errors.value = convertRequestErrorToMap(error);
199
- context.root.$toast({
200
- variant: 'danger',
201
- title: context.root.$t('banners:error'),
202
- body: isCreation.value
203
- ? context.root.$t('banners:bannerCreationWasFailed')
204
- : context.root.$t('banners:bannerUpdateWasFailed'),
205
- });
206
- })
207
- .finally(() => {
208
- isSubmitting.value = false;
209
- });
210
221
  };
211
222
 
212
223
  const isContentLoading = computed<boolean>(
213
- () => isBannerLoading.value || isZonesLoading.value
224
+ () => isBannerLoading.value || isZonesLoading.value
214
225
  );
215
226
 
216
227
  return {
@@ -233,4 +244,32 @@ export default defineComponent({
233
244
  grid-template-columns: repeat(2, 1fr);
234
245
  column-gap: 10px;
235
246
  }
247
+
248
+ .zone {
249
+ display: flex;
250
+
251
+ > *:first-child {
252
+ flex: 1 1 1px;
253
+ }
254
+
255
+ > *:last-child {
256
+ flex-basis: 30%;
257
+ margin-left: 20px;
258
+ }
259
+ }
260
+
261
+ .link {
262
+ display: flex;
263
+ align-items: flex-end;
264
+
265
+ > *:first-child {
266
+ flex: 1 1 1px;
267
+ }
268
+
269
+ > *:last-child {
270
+ flex-basis: 30%;
271
+ margin-left: 20px;
272
+ padding-bottom: 8px;
273
+ }
274
+ }
236
275
  </style>
@@ -3,6 +3,7 @@ import { TFunction } from 'i18next';
3
3
  import { ColumnDefinition } from '@tager/admin-ui';
4
4
 
5
5
  import { Banner, Status } from '../../../typings/banners';
6
+ import { Zone } from '../../../typings/zones';
6
7
 
7
8
  export function getStatus(type: Status, t: TFunction) {
8
9
  switch (type) {
@@ -20,12 +21,16 @@ export function getStatus(type: Status, t: TFunction) {
20
21
  }
21
22
  }
22
23
 
23
- export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
24
+ export function getColumnDefs(
25
+ zoneList: Zone[],
26
+ t: TFunction
27
+ ): ColumnDefinition<Banner>[] {
24
28
  return [
25
29
  {
26
30
  id: 0,
27
31
  name: '#',
28
32
  field: 'id',
33
+ format: ({ rowIndex }) => String(rowIndex + 1),
29
34
  style: { width: '50px', textAlign: 'center' },
30
35
  headStyle: { width: '50px', textAlign: 'center' },
31
36
  },
@@ -33,8 +38,14 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
33
38
  id: 1,
34
39
  name: t('banners:zone'),
35
40
  field: 'bannerZone',
36
- format: ({ row }) =>
37
- row.bannerZone ? row.bannerZone : t('banners:bannerZoneIsDeleted'),
41
+ format: ({ row }) => {
42
+ const foundBannerZone = zoneList.find(
43
+ (zone) => zone.id === row.bannerZone
44
+ );
45
+ return foundBannerZone
46
+ ? foundBannerZone.name
47
+ : t('banners:bannerZoneIsDeleted');
48
+ },
38
49
  },
39
50
  {
40
51
  id: 2,
@@ -46,6 +57,13 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
46
57
  },
47
58
  {
48
59
  id: 3,
60
+ name: t('banners:priority'),
61
+ field: 'priority',
62
+ style: { width: '100px', textAlign: 'center' },
63
+ headStyle: { width: '100px', textAlign: 'center' },
64
+ },
65
+ {
66
+ id: 4,
49
67
  name: t('banners:period'),
50
68
  field: 'dateStart',
51
69
  format: ({ row }) =>
@@ -54,13 +72,13 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
54
72
  }`,
55
73
  },
56
74
  {
57
- id: 4,
75
+ id: 5,
58
76
  name: t('banners:image'),
59
77
  field: 'image',
60
78
  type: 'image',
61
79
  },
62
80
  {
63
- id: 5,
81
+ id: 6,
64
82
  name: t('banners:link'),
65
83
  field: 'link',
66
84
  type: 'name',
@@ -76,14 +94,17 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
76
94
  },
77
95
  ],
78
96
  }),
97
+ options: {
98
+ shouldOpenNewTab: true,
99
+ },
79
100
  },
80
101
  {
81
- id: 6,
102
+ id: 7,
82
103
  name: t('banners:comment'),
83
104
  field: 'comment',
84
105
  },
85
106
  {
86
- id: 7,
107
+ id: 8,
87
108
  name: t('banners:actions'),
88
109
  field: 'actions',
89
110
  style: { whiteSpace: 'nowrap', width: '100px' },
@@ -181,7 +181,7 @@ export default defineComponent({
181
181
  };
182
182
 
183
183
  const columnDefs = computed<ColumnDefinition<Banner>[]>(() =>
184
- getColumnDefs(context.root.$t)
184
+ getColumnDefs(zoneList.value, context.root.$t)
185
185
  );
186
186
 
187
187
  const isRowDataLoading = computed<boolean>(
@@ -112,7 +112,7 @@ export function useAdvancedSearch({ context, t, zoneList }: Params): State {
112
112
  const filterParams = computed(() =>
113
113
  getFilterParams({
114
114
  [FilterTypes.Zone]: zoneFilter.value.map(({ value }) => value),
115
- [FilterTypes.Date]: dateFilter.value,
115
+ [FilterTypes.Date]: dateFilter.value || [],
116
116
  [FilterTypes.Status]: statusFilter.value.map(({ value }) => value),
117
117
  })
118
118
  );