-
Notifications
You must be signed in to change notification settings - Fork 386
/
RemoveCreditCardDialog.vue
124 lines (107 loc) · 3.98 KB
/
RemoveCreditCardDialog.vue
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
// Copyright (C) 2024 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-dialog
v-model="model"
width="320px"
transition="fade-transition"
:persistent="isLoading"
>
<v-card rounded="xlg">
<v-card-item class="pa-5 pl-6">
<v-card-title class="font-weight-bold">Remove credit card</v-card-title>
<template #append>
<v-btn
icon="$close"
variant="text"
size="small"
color="default"
:disabled="isLoading"
@click="model = false"
/>
</template>
</v-card-item>
<v-card-item class="px-6 py-0">
<v-divider />
<v-card-text v-if="card.isDefault" class="py-4 px-0">This is your default payment card. It can't be removed.</v-card-text>
<v-card-text v-else class="py-4 px-0">This is not your default payment card.</v-card-text>
<credit-card-item :card="card" />
<v-divider />
</v-card-item>
<v-card-actions class="pa-6">
<v-row>
<v-col>
<v-btn variant="outlined" color="default" block :disabled="isLoading" @click="model = false">
Cancel
</v-btn>
</v-col>
<v-col v-if="(card.isDefault && moreThanOneCard) || !card.isDefault">
<v-btn v-if="card.isDefault && moreThanOneCard" color="primary" variant="flat" block :loading="isLoading" @click="onEditDefault">
Edit Default
</v-btn>
<v-btn v-if="!card.isDefault" color="error" variant="flat" block :loading="isLoading" @click="onDelete">
Remove
</v-btn>
</v-col>
</v-row>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import {
VDialog,
VCard,
VCardItem,
VCardTitle,
VCardText,
VDivider,
VCardActions,
VRow,
VCol,
VBtn,
} from 'vuetify/components';
import { useConfigStore } from '@/store/modules/configStore';
import { useAnalyticsStore } from '@/store/modules/analyticsStore';
import { useBillingStore } from '@/store/modules/billingStore';
import { useLoading } from '@/composables/useLoading';
import { useNotify } from '@/utils/hooks';
import { AnalyticsErrorEventSource } from '@/utils/constants/analyticsEventNames';
import { CreditCard } from '@/types/payments';
import CreditCardItem from '@poc/components/dialogs/ccActionComponents/CreditCardItem.vue';
const props = defineProps<{
modelValue: boolean,
card: CreditCard,
}>();
const emit = defineEmits<{
'update:modelValue': [value: boolean],
'editDefault': [];
}>();
const model = computed<boolean>({
get: () => props.modelValue,
set: value => emit('update:modelValue', value),
});
const analyticsStore = useAnalyticsStore();
const billingStore = useBillingStore();
const configStore = useConfigStore();
const { isLoading, withLoading } = useLoading();
const notify = useNotify();
const moreThanOneCard = computed<boolean>(() => billingStore.state.creditCards.length > 1);
async function onDelete(): Promise<void> {
await withLoading(async () => {
try {
await billingStore.removeCreditCard(props.card.id);
notify.success('Credit card was successfully removed');
model.value = false;
} catch (error) {
error.message = `Error removing credit card. ${error.message}`;
notify.notifyError(error, AnalyticsErrorEventSource.REMOVE_CC_MODAL);
}
});
}
function onEditDefault(): void {
emit('update:modelValue', false);
emit('editDefault');
}
</script>