|
7 | 7 | <span v-if="bounces.total > 0">({{ bounces.total }})</span> |
8 | 8 | </h1> |
9 | 9 | </div> |
10 | | - <div class="column has-text-right buttons"> |
11 | | - <b-button v-if="bulk.checked.length > 0 || bulk.all" type="is-primary" icon-left="trash-can-outline" |
12 | | - data-cy="btn-delete" @click.prevent="$utils.confirm(null, () => deleteBounces())"> |
13 | | - {{ $t('globals.buttons.clear') }} |
14 | | - </b-button> |
15 | | - <b-button v-if="bounces.total" icon-left="trash-can-outline" data-cy="btn-delete" |
16 | | - @click.prevent="$utils.confirm(null, () => deleteBounces(true))"> |
17 | | - {{ $t('globals.buttons.clearAll') }} |
18 | | - </b-button> |
19 | | - </div> |
20 | 10 | </header> |
21 | 11 |
|
22 | 12 | <b-table :data="bounces.results" :hoverable="true" :loading="loading.bounces" default-sort="createdAt" checkable |
23 | 13 | @check-all="onTableCheck" @check="onTableCheck" :checked-rows.sync="bulk.checked" detailed show-detail-icon |
24 | | - paginated backend-pagination pagination-position="both" @page-change="onPageChange" :current-page="queryParams.page" :per-page="bounces.perPage" |
25 | | - :total="bounces.total" backend-sorting @sort="onSort"> |
| 14 | + paginated backend-pagination pagination-position="both" @page-change="onPageChange" |
| 15 | + :current-page="queryParams.page" :per-page="bounces.perPage" :total="bounces.total" backend-sorting |
| 16 | + @sort="onSort"> |
| 17 | + <template #top-left> |
| 18 | + <div class="actions"> |
| 19 | + <template v-if="bulk.checked.length > 0"> |
| 20 | + <a class="a" href="#" @click.prevent="$utils.confirm(null, () => deleteBounces())" data-cy="btn-delete"> |
| 21 | + <b-icon icon="trash-can-outline" size="is-small" /> {{ $t('globals.buttons.delete') }} |
| 22 | + </a> |
| 23 | + <a class="a" href="#" @click.prevent="$utils.confirm(null, () => blocklistSubscribers())" |
| 24 | + data-cy="btn-manage-blocklist"> |
| 25 | + <b-icon icon="account-off-outline" size="is-small" /> {{ $t('import.blocklist') }} |
| 26 | + </a> |
| 27 | + <span> |
| 28 | + {{ $t('globals.messages.numSelected', { num: numSelectedBounces }) }} |
| 29 | + <span v-if="!bulk.all && bounces.total > bounces.perPage"> |
| 30 | + — |
| 31 | + <a href="#" @click.prevent="selectAllBounces"> |
| 32 | + {{ $t('subscribers.selectAll', { num: bounces.total }) }} |
| 33 | + </a> |
| 34 | + </span> |
| 35 | + </span> |
| 36 | + </template> |
| 37 | + </div> |
| 38 | + </template> |
26 | 39 | <b-table-column v-slot="props" field="email" :label="$t('subscribers.email')" :td-attrs="$utils.tdID" sortable> |
27 | | - <router-link :to="{ name: 'subscriber', params: { id: props.row.subscriberId } }"> |
| 40 | + <router-link :to="{ name: 'subscriber', params: { id: props.row.subscriberId } }" |
| 41 | + :class="{ 'blocklisted': props.row.subscriberStatus === 'blocklisted' }"> |
28 | 42 | {{ props.row.email }} |
| 43 | + <b-tag v-if="props.row.subscriberStatus !== 'enabled'" :class="props.row.subscriberStatus" |
| 44 | + data-cy="blocklisted"> |
| 45 | + {{ $t(`subscribers.status.${props.row.subscriberStatus}`) }} |
| 46 | + </b-tag> |
29 | 47 | </router-link> |
30 | 48 | </b-table-column> |
31 | 49 |
|
@@ -119,7 +137,10 @@ export default Vue.extend({ |
119 | 137 | this.queryParams.page = p; |
120 | 138 | this.getBounces(); |
121 | 139 | }, |
122 | | -
|
| 140 | + // Mark all bounces in the query as selected. |
| 141 | + selectAllBounces() { |
| 142 | + this.bulk.all = true; |
| 143 | + }, |
123 | 144 | onTableCheck() { |
124 | 145 | // Disable bulk.all selection if there are no rows checked in the table. |
125 | 146 | if (this.bulk.checked.length !== this.bounces.total) { |
@@ -149,35 +170,47 @@ export default Vue.extend({ |
149 | 170 | }); |
150 | 171 | }, |
151 | 172 |
|
152 | | - deleteBounces(all) { |
153 | | - const fnSuccess = () => { |
| 173 | + deleteBounces() { |
| 174 | + const params = {}; |
| 175 | + if (!this.bulk.all && this.bulk.checked.length > 0) { |
| 176 | + params.id = this.bulk.checked.map((s) => s.id); |
| 177 | + } else if (this.bulk.all) { |
| 178 | + params.all = true; |
| 179 | + } |
| 180 | +
|
| 181 | + this.$api.deleteBounces(params).then(() => { |
154 | 182 | this.getBounces(); |
155 | 183 | this.$utils.toast(this.$t( |
156 | 184 | 'globals.messages.deletedCount', |
157 | | - { name: this.$tc('globals.terms.bounces'), num: this.bounces.total }, |
| 185 | + { name: this.$tc('globals.terms.bounces'), num: this.numSelectedBounces }, |
158 | 186 | )); |
| 187 | + }); |
| 188 | + }, |
| 189 | +
|
| 190 | + blocklistSubscribers() { |
| 191 | + const cb = () => { |
| 192 | + this.getBounces(); |
| 193 | + this.$utils.toast(this.$t('globals.messages.done')); |
159 | 194 | }; |
160 | 195 |
|
161 | | - if (all) { |
162 | | - this.$api.deleteBounces({ all: true }).then(fnSuccess); |
| 196 | + if (!this.bulk.all && this.bulk.checked.length > 0) { |
| 197 | + const subIds = this.bulk.checked.map((s) => s.subscriberId); |
| 198 | + this.$api.blocklistSubscribers({ ids: subIds }).then(cb); |
163 | 199 | return; |
164 | 200 | } |
165 | 201 |
|
166 | | - const ids = this.bulk.checked.map((s) => s.id); |
167 | | - this.$api.deleteBounces({ id: ids }).then(fnSuccess); |
| 202 | + this.$api.blocklistBouncedSubscribers({ all: true }).then(cb); |
168 | 203 | }, |
169 | 204 | }, |
170 | 205 |
|
171 | 206 | computed: { |
172 | 207 | ...mapState(['templates', 'loading']), |
173 | | -
|
174 | | - selectedBounces() { |
| 208 | + numSelectedBounces() { |
175 | 209 | if (this.bulk.all) { |
176 | 210 | return this.bounces.total; |
177 | 211 | } |
178 | 212 | return this.bulk.checked.length; |
179 | 213 | }, |
180 | | -
|
181 | 214 | }, |
182 | 215 |
|
183 | 216 | mounted() { |
|
0 commit comments