-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCanisterUnlinkDialog.vue
More file actions
154 lines (142 loc) · 3.84 KB
/
Copy pathCanisterUnlinkDialog.vue
File metadata and controls
154 lines (142 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<template>
<VDialog
v-bind="$attrs"
v-model="open"
:persistent="!canClose"
transition="dialog-bottom-transition"
scrollable
:max-width="props.dialogMaxWidth"
>
<VCard data-test-id="canister-unlink-card">
<VToolbar color="background">
<VToolbarTitle>
{{ dialogTitle }}
</VToolbarTitle>
<VBtn :disabled="!canClose" :icon="mdiClose" @click="open = false" />
</VToolbar>
<VDivider />
<VCardText>
{{ $t('app.dialog_confirmation_question') }}
<VSwitch
v-model="softDelete"
class="my-4"
name="soft_delete"
:label="$t('external_canisters.unlink_soft_delete')"
hide-details
inset
color="success"
/>
</VCardText>
<VDivider />
<VCardActions class="pa-3">
<VSpacer />
<VBtn
:loading="submitting"
color="primary"
variant="elevated"
data-test-id="canister-unlink-save-button"
@click="submit"
>
{{ $t('external_canisters.unlink') }}
</VBtn>
</VCardActions>
</VCard>
</VDialog>
</template>
<script lang="ts" setup>
import { Principal } from '@icp-sdk/core/principal';
import { mdiClose } from '@mdi/js';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import {
VBtn,
VCard,
VCardActions,
VCardText,
VDialog,
VDivider,
VSpacer,
VSwitch,
VToolbar,
VToolbarTitle,
} from 'vuetify/components';
import {
useOnFailedOperation,
useOnSuccessfulOperation,
} from '~/composables/notifications.composable';
import { Routes } from '~/configs/routes.config';
import logger from '~/core/logger.core';
import { useStationStore } from '~/stores/station.store';
import { variantIs } from '~/utils/helper.utils';
const props = withDefaults(
defineProps<{
/**
* Whether the dialog is open or not.
*/
open?: boolean;
/**
* The canister ID to target the unlink operation.
*/
canisterId: Principal;
/**
* Wether or not to also delete the canister from the Internet Computer Subnet, or just delete the local reference
* to it in the Orbit Station.
*/
softDelete?: boolean;
/**
* The maximum width of the dialog.
*/
dialogMaxWidth?: number;
/**
* The title of the dialog, if not provided, it will default to the locale key of `external_canisters.unlink_title`.
*/
title?: string;
/**
* Redirect when unlink is successful.
*/
redirect?: boolean;
}>(),
{
open: false,
softDelete: true,
dialogMaxWidth: 800,
title: undefined,
redirect: true,
},
);
const i18n = useI18n();
const station = useStationStore();
const submitting = ref(false);
const canClose = computed(() => !submitting.value);
const dialogTitle = computed(() => props.title || i18n.t('external_canisters.unlink_title'));
const softDelete = ref(props.softDelete);
const router = useRouter();
const emit = defineEmits<{
(event: 'update:open', payload: boolean): void;
}>();
const open = computed({
get: () => props.open,
set: value => emit('update:open', value),
});
const submit = async (): Promise<void> => {
try {
submitting.value = true;
const request = await station.service.unlinkExternalCanister({
canisterId: props.canisterId,
softDelete: softDelete.value,
});
useOnSuccessfulOperation(request);
open.value = false;
// Redirect to the external canisters page if the request is marked as approved directly.
if (props.redirect && variantIs(request.status, 'Approved')) {
await router.push({ name: Routes.ExternalCanisters });
}
} catch (error) {
logger.error('Failed to submit unlink canister request', error);
useOnFailedOperation();
} finally {
submitting.value = false;
}
};
</script>