1
1
<script setup lang="ts">
2
2
import CardBrands from ' ./card-brands.vue'
3
+ import { notification } from ' @stacksjs/notification'
4
+ import { Popover , PopoverPanel , PopoverButton } from ' @stacksjs/popover'
5
+
6
+ const isDefaultLoading = ref <{ [key : string ]: boolean }>({})
3
7
4
8
const paymentStore = usePaymentStore ()
5
9
@@ -10,10 +14,15 @@ async function deletePayment(paymentMethodId: string) {
10
14
}
11
15
12
16
async function makeDefault(paymentMethodId : string ) {
17
+ isDefaultLoading .value [paymentMethodId ] = true
18
+
13
19
await paymentStore .updateDefaultPaymentMethod (paymentMethodId )
14
20
15
21
await paymentStore .fetchUserPaymentMethods ()
16
22
await paymentStore .fetchDefaultPaymentMethod ()
23
+
24
+ notification .success (' Default payment method updated' )
25
+ isDefaultLoading .value [paymentMethodId ] = false
17
26
}
18
27
</script >
19
28
@@ -35,13 +44,19 @@ async function makeDefault(paymentMethodId: string) {
35
44
type =" button"
36
45
class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
37
46
@click =" makeDefault(method.id)"
47
+ :disabled =" isDefaultLoading[method.id]"
38
48
>
39
- <svg class =" h-4 w-4 text-gray-700" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
49
+ <svg v-if = " !isDefaultLoading[method.id] " class =" h-4 w-4 text-gray-700" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
40
50
<path stroke-linecap =" round" stroke-linejoin =" round" d =" M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
41
51
</svg >
52
+
53
+ <svg v-else class =" h-4 w-4 text-gray-700 animate-spin" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
54
+ <circle cx =" 12" cy =" 12" r =" 10" stroke =" currentColor" stroke-opacity =" 0.25" stroke-width =" 4" ></circle >
55
+ <path d =" M4 12a8 8 0 018-8" stroke =" currentColor" stroke-width =" 4" stroke-linecap =" round" ></path >
56
+ </svg >
42
57
</button >
43
58
44
- <button
59
+ <!-- < button
45
60
aria-label="delete"
46
61
type="button"
47
62
class="border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
@@ -50,7 +65,34 @@ async function makeDefault(paymentMethodId: string) {
50
65
<svg class="h-4 w-4 text-gray-700" data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
51
66
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
52
67
</svg>
53
- </button >
68
+ </button> -->
69
+
70
+ <Popover v-slot =" { open }" class =" relative" >
71
+ <PopoverButton
72
+ :class =" open ? 'text-white' : 'text-white/90'"
73
+ class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
74
+ >
75
+ <svg class =" h-4 w-4 text-gray-700" data-slot =" icon" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
76
+ <path stroke-linecap =" round" stroke-linejoin =" round" d =" m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
77
+ </svg >
78
+ </PopoverButton >
79
+
80
+ <PopoverPanel
81
+ class =" absolute left-1/2 z-10 mt-3 w-screen max-w-sm -translate-x-1/2 transform px-4 sm:px-0 lg:max-w-3xl"
82
+ >
83
+ <div class =" p-4" >
84
+ <h3 class =" text-lg font-medium leading-6 text-gray-900" >Delete Payment Method</h3 >
85
+ <div class =" mt-2" >
86
+ <p class =" text-sm text-gray-500" >Are you sure you want to delete this payment method?</p >
87
+ </div >
88
+ <div class =" mt-4 flex justify-end" >
89
+ <button type =" button" class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline" >
90
+ Delete
91
+ </button >
92
+ </div >
93
+ </div >
94
+ </PopoverPanel >
95
+ </Popover >
54
96
</div >
55
97
</div >
56
98
</div >
0 commit comments