11<template >
22 <div class =" space-y-6" >
3- <Message severity="warn" class="inline-block max-w-max">{{ t("Danger zone: deleting an access URL is permanent.")}}</Message >
4- <section class =" p-0" >
5- <h3 class =" mb-2 text-sm font-semibold text-rose-900" >{{ t("Confirm deletion") }}</h3 >
6- <p class =" mb-3 text-sm text-rose-800" >
7- {{ t("Type the full URL to confirm. The URL and its relations will be permanently removed.") }}
3+ <SectionHeader :title =" t (' Confirm deletion' )" />
4+ <Message
5+ severity="warn"
6+ class="inline-block max-w-max"
7+ >
8+ {{ t("Danger zone: deleting an access URL is permanent.") }}
9+ </Message >
10+ <section >
11+ <p class =" mb-3" >
12+ {{ t("The value must match exactly: %s", [urlText]) }}
813 </p >
9- <div class =" grid grid-cols-1 gap-4 md:grid-cols-3 items-center" >
10- <div class =" md:col-span-2" >
11- <label class =" mb-1 block text-xs font-medium text-rose-900" >{{ t("URL") }}</label >
12- <BaseInputText
13- v-model =" confirmText "
14- class="w-full"
15- :placeholder =" urlText || ' https://example.com' "
16- />
17- <p v-if =" confirmText && !canDelete" class =" mt-1 text-xs text-rose-700" >
18- {{ t("The value must match exactly:") }} <strong >{{ urlText }}</strong >
19- </p >
20- </div >
21- <div class =" flex items-center md:justify-end md:col-span-1 md:pr-8" >
22- <div class =" hidden md:block" >
23- <BaseButton
24- :label =" t (' Delete URL' )"
25- icon="delete"
26- type="danger"
27- :disabled =" loading || ! canDelete "
28- :isLoading =" loading "
29- @click =" openConfirmDialog "
30- />
31- </div >
32- </div >
33- </div >
14+
15+ <BaseInputText
16+ id="confirm-text"
17+ v-model =" confirmText "
18+ :label =" t (' URL' )"
19+ :placeholder =" urlText || ' https://example.com' "
20+ class="w-full"
21+ :help-text =" t (' Type the full URL to confirm. The URL and its relations will be permanently removed.' )"
22+ />
23+
24+ <BaseButton
25+ :disabled =" loading || ! canDelete "
26+ :is-loading =" loading "
27+ :label =" t (' Delete URL' )"
28+ icon="delete"
29+ type="danger"
30+ @click =" confirmDialogVisible = true "
31+ />
3432 </section >
33+
3534 <BaseDialogConfirmCancel
3635 v-model :isVisible =" confirmDialogVisible "
36+ :cancel-label =" t (' Cancel' )"
37+ :confirm-label =" t (' Delete' )"
3738 :title =" t (' Confirm deletion' )"
38- :confirmLabel =" t (' Delete' )"
39- :cancelLabel =" t (' Cancel' )"
40- @confirmClicked =" confirmSubmit "
39+ @confirm-clicked =" confirmSubmit "
40+ @cancel-clicked =" confirmDialogVisible = false "
4141 />
4242 </div >
4343</template >
4444
45- <script setup >
45+ <script setup>
4646import { ref , computed , onMounted } from " vue"
4747import { useI18n } from " vue-i18n"
48- import { useRoute , useRouter } from " vue-router"
49- import svc from " ../../services/accessurlService"
48+ import { useRoute } from " vue-router"
49+ import { findById , deleteById } from " ../../services/accessurlService"
5050import Message from " primevue/message"
5151
5252import BaseInputText from " ../../components/basecomponents/BaseInputText.vue"
5353import BaseButton from " ../../components/basecomponents/BaseButton.vue"
5454import BaseDialogConfirmCancel from " ../../components/basecomponents/BaseDialogConfirmCancel.vue"
55+ import SectionHeader from " ../../components/layout/SectionHeader.vue"
56+ import { useNotification } from " ../../composables/notification"
5557
5658const { t } = useI18n ()
5759const route = useRoute ()
58- const router = useRouter ()
60+
61+ const notification = useNotification ()
62+
5963const urlId = Number (route .params .id || 0 )
6064const urlText = ref (route .query .url || " " )
6165const confirmText = ref (" " )
6266const loading = ref (false )
63- const error = ref (" " )
6467const notice = ref (" " )
6568const confirmDialogVisible = ref (false )
6669
@@ -69,34 +72,27 @@ const canDelete = computed(() => !!confirmText.value && confirmText.value === ur
6972onMounted (async () => {
7073 if (! urlText .value && urlId) {
7174 try {
72- const data = await svc . getUrl (urlId)
75+ const data = await findById (urlId)
7376 urlText .value = data .url || " "
7477 } catch (e) {
75- error . value = t ( " Unable to load URL data. " )
78+ notification . showErrorNotification (e )
7679 }
7780 }
7881})
7982
80- function openConfirmDialog () {
81- confirmDialogVisible .value = true
82- }
83-
8483async function confirmSubmit () {
8584 confirmDialogVisible .value = false
86- error .value = " "
8785 notice .value = " "
8886 try {
8987 loading .value = true
90- const secToken = (window .SEC_TOKEN || route .query .sec_token || " " )
91- const res = await svc .deleteAccessUrl (urlId, confirmText .value , secToken)
92- notice .value = res .message || t (" URL deleted successfully." )
93- if (res .redirectUrl ) {
94- window .location .href = res .redirectUrl
95- } else {
96- router .push ({ name: " AccessUrlsList" })
97- }
88+ const secToken = window .SEC_TOKEN || route .query .sec_token || " "
89+ const res = await deleteById (urlId, secToken)
90+
91+ notification .showSuccessNotification (t (" URL deleted successfully." ))
92+
93+ window .location .href = res .redirectUrl
9894 } catch (e) {
99- error . value = e ? . message || (e ? . response ? . data ? . error ) || t ( " Failed to delete URL. " )
95+ notification . showErrorNotification (e )
10096 } finally {
10197 loading .value = false
10298 }
0 commit comments