|
2 | 2 |
|
3 | 3 | <div> |
4 | 4 | <KModal |
5 | | - v-if="restoreDialog" |
6 | | - :title="$tr('restoreChannelTitle')" |
7 | | - :submitText="$tr('restoreAction')" |
| 5 | + v-if="activeDialog" |
| 6 | + :title="dialogConfig.title" |
| 7 | + :submitText="dialogConfig.submitText" |
8 | 8 | :cancelText="$tr('cancelAction')" |
9 | | - data-test="confirm-restore" |
10 | | - @submit="restoreHandler" |
11 | | - @cancel="restoreDialog = false" |
| 9 | + :data-test="dialogConfig.testId" |
| 10 | + @submit="handleSubmit" |
| 11 | + @cancel="activeDialog = null" |
12 | 12 | > |
13 | | - <p> |
14 | | - {{ $tr('restoreChannelMessage', { name: name }) }} |
15 | | - </p> |
16 | | - </KModal> |
17 | | - |
18 | | - <KModal |
19 | | - v-if="makePublicDialog" |
20 | | - :title="$tr('makePublicTitle')" |
21 | | - :submitText="$tr('makePublicAction')" |
22 | | - :cancelText="$tr('cancelAction')" |
23 | | - data-test="confirm-public" |
24 | | - @submit="makePublicHandler" |
25 | | - @cancel="makePublicDialog = false" |
26 | | - > |
27 | | - <p>{{ $tr('makePublicMessage', { name: name }) }}</p> |
28 | | - </KModal> |
29 | | - |
30 | | - <KModal |
31 | | - v-if="makePrivateDialog" |
32 | | - :title="$tr('makePrivateTitle')" |
33 | | - :submitText="$tr('makePrivateAction')" |
34 | | - :cancelText="$tr('cancelAction')" |
35 | | - data-test="confirm-private" |
36 | | - @submit="makePrivateHandler" |
37 | | - @cancel="makePrivateDialog = false" |
38 | | - > |
39 | | - <p>{{ $tr('makePrivateMessage', { name: name }) }}</p> |
40 | | - </KModal> |
41 | | - |
42 | | - <KModal |
43 | | - v-if="deleteDialog" |
44 | | - :title="$tr('permanentDeleteTitle')" |
45 | | - :submitText="$tr('permanentDeleteAction')" |
46 | | - :cancelText="$tr('cancelAction')" |
47 | | - data-test="confirm-delete" |
48 | | - @submit="deleteHandler" |
49 | | - @cancel="deleteDialog = false" |
50 | | - > |
51 | | - <p> |
52 | | - {{ $tr('permanentDeleteMessage', { name: name }) }} |
53 | | - </p> |
54 | | - </KModal> |
55 | | - |
56 | | - <KModal |
57 | | - v-if="softDeleteDialog" |
58 | | - :title="$tr('softDeleteTitle')" |
59 | | - :submitText="$tr('softDeleteAction')" |
60 | | - :cancelText="$tr('cancelAction')" |
61 | | - data-test="confirm-softdelete" |
62 | | - @submit="softDeleteHandler" |
63 | | - @cancel="softDeleteDialog = false" |
64 | | - > |
65 | | - <p>{{ $tr('softDeleteMessage', { name: name }) }}</p> |
| 13 | + <p>{{ dialogConfig.message }}</p> |
66 | 14 | </KModal> |
67 | 15 |
|
68 | 16 | <BaseMenu> |
|
82 | 30 | <template v-if="channel.deleted"> |
83 | 31 | <VListTile |
84 | 32 | data-test="restore" |
85 | | - @click="restoreDialog = true" |
| 33 | + @click="openDialog('restore')" |
86 | 34 | > |
87 | 35 | <VListTileTitle>Restore</VListTileTitle> |
88 | 36 | </VListTile> |
89 | 37 | <VListTile |
90 | 38 | data-test="delete" |
91 | | - @click="deleteDialog = true" |
| 39 | + @click="openDialog('permanentDelete')" |
92 | 40 | > |
93 | 41 | <VListTileTitle>Delete permanently</VListTileTitle> |
94 | 42 | </VListTile> |
|
115 | 63 | <VListTile |
116 | 64 | v-if="channel.public" |
117 | 65 | data-test="private" |
118 | | - @click="makePrivateDialog = true" |
| 66 | + @click="openDialog('makePrivate')" |
119 | 67 | > |
120 | 68 | <VListTileTitle>Make private</VListTileTitle> |
121 | 69 | </VListTile> |
122 | 70 | <VListTile |
123 | 71 | v-else |
124 | 72 | data-test="public" |
125 | | - @click="makePublicDialog = true" |
| 73 | + @click="openDialog('makePublic')" |
126 | 74 | > |
127 | 75 | <VListTileTitle>Make public</VListTileTitle> |
128 | 76 | </VListTile> |
129 | 77 | <VListTile |
130 | 78 | v-if="!channel.public" |
131 | 79 | data-test="softdelete" |
132 | | - @click="softDeleteDialog = true" |
| 80 | + @click="openDialog('softDelete')" |
133 | 81 | > |
134 | 82 | <VListTileTitle>Delete channel</VListTileTitle> |
135 | 83 | </VListTile> |
|
157 | 105 | }, |
158 | 106 | }, |
159 | 107 | data: () => ({ |
160 | | - deleteDialog: false, |
161 | | - makePublicDialog: false, |
162 | | - makePrivateDialog: false, |
163 | | - restoreDialog: false, |
164 | | - softDeleteDialog: false, |
| 108 | + activeDialog: null, |
165 | 109 | }), |
166 | 110 | computed: { |
167 | 111 | ...mapGetters('channel', ['getChannel']), |
|
179 | 123 | }, |
180 | 124 | }; |
181 | 125 | }, |
| 126 | + dialogConfig() { |
| 127 | + const configs = { |
| 128 | + restore: { |
| 129 | + title: this.$tr('restoreChannelTitle'), |
| 130 | + submitText: this.$tr('restoreAction'), |
| 131 | + message: this.$tr('restoreChannelMessage', { name: this.name }), |
| 132 | + testId: 'confirm-restore', |
| 133 | + handler: this.restoreHandler, |
| 134 | + }, |
| 135 | + makePublic: { |
| 136 | + title: this.$tr('makePublicTitle'), |
| 137 | + submitText: this.$tr('makePublicAction'), |
| 138 | + message: this.$tr('makePublicMessage', { name: this.name }), |
| 139 | + testId: 'confirm-public', |
| 140 | + handler: this.makePublicHandler, |
| 141 | + }, |
| 142 | + makePrivate: { |
| 143 | + title: this.$tr('makePrivateTitle'), |
| 144 | + submitText: this.$tr('makePrivateAction'), |
| 145 | + message: this.$tr('makePrivateMessage', { name: this.name }), |
| 146 | + testId: 'confirm-private', |
| 147 | + handler: this.makePrivateHandler, |
| 148 | + }, |
| 149 | + permanentDelete: { |
| 150 | + title: this.$tr('permanentDeleteTitle'), |
| 151 | + submitText: this.$tr('permanentDeleteAction'), |
| 152 | + message: this.$tr('permanentDeleteMessage', { name: this.name }), |
| 153 | + testId: 'confirm-delete', |
| 154 | + handler: this.deleteHandler, |
| 155 | + }, |
| 156 | + softDelete: { |
| 157 | + title: this.$tr('softDeleteTitle'), |
| 158 | + submitText: this.$tr('softDeleteAction'), |
| 159 | + message: this.$tr('softDeleteMessage', { name: this.name }), |
| 160 | + testId: 'confirm-softdelete', |
| 161 | + handler: this.softDeleteHandler, |
| 162 | + }, |
| 163 | + }; |
| 164 | + return configs[this.activeDialog] || {}; |
| 165 | + }, |
182 | 166 | }, |
183 | 167 | methods: { |
184 | 168 | ...mapActions('channelAdmin', [ |
185 | 169 | 'getAdminChannelListDetails', |
186 | 170 | 'deleteChannel', |
187 | 171 | 'updateChannel', |
188 | 172 | ]), |
| 173 | + openDialog(type) { |
| 174 | + this.activeDialog = type; |
| 175 | + }, |
| 176 | + handleSubmit() { |
| 177 | + if (this.dialogConfig.handler) { |
| 178 | + this.dialogConfig.handler(); |
| 179 | + } |
| 180 | + this.activeDialog = null; |
| 181 | + }, |
189 | 182 | async downloadPDF() { |
190 | 183 | this.$store.dispatch('showSnackbarSimple', 'Generating PDF...'); |
191 | 184 | const channelList = await this.getAdminChannelListDetails([this.channel.id]); |
|
197 | 190 | return this.generateChannelsCSV(channelList); |
198 | 191 | }, |
199 | 192 | restoreHandler() { |
200 | | - this.restoreDialog = false; |
201 | 193 | this.updateChannel({ |
202 | 194 | id: this.channelId, |
203 | 195 | deleted: false, |
|
206 | 198 | }); |
207 | 199 | }, |
208 | 200 | softDeleteHandler() { |
209 | | - this.softDeleteDialog = false; |
210 | 201 | this.updateChannel({ |
211 | 202 | id: this.channelId, |
212 | 203 | deleted: true, |
|
215 | 206 | }); |
216 | 207 | }, |
217 | 208 | deleteHandler() { |
218 | | - this.deleteDialog = false; |
219 | 209 | this.$emit('deleted'); |
220 | 210 | return this.deleteChannel(this.channelId).then(() => { |
221 | 211 | this.$store.dispatch('showSnackbarSimple', 'Channel deleted permanently'); |
222 | 212 | }); |
223 | 213 | }, |
224 | 214 | makePublicHandler() { |
225 | | - this.makePublicDialog = false; |
226 | 215 | this.updateChannel({ |
227 | 216 | id: this.channelId, |
228 | 217 | isPublic: true, |
|
231 | 220 | }); |
232 | 221 | }, |
233 | 222 | makePrivateHandler() { |
234 | | - this.makePrivateDialog = false; |
235 | 223 | this.updateChannel({ |
236 | 224 | id: this.channelId, |
237 | 225 | isPublic: false, |
|
0 commit comments