@zaaxch/grasp-vue 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/components.d.ts +76 -7
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +240 -230
- package/dist/components.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -12
- package/dist/index.js.map +1 -1
- package/dist/preferences.d.ts +39 -0
- package/dist/preferences.d.ts.map +1 -0
- package/dist/preferences.js +208 -0
- package/dist/preferences.js.map +1 -0
- package/dist/router.d.ts +21 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +29 -3
- package/dist/router.js.map +1 -1
- package/dist/stores.d.ts +33 -7
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +9 -1
- package/dist/stores.js.map +1 -1
- package/dist/theme.d.ts +24 -5
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +46 -10
- package/dist/theme.js.map +1 -1
- package/package.json +11 -3
- package/styles.css +1 -0
package/dist/components.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { computed, defineComponent, h, inject, onMounted, ref } from 'vue';
|
|
1
|
+
import { computed, defineComponent, h, inject, onMounted, ref, watch } from 'vue';
|
|
2
2
|
import { RouterLink, RouterView, useRoute, useRouter } from 'vue-router';
|
|
3
|
-
import {
|
|
3
|
+
import { GRASP_NAV_KEY, GRASP_THEME_KEY, useAuthStore, useBillingStore, useGraspConfig, useGraspUi, useNotificationsStore, } from './stores.js';
|
|
4
4
|
function formatCurrency(cents, currency) {
|
|
5
5
|
return new Intl.NumberFormat('en-US', {
|
|
6
6
|
style: 'currency',
|
|
@@ -13,120 +13,53 @@ function safeRedirectTarget(raw, fallback = '/settings') {
|
|
|
13
13
|
}
|
|
14
14
|
return fallback;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
const variant = options.variant ?? 'solid';
|
|
19
|
-
const size = options.size ?? 'md';
|
|
20
|
-
const isDisabled = Boolean(options.disabled || options.loading);
|
|
21
|
-
const sizeClass = size === 'sm' ? 'px-3 py-1.5 text-xs' : 'px-4 py-2 text-sm';
|
|
22
|
-
let colorClass = 'bg-primary text-inverted hover:opacity-90';
|
|
23
|
-
if (variant === 'outline') {
|
|
24
|
-
if (tone === 'danger') {
|
|
25
|
-
colorClass = 'border border-error/40 text-error hover:bg-error/10';
|
|
26
|
-
}
|
|
27
|
-
else if (tone === 'secondary') {
|
|
28
|
-
colorClass = 'border border-default text-default hover:bg-elevated';
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
colorClass = 'border border-primary/50 text-primary hover:bg-primary/10';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else if (variant === 'ghost') {
|
|
35
|
-
colorClass = tone === 'danger' ? 'text-error hover:bg-error/10' : 'text-muted hover:bg-elevated';
|
|
36
|
-
}
|
|
37
|
-
else if (tone === 'danger') {
|
|
38
|
-
colorClass = 'bg-error text-inverted hover:opacity-90';
|
|
39
|
-
}
|
|
40
|
-
else if (tone === 'secondary') {
|
|
41
|
-
colorClass = 'bg-elevated text-default ring ring-inset ring-default hover:bg-accented/50';
|
|
42
|
-
}
|
|
43
|
-
return h('button', {
|
|
44
|
-
...(options.key !== undefined ? { key: options.key } : {}),
|
|
45
|
-
type: 'button',
|
|
46
|
-
disabled: isDisabled,
|
|
47
|
-
class: [
|
|
48
|
-
'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-60',
|
|
49
|
-
sizeClass,
|
|
50
|
-
colorClass,
|
|
51
|
-
options.class,
|
|
52
|
-
]
|
|
53
|
-
.filter(Boolean)
|
|
54
|
-
.join(' '),
|
|
55
|
-
...(options.testId ? { 'data-testid': options.testId } : {}),
|
|
56
|
-
onClick: options.onClick,
|
|
57
|
-
}, options.loading ? `${options.label}…` : options.label);
|
|
58
|
-
}
|
|
59
|
-
function renderCard(options) {
|
|
60
|
-
return h('section', {
|
|
61
|
-
...(options.key !== undefined ? { key: options.key } : {}),
|
|
62
|
-
class: ['rounded-lg border border-default bg-default p-6 shadow-xs', options.class]
|
|
63
|
-
.filter(Boolean)
|
|
64
|
-
.join(' '),
|
|
65
|
-
...(options.testId ? { 'data-testid': options.testId } : {}),
|
|
66
|
-
}, [
|
|
67
|
-
options.title ? h('div', { class: 'mb-4 font-semibold' }, [options.title()]) : null,
|
|
68
|
-
h('div', undefined, [options.content()]),
|
|
69
|
-
]);
|
|
16
|
+
function severityToToastColor(severity) {
|
|
17
|
+
return severity === 'warn' ? 'warning' : severity;
|
|
70
18
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const toneClass = tone === 'success'
|
|
74
|
-
? 'bg-emerald-500/10 text-emerald-700 ring-emerald-500/25 dark:text-emerald-300'
|
|
75
|
-
: tone === 'info'
|
|
76
|
-
? 'bg-primary/10 text-primary ring-primary/25'
|
|
77
|
-
: 'bg-elevated text-muted ring-default';
|
|
78
|
-
return h('span', {
|
|
79
|
-
class: `inline-flex items-center rounded-md px-2 py-0.5 text-xs font-medium ring ring-inset ${toneClass}`,
|
|
80
|
-
...(options.testId ? { 'data-testid': options.testId } : {}),
|
|
81
|
-
}, options.value);
|
|
82
|
-
}
|
|
83
|
-
function renderAlert(options) {
|
|
84
|
-
const severityClass = options.severity === 'error'
|
|
85
|
-
? 'border-red-500/30 bg-red-500/10 text-red-700 dark:text-red-300'
|
|
86
|
-
: options.severity === 'warn'
|
|
87
|
-
? 'border-amber-500/30 bg-amber-500/10 text-amber-800 dark:text-amber-200'
|
|
88
|
-
: options.severity === 'success'
|
|
89
|
-
? 'border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
|
90
|
-
: 'border-primary/30 bg-primary/10 text-default';
|
|
91
|
-
return h('div', {
|
|
92
|
-
...(options.key !== undefined ? { key: options.key } : {}),
|
|
93
|
-
role: 'alert',
|
|
94
|
-
class: `flex items-start justify-between gap-3 rounded-lg border px-3.5 py-2.5 text-sm shadow-xs ${severityClass}`,
|
|
95
|
-
...(options.testId ? { 'data-testid': options.testId } : {}),
|
|
96
|
-
}, [
|
|
97
|
-
h('span', { class: 'flex-1' }, options.message),
|
|
98
|
-
options.onDismiss
|
|
99
|
-
? h('button', {
|
|
100
|
-
type: 'button',
|
|
101
|
-
'aria-label': 'Dismiss notification',
|
|
102
|
-
class: 'shrink-0 rounded px-1 text-xs opacity-70 hover:opacity-100',
|
|
103
|
-
onClick: options.onDismiss,
|
|
104
|
-
}, '×')
|
|
105
|
-
: null,
|
|
106
|
-
]);
|
|
107
|
-
}
|
|
108
|
-
export const GraspAppRoot = defineComponent({
|
|
109
|
-
name: 'GraspAppRoot',
|
|
19
|
+
export const GraspNotificationBridge = defineComponent({
|
|
20
|
+
name: 'GraspNotificationBridge',
|
|
110
21
|
setup() {
|
|
111
22
|
const notifications = useNotificationsStore();
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
23
|
+
const ui = useGraspUi();
|
|
24
|
+
const toastApi = ui.useToast?.();
|
|
25
|
+
const forwardedIds = new Set();
|
|
26
|
+
watch(() => notifications.items, (items) => {
|
|
27
|
+
if (!toastApi)
|
|
28
|
+
return;
|
|
29
|
+
const currentIds = new Set(items.map((item) => item.id));
|
|
30
|
+
for (const oldId of forwardedIds) {
|
|
31
|
+
if (!currentIds.has(oldId)) {
|
|
32
|
+
forwardedIds.delete(oldId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const item of items) {
|
|
36
|
+
if (forwardedIds.has(item.id))
|
|
37
|
+
continue;
|
|
38
|
+
forwardedIds.add(item.id);
|
|
39
|
+
toastApi.add({
|
|
40
|
+
id: item.id,
|
|
41
|
+
title: item.summary,
|
|
42
|
+
...(item.detail !== undefined ? { description: item.detail } : {}),
|
|
43
|
+
color: severityToToastColor(item.severity),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}, { immediate: true, flush: 'sync' });
|
|
47
|
+
return () => null;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
export const GraspAppRoot = defineComponent({
|
|
51
|
+
name: 'GraspAppRoot',
|
|
52
|
+
setup(_props, { slots }) {
|
|
53
|
+
const ui = useGraspUi();
|
|
54
|
+
const theme = inject(GRASP_THEME_KEY, null);
|
|
55
|
+
return () => h(ui.UApp, theme?.toaster !== undefined ? { toaster: theme.toaster } : {}, {
|
|
56
|
+
default: () => [
|
|
57
|
+
h(GraspNotificationBridge),
|
|
58
|
+
h('div', { class: 'min-h-screen bg-default text-default', 'data-testid': 'grasp-root' }, [
|
|
59
|
+
slots['default'] ? slots['default']() : h(RouterView),
|
|
60
|
+
]),
|
|
61
|
+
],
|
|
62
|
+
});
|
|
130
63
|
},
|
|
131
64
|
});
|
|
132
65
|
export const GraspAuthFlow = defineComponent({
|
|
@@ -135,6 +68,7 @@ export const GraspAuthFlow = defineComponent({
|
|
|
135
68
|
homePath: { type: String, default: '/settings' },
|
|
136
69
|
},
|
|
137
70
|
setup(props) {
|
|
71
|
+
const ui = useGraspUi();
|
|
138
72
|
const auth = useAuthStore();
|
|
139
73
|
const config = useGraspConfig();
|
|
140
74
|
const route = useRoute();
|
|
@@ -160,23 +94,23 @@ export const GraspAuthFlow = defineComponent({
|
|
|
160
94
|
class: 'mx-auto flex min-h-screen max-w-md items-center justify-center px-4',
|
|
161
95
|
'data-testid': 'grasp-auth-flow',
|
|
162
96
|
}, [
|
|
163
|
-
|
|
164
|
-
class: '
|
|
165
|
-
|
|
166
|
-
content: () => h('div', { class: 'flex flex-col gap-4' }, [
|
|
97
|
+
h(ui.UCard, { class: 'w-full shadow-md' }, {
|
|
98
|
+
header: () => h('h1', { class: 'text-xl font-semibold' }, `Sign in to ${config.app.displayName}`),
|
|
99
|
+
default: () => h('div', { class: 'flex flex-col gap-4' }, [
|
|
167
100
|
auth.error
|
|
168
|
-
?
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
101
|
+
? h(ui.UAlert, {
|
|
102
|
+
color: 'error',
|
|
103
|
+
variant: 'soft',
|
|
104
|
+
title: auth.error,
|
|
105
|
+
'data-testid': 'grasp-auth-error',
|
|
172
106
|
})
|
|
173
107
|
: null,
|
|
174
|
-
|
|
108
|
+
h(ui.UButton, {
|
|
175
109
|
label: 'Continue with Google',
|
|
176
110
|
loading: auth.loading,
|
|
177
111
|
disabled: auth.loading,
|
|
178
|
-
|
|
179
|
-
|
|
112
|
+
block: true,
|
|
113
|
+
'data-testid': 'grasp-google-signin',
|
|
180
114
|
onClick: handleGoogleLogin,
|
|
181
115
|
}),
|
|
182
116
|
auth.devMode
|
|
@@ -187,13 +121,13 @@ export const GraspAuthFlow = defineComponent({
|
|
|
187
121
|
h('p', {
|
|
188
122
|
class: 'mb-2 text-xs font-medium uppercase tracking-wide opacity-70',
|
|
189
123
|
}, 'Local Dev Personas'),
|
|
190
|
-
h('div', { class: 'flex flex-col gap-2' }, auth.personas.map((persona) =>
|
|
124
|
+
h('div', { class: 'flex flex-col gap-2' }, auth.personas.map((persona) => h(ui.UButton, {
|
|
191
125
|
key: persona.uid,
|
|
192
126
|
label: `${persona.displayName} (${persona.email})`,
|
|
193
|
-
|
|
127
|
+
color: 'neutral',
|
|
194
128
|
variant: 'outline',
|
|
195
129
|
size: 'sm',
|
|
196
|
-
|
|
130
|
+
'data-testid': `grasp-dev-persona-${persona.uid}`,
|
|
197
131
|
onClick: () => handleDevLogin(persona.uid),
|
|
198
132
|
}))),
|
|
199
133
|
])
|
|
@@ -203,25 +137,95 @@ export const GraspAuthFlow = defineComponent({
|
|
|
203
137
|
]);
|
|
204
138
|
},
|
|
205
139
|
});
|
|
140
|
+
export const GraspDeleteAccountCard = defineComponent({
|
|
141
|
+
name: 'GraspDeleteAccountCard',
|
|
142
|
+
props: {
|
|
143
|
+
title: { type: String, default: 'Danger Zone' },
|
|
144
|
+
description: {
|
|
145
|
+
type: String,
|
|
146
|
+
default: 'Permanently delete your account, subscriptions, credits, and all associated data.',
|
|
147
|
+
},
|
|
148
|
+
buttonLabel: { type: String, default: 'Delete Account' },
|
|
149
|
+
confirmLabel: { type: String, default: 'Confirm Permanent Deletion' },
|
|
150
|
+
redirectTo: { type: String, default: '/' },
|
|
151
|
+
portal: { type: Boolean, default: true },
|
|
152
|
+
},
|
|
153
|
+
setup(props) {
|
|
154
|
+
const ui = useGraspUi();
|
|
155
|
+
const auth = useAuthStore();
|
|
156
|
+
const router = useRouter();
|
|
157
|
+
const confirmOpen = ref(false);
|
|
158
|
+
const handleDeleteAccount = async () => {
|
|
159
|
+
await auth.deleteAccount();
|
|
160
|
+
confirmOpen.value = false;
|
|
161
|
+
await router.replace(props.redirectTo);
|
|
162
|
+
};
|
|
163
|
+
return () => h(ui.UCard, { 'data-testid': 'grasp-delete-account-card' }, {
|
|
164
|
+
header: () => h('span', { class: 'font-semibold text-error' }, props.title),
|
|
165
|
+
default: () => h('div', { class: 'flex flex-col gap-3' }, [
|
|
166
|
+
h('p', { class: 'text-sm opacity-80' }, props.description),
|
|
167
|
+
h('div', [
|
|
168
|
+
h(ui.UButton, {
|
|
169
|
+
label: props.buttonLabel,
|
|
170
|
+
color: 'error',
|
|
171
|
+
variant: 'outline',
|
|
172
|
+
'data-testid': 'grasp-delete-account-start',
|
|
173
|
+
onClick: () => {
|
|
174
|
+
confirmOpen.value = true;
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
177
|
+
]),
|
|
178
|
+
h(ui.UModal, {
|
|
179
|
+
open: confirmOpen.value,
|
|
180
|
+
'onUpdate:open': (nextOpen) => {
|
|
181
|
+
confirmOpen.value = nextOpen;
|
|
182
|
+
},
|
|
183
|
+
title: 'Confirm Account Deletion',
|
|
184
|
+
description: props.description,
|
|
185
|
+
portal: props.portal,
|
|
186
|
+
}, {
|
|
187
|
+
body: () => h('p', {
|
|
188
|
+
class: 'text-sm text-toned',
|
|
189
|
+
'data-testid': 'grasp-delete-account-confirm-box',
|
|
190
|
+
}, 'This action cannot be undone.'),
|
|
191
|
+
footer: () => h('div', { class: 'flex items-center justify-end gap-2' }, [
|
|
192
|
+
h(ui.UButton, {
|
|
193
|
+
label: 'Cancel',
|
|
194
|
+
color: 'neutral',
|
|
195
|
+
variant: 'ghost',
|
|
196
|
+
onClick: () => {
|
|
197
|
+
confirmOpen.value = false;
|
|
198
|
+
},
|
|
199
|
+
}),
|
|
200
|
+
h(ui.UButton, {
|
|
201
|
+
label: props.confirmLabel,
|
|
202
|
+
color: 'error',
|
|
203
|
+
loading: auth.loading,
|
|
204
|
+
disabled: auth.loading,
|
|
205
|
+
'data-testid': 'grasp-delete-account-confirm',
|
|
206
|
+
onClick: handleDeleteAccount,
|
|
207
|
+
}),
|
|
208
|
+
]),
|
|
209
|
+
}),
|
|
210
|
+
]),
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
});
|
|
206
214
|
export const GraspAccountSettings = defineComponent({
|
|
207
215
|
name: 'GraspAccountSettings',
|
|
208
|
-
setup() {
|
|
216
|
+
setup(_props, { slots }) {
|
|
217
|
+
const ui = useGraspUi();
|
|
209
218
|
const auth = useAuthStore();
|
|
210
219
|
const router = useRouter();
|
|
211
|
-
const confirmingDelete = ref(false);
|
|
212
220
|
const handleLogout = async () => {
|
|
213
221
|
await auth.logout();
|
|
214
222
|
await router.replace('/login');
|
|
215
223
|
};
|
|
216
|
-
const handleDeleteAccount = async () => {
|
|
217
|
-
await auth.deleteAccount();
|
|
218
|
-
confirmingDelete.value = false;
|
|
219
|
-
await router.replace('/');
|
|
220
|
-
};
|
|
221
224
|
return () => h('div', { class: 'mx-auto flex max-w-2xl flex-col gap-6', 'data-testid': 'grasp-account-settings' }, [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
...(slots['header'] ? slots['header']() : []),
|
|
226
|
+
h(ui.UCard, null, {
|
|
227
|
+
header: () => h('span', { class: 'font-semibold' }, 'Account Profile'),
|
|
228
|
+
default: () => h('div', { class: 'flex flex-col gap-3' }, [
|
|
225
229
|
h('div', { class: 'flex items-center justify-between' }, [
|
|
226
230
|
h('span', { class: 'text-sm opacity-70' }, 'User ID'),
|
|
227
231
|
h('code', { 'data-testid': 'grasp-account-id' }, auth.user?.id ?? '—'),
|
|
@@ -235,52 +239,19 @@ export const GraspAccountSettings = defineComponent({
|
|
|
235
239
|
h('span', { 'data-testid': 'grasp-account-email' }, auth.user?.email ?? '—'),
|
|
236
240
|
]),
|
|
237
241
|
h('div', { class: 'pt-2' }, [
|
|
238
|
-
|
|
242
|
+
h(ui.UButton, {
|
|
239
243
|
label: 'Sign out',
|
|
240
|
-
|
|
244
|
+
color: 'neutral',
|
|
241
245
|
variant: 'outline',
|
|
242
|
-
|
|
246
|
+
'data-testid': 'grasp-signout-btn',
|
|
243
247
|
onClick: handleLogout,
|
|
244
248
|
}),
|
|
245
249
|
]),
|
|
246
250
|
]),
|
|
247
251
|
}),
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
h('p', { class: 'text-sm opacity-80' }, 'Permanently delete your account, subscriptions, credits, and all associated data.'),
|
|
252
|
-
!confirmingDelete.value
|
|
253
|
-
? renderButton({
|
|
254
|
-
label: 'Delete Account',
|
|
255
|
-
tone: 'danger',
|
|
256
|
-
variant: 'outline',
|
|
257
|
-
testId: 'grasp-delete-account-start',
|
|
258
|
-
onClick: () => {
|
|
259
|
-
confirmingDelete.value = true;
|
|
260
|
-
},
|
|
261
|
-
})
|
|
262
|
-
: h('div', {
|
|
263
|
-
class: 'flex items-center gap-2',
|
|
264
|
-
'data-testid': 'grasp-delete-account-confirm-box',
|
|
265
|
-
}, [
|
|
266
|
-
renderButton({
|
|
267
|
-
label: 'Confirm Permanent Deletion',
|
|
268
|
-
tone: 'danger',
|
|
269
|
-
loading: auth.loading,
|
|
270
|
-
testId: 'grasp-delete-account-confirm',
|
|
271
|
-
onClick: handleDeleteAccount,
|
|
272
|
-
}),
|
|
273
|
-
renderButton({
|
|
274
|
-
label: 'Cancel',
|
|
275
|
-
tone: 'secondary',
|
|
276
|
-
variant: 'ghost',
|
|
277
|
-
onClick: () => {
|
|
278
|
-
confirmingDelete.value = false;
|
|
279
|
-
},
|
|
280
|
-
}),
|
|
281
|
-
]),
|
|
282
|
-
]),
|
|
283
|
-
}),
|
|
252
|
+
...(slots['extra'] ? slots['extra']() : []),
|
|
253
|
+
h(GraspDeleteAccountCard),
|
|
254
|
+
...(slots['footer'] ? slots['footer']() : []),
|
|
284
255
|
]);
|
|
285
256
|
},
|
|
286
257
|
});
|
|
@@ -293,43 +264,49 @@ export const GraspPricingTable = defineComponent({
|
|
|
293
264
|
},
|
|
294
265
|
currentPlanId: { type: String, required: true },
|
|
295
266
|
busy: { type: Boolean, default: false },
|
|
267
|
+
canCheckout: { type: Boolean, default: true },
|
|
296
268
|
},
|
|
297
269
|
emits: {
|
|
298
270
|
selectPlan: (_planId, _interval) => true,
|
|
299
271
|
},
|
|
300
272
|
setup(props, { emit }) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
h('span', plan.name),
|
|
273
|
+
const ui = useGraspUi();
|
|
274
|
+
return () => h('div', { class: 'grid gap-4 md:grid-cols-2', 'data-testid': 'grasp-pricing-table' }, props.plans.map((plan) => h(ui.UCard, { key: plan.id, 'data-testid': `grasp-plan-card-${plan.id}` }, {
|
|
275
|
+
header: () => h('div', { class: 'flex items-center justify-between' }, [
|
|
276
|
+
h('span', { class: 'font-semibold' }, plan.name),
|
|
306
277
|
props.currentPlanId === plan.id
|
|
307
|
-
?
|
|
278
|
+
? h(ui.UBadge, { label: 'Current', color: 'success', variant: 'subtle' })
|
|
308
279
|
: plan.trialDays
|
|
309
|
-
?
|
|
280
|
+
? h(ui.UBadge, {
|
|
281
|
+
label: `${plan.trialDays}d trial`,
|
|
282
|
+
color: 'info',
|
|
283
|
+
variant: 'subtle',
|
|
284
|
+
})
|
|
310
285
|
: null,
|
|
311
286
|
]),
|
|
312
|
-
|
|
287
|
+
default: () => h('div', { class: 'flex flex-col gap-3' }, [
|
|
313
288
|
h('ul', { class: 'flex flex-col gap-1 text-sm' }, Object.entries(plan.limits).map(([key, val]) => h('li', { key }, `${key}: ${String(val)}`))),
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
289
|
+
props.canCheckout
|
|
290
|
+
? h('div', { class: 'flex flex-wrap gap-2 pt-2' }, [
|
|
291
|
+
plan.prices.month
|
|
292
|
+
? h(ui.UButton, {
|
|
293
|
+
label: `Upgrade Monthly (${formatCurrency(plan.prices.month.unitAmount, plan.prices.month.currency)})`,
|
|
294
|
+
disabled: !plan.upgradable || props.busy,
|
|
295
|
+
'data-testid': `grasp-upgrade-${plan.id}-month`,
|
|
296
|
+
onClick: () => emit('selectPlan', plan.id, 'month'),
|
|
297
|
+
})
|
|
298
|
+
: null,
|
|
299
|
+
plan.prices.year
|
|
300
|
+
? h(ui.UButton, {
|
|
301
|
+
label: `Upgrade Yearly (${formatCurrency(plan.prices.year.unitAmount, plan.prices.year.currency)})`,
|
|
302
|
+
variant: 'outline',
|
|
303
|
+
disabled: !plan.upgradable || props.busy,
|
|
304
|
+
'data-testid': `grasp-upgrade-${plan.id}-year`,
|
|
305
|
+
onClick: () => emit('selectPlan', plan.id, 'year'),
|
|
306
|
+
})
|
|
307
|
+
: null,
|
|
308
|
+
])
|
|
309
|
+
: null,
|
|
333
310
|
]),
|
|
334
311
|
})));
|
|
335
312
|
},
|
|
@@ -337,6 +314,7 @@ export const GraspPricingTable = defineComponent({
|
|
|
337
314
|
export const GraspBillingPanel = defineComponent({
|
|
338
315
|
name: 'GraspBillingPanel',
|
|
339
316
|
setup() {
|
|
317
|
+
const ui = useGraspUi();
|
|
340
318
|
const billing = useBillingStore();
|
|
341
319
|
const notifications = useNotificationsStore();
|
|
342
320
|
onMounted(() => {
|
|
@@ -356,60 +334,77 @@ export const GraspBillingPanel = defineComponent({
|
|
|
356
334
|
if (!s) {
|
|
357
335
|
return h('div', { 'data-testid': 'grasp-billing-loading' }, [
|
|
358
336
|
billing.loading
|
|
359
|
-
? h(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
337
|
+
? h(ui.UProgress, {
|
|
338
|
+
color: 'primary',
|
|
339
|
+
size: 'sm',
|
|
340
|
+
'aria-label': 'Loading billing summary',
|
|
341
|
+
})
|
|
364
342
|
: null,
|
|
365
343
|
]);
|
|
366
344
|
}
|
|
367
345
|
return h('div', { class: 'mx-auto flex max-w-4xl flex-col gap-6', 'data-testid': 'grasp-billing-panel' }, [
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
346
|
+
s.effective.status === 'expired'
|
|
347
|
+
? h(ui.UAlert, {
|
|
348
|
+
color: 'warning',
|
|
349
|
+
variant: 'soft',
|
|
350
|
+
title: 'Access Expired',
|
|
351
|
+
description: s.effective.entitledThrough
|
|
352
|
+
? `Your previous access expired on ${new Date(s.effective.entitledThrough).toLocaleDateString()}.`
|
|
353
|
+
: 'Your previous access has expired.',
|
|
354
|
+
'data-testid': 'grasp-entitlement-expired',
|
|
355
|
+
})
|
|
356
|
+
: null,
|
|
357
|
+
h(ui.UCard, null, {
|
|
358
|
+
header: () => h('span', { class: 'font-semibold' }, 'Current Subscription & Credits'),
|
|
359
|
+
default: () => h('div', { class: 'flex flex-col gap-3' }, [
|
|
371
360
|
h('div', { class: 'flex flex-wrap items-center gap-3' }, [
|
|
372
361
|
h('span', { class: 'text-lg font-semibold', 'data-testid': 'grasp-current-plan' }, s.effective.planName),
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
362
|
+
h(ui.UBadge, {
|
|
363
|
+
label: s.effective.status,
|
|
364
|
+
color: s.effective.status === 'expired' ? 'warning' : 'info',
|
|
365
|
+
variant: 'subtle',
|
|
366
|
+
}),
|
|
367
|
+
h(ui.UBadge, {
|
|
368
|
+
label: `${s.effective.creditBalance} credits`,
|
|
369
|
+
color: 'neutral',
|
|
370
|
+
variant: 'subtle',
|
|
371
|
+
'data-testid': 'grasp-credit-balance',
|
|
378
372
|
}),
|
|
379
373
|
]),
|
|
380
|
-
s.canManagePortal
|
|
374
|
+
s.mode === 'stripe' && s.canManagePortal
|
|
381
375
|
? h('div', [
|
|
382
|
-
|
|
376
|
+
h(ui.UButton, {
|
|
383
377
|
label: 'Manage Billing in Stripe',
|
|
384
378
|
variant: 'outline',
|
|
385
379
|
disabled: billing.busy,
|
|
386
|
-
|
|
380
|
+
'data-testid': 'grasp-manage-portal-btn',
|
|
387
381
|
onClick: handleManagePortal,
|
|
388
382
|
}),
|
|
389
383
|
])
|
|
390
384
|
: null,
|
|
391
385
|
]),
|
|
392
386
|
}),
|
|
393
|
-
s.
|
|
387
|
+
s.mode !== 'disabled' && s.plans.length > 0
|
|
394
388
|
? h(GraspPricingTable, {
|
|
395
389
|
plans: s.plans,
|
|
396
390
|
currentPlanId: s.effective.planId,
|
|
397
391
|
busy: billing.busy,
|
|
392
|
+
canCheckout: s.mode === 'stripe',
|
|
398
393
|
onSelectPlan: handleSelectPlan,
|
|
399
394
|
})
|
|
400
395
|
: null,
|
|
401
|
-
s.
|
|
402
|
-
?
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
content: () => h('div', { class: 'flex flex-wrap gap-3' }, s.creditPacks.map((pack) => renderButton({
|
|
396
|
+
s.mode === 'stripe' && s.creditPacks.length > 0
|
|
397
|
+
? h(ui.UCard, { 'data-testid': 'grasp-credit-packs' }, {
|
|
398
|
+
header: () => h('span', { class: 'font-semibold' }, 'Credit Packs'),
|
|
399
|
+
default: () => h('div', { class: 'flex flex-wrap gap-3' }, s.creditPacks.map((pack) => h(ui.UButton, {
|
|
406
400
|
key: pack.id,
|
|
407
401
|
label: pack.unitAmount !== undefined && pack.currency !== undefined
|
|
408
402
|
? `${pack.name} (${formatCurrency(pack.unitAmount, pack.currency)})`
|
|
409
403
|
: pack.name,
|
|
410
|
-
|
|
404
|
+
color: 'neutral',
|
|
405
|
+
variant: 'outline',
|
|
411
406
|
disabled: billing.busy,
|
|
412
|
-
|
|
407
|
+
'data-testid': `grasp-buy-pack-${pack.id}`,
|
|
413
408
|
onClick: () => handleBuyCredits(pack.id),
|
|
414
409
|
}))),
|
|
415
410
|
})
|
|
@@ -421,13 +416,16 @@ export const GraspBillingPanel = defineComponent({
|
|
|
421
416
|
export const GraspShellLayout = defineComponent({
|
|
422
417
|
name: 'GraspShellLayout',
|
|
423
418
|
setup(_props, { slots }) {
|
|
419
|
+
const ui = useGraspUi();
|
|
424
420
|
const config = useGraspConfig();
|
|
425
421
|
const auth = useAuthStore();
|
|
426
422
|
const navItems = inject(GRASP_NAV_KEY, []);
|
|
423
|
+
const theme = inject(GRASP_THEME_KEY, null);
|
|
427
424
|
const layoutMode = computed(() => config.ui.layout);
|
|
425
|
+
const showColorMode = computed(() => theme?.colorMode !== false);
|
|
428
426
|
const allNav = computed(() => [
|
|
429
427
|
...navItems,
|
|
430
|
-
...(config.billing.
|
|
428
|
+
...(config.billing.mode !== 'disabled' ? [{ label: 'Billing', to: '/billing' }] : []),
|
|
431
429
|
...(config.auth.enabled !== false ? [{ label: 'Settings', to: '/settings' }] : []),
|
|
432
430
|
]);
|
|
433
431
|
const renderNavLinks = (row = false) => h('nav', { class: row ? 'flex items-center gap-3' : 'flex flex-col gap-1' }, allNav.value.map((item) => h(RouterLink, {
|
|
@@ -435,6 +433,12 @@ export const GraspShellLayout = defineComponent({
|
|
|
435
433
|
to: item.to,
|
|
436
434
|
class: 'rounded-md px-3 py-2 text-sm font-medium hover:bg-elevated',
|
|
437
435
|
}, { default: () => item.label })));
|
|
436
|
+
const renderColorModeButton = () => showColorMode.value
|
|
437
|
+
? h(ui.UColorModeButton, {
|
|
438
|
+
size: 'sm',
|
|
439
|
+
'data-testid': 'grasp-color-mode-toggle',
|
|
440
|
+
})
|
|
441
|
+
: null;
|
|
438
442
|
return () => {
|
|
439
443
|
if (layoutMode.value === 'minimal') {
|
|
440
444
|
return h('div', { class: 'min-h-screen p-6', 'data-testid': 'grasp-layout-minimal' }, [
|
|
@@ -448,7 +452,10 @@ export const GraspShellLayout = defineComponent({
|
|
|
448
452
|
h('span', { class: 'font-semibold' }, config.app.displayName),
|
|
449
453
|
renderNavLinks(true),
|
|
450
454
|
]),
|
|
451
|
-
h('
|
|
455
|
+
h('div', { class: 'flex items-center gap-3' }, [
|
|
456
|
+
renderColorModeButton(),
|
|
457
|
+
h('span', { class: 'text-sm opacity-75' }, auth.user?.displayName ?? auth.user?.email ?? ''),
|
|
458
|
+
]),
|
|
452
459
|
]),
|
|
453
460
|
h('main', { class: 'flex-1 p-6' }, [
|
|
454
461
|
slots['default'] ? slots['default']() : h(RouterView),
|
|
@@ -458,7 +465,10 @@ export const GraspShellLayout = defineComponent({
|
|
|
458
465
|
return h('div', { class: 'flex min-h-screen', 'data-testid': 'grasp-layout-sidebar' }, [
|
|
459
466
|
h('aside', { class: 'w-60 border-r border-default p-4 flex flex-col justify-between' }, [
|
|
460
467
|
h('div', { class: 'flex flex-col gap-4' }, [
|
|
461
|
-
h('div', { class: 'px-3
|
|
468
|
+
h('div', { class: 'flex items-center justify-between px-3' }, [
|
|
469
|
+
h('span', { class: 'font-semibold' }, config.app.displayName),
|
|
470
|
+
renderColorModeButton(),
|
|
471
|
+
]),
|
|
462
472
|
renderNavLinks(false),
|
|
463
473
|
]),
|
|
464
474
|
h('div', { class: 'px-3 text-xs opacity-70' }, [
|