@molecule/app-settings-panel-vue 0.0.0-stage → 1.1.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/LICENSE +202 -0
- package/README.md +781 -2
- package/dist/AccountSection.d.ts +23 -0
- package/dist/AccountSection.d.ts.map +1 -0
- package/dist/AccountSection.js +139 -0
- package/dist/AccountSection.js.map +1 -0
- package/dist/AppearanceSection.d.ts +20 -0
- package/dist/AppearanceSection.d.ts.map +1 -0
- package/dist/AppearanceSection.js +47 -0
- package/dist/AppearanceSection.js.map +1 -0
- package/dist/AuthSection.d.ts +30 -0
- package/dist/AuthSection.d.ts.map +1 -0
- package/dist/AuthSection.js +320 -0
- package/dist/AuthSection.js.map +1 -0
- package/dist/BillingSection.d.ts +51 -0
- package/dist/BillingSection.d.ts.map +1 -0
- package/dist/BillingSection.js +84 -0
- package/dist/BillingSection.js.map +1 -0
- package/dist/DevicesSection.d.ts +52 -0
- package/dist/DevicesSection.d.ts.map +1 -0
- package/dist/DevicesSection.js +171 -0
- package/dist/DevicesSection.js.map +1 -0
- package/dist/LogOutDeleteSection.d.ts +22 -0
- package/dist/LogOutDeleteSection.d.ts.map +1 -0
- package/dist/LogOutDeleteSection.js +129 -0
- package/dist/LogOutDeleteSection.js.map +1 -0
- package/dist/NotificationsSection.d.ts +27 -0
- package/dist/NotificationsSection.d.ts.map +1 -0
- package/dist/NotificationsSection.js +148 -0
- package/dist/NotificationsSection.js.map +1 -0
- package/dist/SettingsContainer.d.ts +39 -0
- package/dist/SettingsContainer.d.ts.map +1 -0
- package/dist/SettingsContainer.js +48 -0
- package/dist/SettingsContainer.js.map +1 -0
- package/dist/ThisDeviceSection.d.ts +21 -0
- package/dist/ThisDeviceSection.d.ts.map +1 -0
- package/dist/ThisDeviceSection.js +57 -0
- package/dist/ThisDeviceSection.js.map +1 -0
- package/dist/TiersUpgradeSection.d.ts +56 -0
- package/dist/TiersUpgradeSection.d.ts.map +1 -0
- package/dist/TiersUpgradeSection.js +218 -0
- package/dist/TiersUpgradeSection.js.map +1 -0
- package/dist/context.d.ts +25 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +20 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/pushToggle.d.ts +12 -0
- package/dist/pushToggle.d.ts.map +1 -0
- package/dist/pushToggle.js +11 -0
- package/dist/pushToggle.js.map +1 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -4
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue push-notification toggle section: the full receive-side enable chain
|
|
3
|
+
* over the shared current-device push helpers.
|
|
4
|
+
*
|
|
5
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
6
|
+
* `NotificationsSection` — the same DOM, callbacks and service calls.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { defineComponent, h, onMounted, onUnmounted, ref } from 'vue';
|
|
11
|
+
import { disablePushOnCurrentDevice, enablePushOnCurrentDevice, readCurrentDevicePushEnabled, } from '@molecule/app-push';
|
|
12
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
13
|
+
import { Flex, Switch } from '@molecule/app-ui-vue';
|
|
14
|
+
import { useHttpClient, usePush, useTranslation } from '@molecule/app-vue';
|
|
15
|
+
/**
|
|
16
|
+
* Push-notification toggle section — the full receive-side enable chain:
|
|
17
|
+
* browser permission → runtime VAPID public key
|
|
18
|
+
* (`GET /api/devices/push/public-key`) → `pushManager.subscribe` with
|
|
19
|
+
* `applicationServerKey` → PATCH the subscription onto the current device
|
|
20
|
+
* row (`/api/devices/:id { pushSubscription, hasPushSubscription }`), which
|
|
21
|
+
* is where the api-side push fan-outs look for it.
|
|
22
|
+
*
|
|
23
|
+
* Initial state reflects SERVER truth (the current device row's
|
|
24
|
+
* `hasPushSubscription`), and every failure surfaces as an honest inline
|
|
25
|
+
* message — a dev build without a service worker fails fast instead of
|
|
26
|
+
* hanging the switch.
|
|
27
|
+
*
|
|
28
|
+
* @returns The notifications section component.
|
|
29
|
+
*/
|
|
30
|
+
export const NotificationsSection = defineComponent({
|
|
31
|
+
name: 'NotificationsSection',
|
|
32
|
+
setup() {
|
|
33
|
+
const cm = getClassMap();
|
|
34
|
+
const { t } = useTranslation();
|
|
35
|
+
const http = useHttpClient();
|
|
36
|
+
const { requestPermission, register, unregister } = usePush();
|
|
37
|
+
const enabled = ref(false);
|
|
38
|
+
const busy = ref(false);
|
|
39
|
+
const error = ref(null);
|
|
40
|
+
let cancelled = false;
|
|
41
|
+
onMounted(() => {
|
|
42
|
+
// Server truth for THIS device; resolves false (never throws) when the
|
|
43
|
+
// devices endpoint is unavailable.
|
|
44
|
+
void readCurrentDevicePushEnabled(http).then((serverEnabled) => {
|
|
45
|
+
if (!cancelled && serverEnabled)
|
|
46
|
+
enabled.value = true;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
onUnmounted(() => {
|
|
50
|
+
cancelled = true;
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Maps a failed toggle result to its honest inline message.
|
|
54
|
+
*
|
|
55
|
+
* @param result - The failing toggle result.
|
|
56
|
+
* @returns The message to render under the switch.
|
|
57
|
+
*/
|
|
58
|
+
const failureMessage = (result) => {
|
|
59
|
+
switch (result.reason) {
|
|
60
|
+
case 'permission-denied':
|
|
61
|
+
return t('settings.pushPermissionDenied', undefined, {
|
|
62
|
+
defaultValue: 'Notification permission was denied.',
|
|
63
|
+
});
|
|
64
|
+
case 'server-unconfigured':
|
|
65
|
+
return t('settings.pushServerUnavailable', undefined, {
|
|
66
|
+
defaultValue: 'Push notifications are not configured on this server.',
|
|
67
|
+
});
|
|
68
|
+
case 'register-failed':
|
|
69
|
+
// The push provider throws already-localized messages (not supported /
|
|
70
|
+
// no service worker in a dev build / push-service rejection).
|
|
71
|
+
return (result.message ||
|
|
72
|
+
t('settings.pushUpdateFailed', undefined, {
|
|
73
|
+
defaultValue: 'Could not update push notification settings.',
|
|
74
|
+
}));
|
|
75
|
+
case 'persist-failed':
|
|
76
|
+
// `result.message` here is the HTTP client's error (a status line or a
|
|
77
|
+
// network error), not text written for the user, so it is not shown.
|
|
78
|
+
return t('settings.pushUpdateFailed', undefined, {
|
|
79
|
+
defaultValue: 'Could not update push notification settings.',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Runs the enable or disable chain for the switch's next state.
|
|
85
|
+
*
|
|
86
|
+
* @param next - The state the user toggled to.
|
|
87
|
+
*/
|
|
88
|
+
const handleToggle = async (next) => {
|
|
89
|
+
if (busy.value)
|
|
90
|
+
return;
|
|
91
|
+
busy.value = true;
|
|
92
|
+
error.value = null;
|
|
93
|
+
try {
|
|
94
|
+
if (next) {
|
|
95
|
+
const result = await enablePushOnCurrentDevice({ http, requestPermission, register });
|
|
96
|
+
if (result.ok) {
|
|
97
|
+
enabled.value = true;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
error.value = failureMessage(result);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const result = await disablePushOnCurrentDevice({ http, unregister });
|
|
105
|
+
// The switch goes off locally either way; a failed server clear is
|
|
106
|
+
// still reported so the user knows sends may continue.
|
|
107
|
+
enabled.value = false;
|
|
108
|
+
if (!result.ok) {
|
|
109
|
+
error.value = failureMessage(result);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
busy.value = false;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return () => h('section', [
|
|
118
|
+
h('h3', { class: cm.cn(cm.sectionHeading, cm.sp('mb', 3)) }, [
|
|
119
|
+
t('settings.notifications', undefined, { defaultValue: 'Notifications' }),
|
|
120
|
+
]),
|
|
121
|
+
h(Flex, { align: 'center', justify: 'between' }, () => [
|
|
122
|
+
h('span', { class: cm.textSize('sm') }, [
|
|
123
|
+
t('settings.pushNotifications', undefined, { defaultValue: 'Push notifications' }),
|
|
124
|
+
]),
|
|
125
|
+
h(Switch, {
|
|
126
|
+
checked: enabled.value,
|
|
127
|
+
disabled: busy.value,
|
|
128
|
+
// The visible text is a SIBLING span, not the Switch's label —
|
|
129
|
+
// without aria-label the control is announced as just "switch".
|
|
130
|
+
'aria-label': t('settings.pushNotifications', undefined, {
|
|
131
|
+
defaultValue: 'Push notifications',
|
|
132
|
+
}),
|
|
133
|
+
onChange: (e) => handleToggle(e.target.checked),
|
|
134
|
+
size: 'sm',
|
|
135
|
+
'data-mol-id': 'settings-push-toggle',
|
|
136
|
+
}),
|
|
137
|
+
]),
|
|
138
|
+
error.value
|
|
139
|
+
? h('p', {
|
|
140
|
+
class: cm.cn(cm.textSize('xs'), cm.textError, cm.sp('mt', 1)),
|
|
141
|
+
role: 'alert',
|
|
142
|
+
'data-mol-id': 'settings-push-error',
|
|
143
|
+
}, [error.value])
|
|
144
|
+
: null,
|
|
145
|
+
]);
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
//# sourceMappingURL=NotificationsSection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationsSection.js","sourceRoot":"","sources":["../src/NotificationsSection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAY,GAAG,EAAmB,MAAM,KAAK,CAAA;AAGhG,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,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AK;gBACT,CAAC,CAAC,CAAC,CACC,GAAG,EACH;oBACE,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;oBAC7D,IAAI,EAAE,OAAO;oBACb,aAAa,EAAE,qBAAqB;iBACrC,EACD,CAAC,KAAK,CAAC,KAAK,CAAC,CACd;gBACH,CAAC,CAAC,IAAI;SACT,CAAC,CAAA;IACN,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue outer settings-panel layout: a padded vertical stack that hosts the
|
|
3
|
+
* section components and publishes `onClose` through
|
|
4
|
+
* {@link SettingsPanelContext}.
|
|
5
|
+
*
|
|
6
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
7
|
+
* `SettingsContainer` — the same props (React names), the same DOM.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type PropType, type VNodeChild } from 'vue';
|
|
12
|
+
/**
|
|
13
|
+
* Outer settings-panel layout: padded vertical stack that hosts the
|
|
14
|
+
* section sub-components. Publishes `onClose` to descendants via
|
|
15
|
+
* context so `<LogOutDeleteSection>` etc. can dismiss the panel
|
|
16
|
+
* after an action without explicit prop threading.
|
|
17
|
+
*
|
|
18
|
+
* Children go through the default slot; `onClose` is passed as the
|
|
19
|
+
* `onClose` prop or bound as `@close` — both reach the same listener.
|
|
20
|
+
*
|
|
21
|
+
* @param props - Component props.
|
|
22
|
+
* @returns The container component.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SettingsContainer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
25
|
+
/** Dismisses the settings panel; published to sections as the panel context. */
|
|
26
|
+
onClose: {
|
|
27
|
+
type: PropType<() => void>;
|
|
28
|
+
required: true;
|
|
29
|
+
};
|
|
30
|
+
}>, () => VNodeChild, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "close"[], "close", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
31
|
+
/** Dismisses the settings panel; published to sections as the panel context. */
|
|
32
|
+
onClose: {
|
|
33
|
+
type: PropType<() => void>;
|
|
34
|
+
required: true;
|
|
35
|
+
};
|
|
36
|
+
}>> & Readonly<{
|
|
37
|
+
onClose?: ((...args: any[]) => any) | undefined;
|
|
38
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
39
|
+
//# sourceMappingURL=SettingsContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsContainer.d.ts","sourceRoot":"","sources":["../src/SettingsContainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsB,KAAK,QAAQ,EAAW,KAAK,UAAU,EAAE,MAAM,KAAK,CAAA;AAMjF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB;IAG1B,gFAAgF;;cAE5D,QAAQ,CAAC,MAAM,IAAI,CAAC;;;UAe7B,UAAU;IAjBrB,gFAAgF;;cAE5D,QAAQ,CAAC,MAAM,IAAI,CAAC;;;;;iFAkB1C,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue outer settings-panel layout: a padded vertical stack that hosts the
|
|
3
|
+
* section components and publishes `onClose` through
|
|
4
|
+
* {@link SettingsPanelContext}.
|
|
5
|
+
*
|
|
6
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
7
|
+
* `SettingsContainer` — the same props (React names), the same DOM.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { defineComponent, h, provide } from 'vue';
|
|
12
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
13
|
+
import { SettingsPanelContext } from './context.js';
|
|
14
|
+
/**
|
|
15
|
+
* Outer settings-panel layout: padded vertical stack that hosts the
|
|
16
|
+
* section sub-components. Publishes `onClose` to descendants via
|
|
17
|
+
* context so `<LogOutDeleteSection>` etc. can dismiss the panel
|
|
18
|
+
* after an action without explicit prop threading.
|
|
19
|
+
*
|
|
20
|
+
* Children go through the default slot; `onClose` is passed as the
|
|
21
|
+
* `onClose` prop or bound as `@close` — both reach the same listener.
|
|
22
|
+
*
|
|
23
|
+
* @param props - Component props.
|
|
24
|
+
* @returns The container component.
|
|
25
|
+
*/
|
|
26
|
+
export const SettingsContainer = defineComponent({
|
|
27
|
+
name: 'SettingsContainer',
|
|
28
|
+
props: {
|
|
29
|
+
/** Dismisses the settings panel; published to sections as the panel context. */
|
|
30
|
+
onClose: {
|
|
31
|
+
type: Function,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
emits: ['close'],
|
|
36
|
+
setup(props, { emit, slots }) {
|
|
37
|
+
const cm = getClassMap();
|
|
38
|
+
// React's context value is memoized on [onClose]; the injected object is
|
|
39
|
+
// created once in setup and reads the current listener at call time.
|
|
40
|
+
provide(SettingsPanelContext, {
|
|
41
|
+
onClose: () => {
|
|
42
|
+
emit('close');
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
return () => h('div', { class: cm.cn(cm.sp('p', 6), cm.stack(6)) }, slots.default?.());
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=SettingsContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsContainer.js","sourceRoot":"","sources":["../src/SettingsContainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAAiB,OAAO,EAAmB,MAAM,KAAK,CAAA;AAEjF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;IAC/C,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE;QACL,gFAAgF;QAChF,OAAO,EAAE;YACP,IAAI,EAAE,QAAgC;YACtC,QAAQ,EAAE,IAAI;SACf;KACF;IACD,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,KAAK,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;QAC1B,MAAM,EAAE,GAAG,WAAW,EAAE,CAAA;QACxB,yEAAyE;QACzE,qEAAqE;QACrE,OAAO,CAAC,oBAAoB,EAAE;YAC5B,OAAO,EAAE,GAAS,EAAE;gBAClB,IAAI,CAAC,OAAO,CAAC,CAAA;YACf,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,GAAe,EAAE,CACtB,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IAC7E,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue "This device" detail strip: the current device's OS, browser and
|
|
3
|
+
* online/offline state.
|
|
4
|
+
*
|
|
5
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
6
|
+
* `ThisDeviceSection` — the same DOM, callbacks and service calls.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type VNodeChild } from 'vue';
|
|
11
|
+
/**
|
|
12
|
+
* "This device" detail strip — OS, browser, online/offline.
|
|
13
|
+
*
|
|
14
|
+
* Reads everything from `@molecule/app-device` through the `useDevice`
|
|
15
|
+
* composable (`deviceInfo` and `isOnline()`), so the bonded device provider
|
|
16
|
+
* decides what it shows. No side effects, no app-specific state.
|
|
17
|
+
*
|
|
18
|
+
* @returns The this-device section component.
|
|
19
|
+
*/
|
|
20
|
+
export declare const ThisDeviceSection: import("vue").DefineComponent<{}, () => VNodeChild, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
21
|
+
//# sourceMappingURL=ThisDeviceSection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThisDeviceSection.d.ts","sourceRoot":"","sources":["../src/ThisDeviceSection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,KAAK,CAAA;AAMnE;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,0CAsBf,UAAU,yOAwBvB,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue "This device" detail strip: the current device's OS, browser and
|
|
3
|
+
* online/offline state.
|
|
4
|
+
*
|
|
5
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
6
|
+
* `ThisDeviceSection` — the same DOM, callbacks and service calls.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { computed, defineComponent, h } from 'vue';
|
|
11
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
12
|
+
import { Flex } from '@molecule/app-ui-vue';
|
|
13
|
+
import { useDevice, useTranslation } from '@molecule/app-vue';
|
|
14
|
+
/**
|
|
15
|
+
* "This device" detail strip — OS, browser, online/offline.
|
|
16
|
+
*
|
|
17
|
+
* Reads everything from `@molecule/app-device` through the `useDevice`
|
|
18
|
+
* composable (`deviceInfo` and `isOnline()`), so the bonded device provider
|
|
19
|
+
* decides what it shows. No side effects, no app-specific state.
|
|
20
|
+
*
|
|
21
|
+
* @returns The this-device section component.
|
|
22
|
+
*/
|
|
23
|
+
export const ThisDeviceSection = defineComponent({
|
|
24
|
+
name: 'ThisDeviceSection',
|
|
25
|
+
setup() {
|
|
26
|
+
const cm = getClassMap();
|
|
27
|
+
const { t, locale } = useTranslation();
|
|
28
|
+
const { deviceInfo, isOnline } = useDevice();
|
|
29
|
+
// React reads `isOnline()` during every render. The locale key makes this
|
|
30
|
+
// re-run exactly when the rendered output can change: the binding's mount
|
|
31
|
+
// reconciliation re-reads the SAME locale (the computed keeps its cached
|
|
32
|
+
// answer, so no second provider call), while a locale switch re-runs it.
|
|
33
|
+
const online = computed(() => {
|
|
34
|
+
void locale.value;
|
|
35
|
+
return isOnline();
|
|
36
|
+
});
|
|
37
|
+
/** Renders one label/value row of the detail list. */
|
|
38
|
+
const row = (label, value) => h(Flex, { justify: 'between' }, () => [
|
|
39
|
+
h('dt', { class: cm.textMuted }, [label]),
|
|
40
|
+
h('dd', [value]),
|
|
41
|
+
]);
|
|
42
|
+
return () => h('section', [
|
|
43
|
+
h('h3', { class: cm.cn(cm.sectionHeading, cm.sp('mb', 3)) }, [
|
|
44
|
+
t('settings.thisDevice', undefined, { defaultValue: 'This Device' }),
|
|
45
|
+
]),
|
|
46
|
+
h('dl', { class: cm.cn(cm.stack(1), cm.textSize('sm')) }, [
|
|
47
|
+
row(t('settings.platform', undefined, { defaultValue: 'Platform' }), deviceInfo.os.name || t('settings.unknown', undefined, { defaultValue: 'Unknown' })),
|
|
48
|
+
row(t('settings.browser', undefined, { defaultValue: 'Browser' }), deviceInfo.browser.name ||
|
|
49
|
+
t('settings.unknown', undefined, { defaultValue: 'Unknown' })),
|
|
50
|
+
row(t('settings.network', undefined, { defaultValue: 'Network' }), online.value
|
|
51
|
+
? t('settings.online', undefined, { defaultValue: 'Online' })
|
|
52
|
+
: t('settings.offline', undefined, { defaultValue: 'Offline' })),
|
|
53
|
+
]),
|
|
54
|
+
]);
|
|
55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AS,EAAE,CAAC,CAClE;aACF,CAAC;SACH,CAAC,CAAA;IACN,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue billing section with the full multi-tier upgrade flow.
|
|
3
|
+
*
|
|
4
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
5
|
+
* `TiersUpgradeSection` — the same DOM, callbacks and service calls.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type PropType, type VNodeChild } from 'vue';
|
|
10
|
+
import type { TiersUpgradeSectionProps } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Billing section with full multi-tier upgrade flow.
|
|
13
|
+
*
|
|
14
|
+
* Replaces the simpler `<BillingSection>` for apps backed by
|
|
15
|
+
* `@molecule/api-payments-stripe` + `@molecule/api-resource-payment`
|
|
16
|
+
* — loads the user's current plan from `/api/billing/status`,
|
|
17
|
+
* loads available tiers from `/api/billing/tiers`, and renders an
|
|
18
|
+
* Upgrade modal with a Subscribe button per tier price. Subscribe
|
|
19
|
+
* POSTs to `/api/billing/checkout` and redirects to the Stripe
|
|
20
|
+
* checkout URL; paid users see a Cancel button that POSTs to
|
|
21
|
+
* `/api/billing/cancel`. A refused request shows the server's message.
|
|
22
|
+
*
|
|
23
|
+
* @returns The multi-tier billing section component.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TiersUpgradeSection: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
26
|
+
/**
|
|
27
|
+
* How the page leaves for the checkout URL the server returns. Defaults
|
|
28
|
+
* to a full-page navigation (`openUrl`, which refuses anything but
|
|
29
|
+
* http(s)); pass an in-app browser opener on native.
|
|
30
|
+
*/
|
|
31
|
+
redirectToCheckout: {
|
|
32
|
+
type: PropType<TiersUpgradeSectionProps["redirectToCheckout"]>;
|
|
33
|
+
required: false;
|
|
34
|
+
default: (url: string, options?: {
|
|
35
|
+
newWindow?: boolean;
|
|
36
|
+
target?: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
};
|
|
39
|
+
}>, () => VNodeChild, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
40
|
+
/**
|
|
41
|
+
* How the page leaves for the checkout URL the server returns. Defaults
|
|
42
|
+
* to a full-page navigation (`openUrl`, which refuses anything but
|
|
43
|
+
* http(s)); pass an in-app browser opener on native.
|
|
44
|
+
*/
|
|
45
|
+
redirectToCheckout: {
|
|
46
|
+
type: PropType<TiersUpgradeSectionProps["redirectToCheckout"]>;
|
|
47
|
+
required: false;
|
|
48
|
+
default: (url: string, options?: {
|
|
49
|
+
newWindow?: boolean;
|
|
50
|
+
target?: string;
|
|
51
|
+
}) => void;
|
|
52
|
+
};
|
|
53
|
+
}>> & Readonly<{}>, {
|
|
54
|
+
redirectToCheckout: ((checkoutUrl: string) => void) | undefined;
|
|
55
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
56
|
+
//# sourceMappingURL=TiersUpgradeSection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TiersUpgradeSection.d.ts","sourceRoot":"","sources":["../src/TiersUpgradeSection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAKL,KAAK,QAAQ,EAGb,KAAK,UAAU,EAChB,MAAM,KAAK,CAAA;AAQZ,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAgB1D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB;IAG5B;;;;OAIG;;cAEiB,QAAQ,CAAC,wBAAwB,CAAC,oBAAoB,CAAC,CAAC;;;qBAJV,CAAC;kBACnD,CAAC;;;UAsHN,UAAU;IAzHrB;;;;OAIG;;cAEiB,QAAQ,CAAC,wBAAwB,CAAC,oBAAoB,CAAC,CAAC;;;qBAJV,CAAC;kBACnD,CAAC;;;;;4EAsNnB,CAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue billing section with the full multi-tier upgrade flow.
|
|
3
|
+
*
|
|
4
|
+
* Vue counterpart of `@molecule/app-settings-panel-react`'s
|
|
5
|
+
* `TiersUpgradeSection` — the same DOM, callbacks and service calls.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { defineComponent, h, onMounted, onUnmounted, ref, } from 'vue';
|
|
10
|
+
import { serverErrorMessage } from '@molecule/app-http';
|
|
11
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
12
|
+
import { Alert, Button, ConfirmButton, Flex, Modal } from '@molecule/app-ui-vue';
|
|
13
|
+
import { openUrl } from '@molecule/app-utilities';
|
|
14
|
+
import { useHttpClient, useTranslation } from '@molecule/app-vue';
|
|
15
|
+
/**
|
|
16
|
+
* Billing section with full multi-tier upgrade flow.
|
|
17
|
+
*
|
|
18
|
+
* Replaces the simpler `<BillingSection>` for apps backed by
|
|
19
|
+
* `@molecule/api-payments-stripe` + `@molecule/api-resource-payment`
|
|
20
|
+
* — loads the user's current plan from `/api/billing/status`,
|
|
21
|
+
* loads available tiers from `/api/billing/tiers`, and renders an
|
|
22
|
+
* Upgrade modal with a Subscribe button per tier price. Subscribe
|
|
23
|
+
* POSTs to `/api/billing/checkout` and redirects to the Stripe
|
|
24
|
+
* checkout URL; paid users see a Cancel button that POSTs to
|
|
25
|
+
* `/api/billing/cancel`. A refused request shows the server's message.
|
|
26
|
+
*
|
|
27
|
+
* @returns The multi-tier billing section component.
|
|
28
|
+
*/
|
|
29
|
+
export const TiersUpgradeSection = defineComponent({
|
|
30
|
+
name: 'TiersUpgradeSection',
|
|
31
|
+
props: {
|
|
32
|
+
/**
|
|
33
|
+
* How the page leaves for the checkout URL the server returns. Defaults
|
|
34
|
+
* to a full-page navigation (`openUrl`, which refuses anything but
|
|
35
|
+
* http(s)); pass an in-app browser opener on native.
|
|
36
|
+
*/
|
|
37
|
+
redirectToCheckout: {
|
|
38
|
+
type: Function,
|
|
39
|
+
required: false,
|
|
40
|
+
default: openUrl,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
setup(props) {
|
|
44
|
+
const cm = getClassMap();
|
|
45
|
+
const { t } = useTranslation();
|
|
46
|
+
const http = useHttpClient();
|
|
47
|
+
const plan = ref('Free');
|
|
48
|
+
const planKey = ref('free');
|
|
49
|
+
const tiers = ref([]);
|
|
50
|
+
const showUpgrade = ref(false);
|
|
51
|
+
const upgradeLoading = ref(null);
|
|
52
|
+
const upgradeError = ref('');
|
|
53
|
+
let cancelled = false;
|
|
54
|
+
onMounted(() => {
|
|
55
|
+
void Promise.all([
|
|
56
|
+
// Each fetch resolves null on failure; the .then handler then keeps the
|
|
57
|
+
// defaults ('Free', empty tier list) instead of throwing.
|
|
58
|
+
http
|
|
59
|
+
.get('/api/billing/status')
|
|
60
|
+
.catch((_error) => null),
|
|
61
|
+
http
|
|
62
|
+
.get('/api/billing/tiers')
|
|
63
|
+
.catch((_error) => null),
|
|
64
|
+
])
|
|
65
|
+
.then(([statusRes, tiersRes]) => {
|
|
66
|
+
if (cancelled)
|
|
67
|
+
return;
|
|
68
|
+
const status = statusRes?.data ?? null;
|
|
69
|
+
if (status?.name)
|
|
70
|
+
plan.value = status.name;
|
|
71
|
+
if (status?.planKey)
|
|
72
|
+
planKey.value = status.planKey;
|
|
73
|
+
const list = tiersRes?.data?.data ?? [];
|
|
74
|
+
if (Array.isArray(list)) {
|
|
75
|
+
tiers.value = list.map((tier) => ({
|
|
76
|
+
planKey: tier.key,
|
|
77
|
+
name: tier.name,
|
|
78
|
+
prices: (tier.prices || []).map((p) => ({
|
|
79
|
+
stripePriceId: p.stripePriceId ?? undefined,
|
|
80
|
+
interval: p.period,
|
|
81
|
+
priceLabel: p.price,
|
|
82
|
+
})),
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.catch((_error) => {
|
|
87
|
+
// Fetch failures already resolve to null above; this only guards the
|
|
88
|
+
// mapping, keeping the section on its defaults rather than throwing.
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
onUnmounted(() => {
|
|
92
|
+
cancelled = true;
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Starts checkout for one price and leaves through the checkout URL;
|
|
96
|
+
* a refusal shows the server's message.
|
|
97
|
+
*
|
|
98
|
+
* @param stripePriceId - The Stripe price to subscribe to.
|
|
99
|
+
*/
|
|
100
|
+
const handleStartCheckout = async (stripePriceId) => {
|
|
101
|
+
upgradeError.value = '';
|
|
102
|
+
upgradeLoading.value = stripePriceId;
|
|
103
|
+
try {
|
|
104
|
+
const res = await http.post('/api/billing/checkout', { priceId: stripePriceId });
|
|
105
|
+
const data = res.data;
|
|
106
|
+
if (data?.checkoutUrl) {
|
|
107
|
+
props.redirectToCheckout(data.checkoutUrl);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (data?.updated) {
|
|
111
|
+
showUpgrade.value = false;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
upgradeError.value = t('settings.billing.checkoutFailed', undefined, {
|
|
115
|
+
defaultValue: 'Could not start checkout.',
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
upgradeError.value =
|
|
120
|
+
serverErrorMessage(err) ??
|
|
121
|
+
t('settings.billing.checkoutFailed', undefined, {
|
|
122
|
+
defaultValue: 'Could not start checkout.',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
upgradeLoading.value = null;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/** Cancels the subscription back to the free plan. */
|
|
130
|
+
const handleCancelSubscription = async () => {
|
|
131
|
+
upgradeError.value = '';
|
|
132
|
+
try {
|
|
133
|
+
await http.post('/api/billing/cancel', {});
|
|
134
|
+
plan.value = 'Free';
|
|
135
|
+
planKey.value = 'free';
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
upgradeError.value =
|
|
139
|
+
serverErrorMessage(err) ??
|
|
140
|
+
t('settings.billing.cancelFailed', undefined, {
|
|
141
|
+
defaultValue: 'Could not cancel.',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return () => [
|
|
146
|
+
h('section', [
|
|
147
|
+
h('h3', { class: cm.cn(cm.sectionHeading, cm.sp('mb', 3)) }, [
|
|
148
|
+
t('settings.billing', undefined, { defaultValue: 'Billing' }),
|
|
149
|
+
]),
|
|
150
|
+
h(Flex, { align: 'center', justify: 'between' }, () => [
|
|
151
|
+
h('span', { class: cm.textSize('sm') }, [
|
|
152
|
+
t('settings.plan', undefined, { defaultValue: 'Plan: ' }),
|
|
153
|
+
h('strong', [plan.value]),
|
|
154
|
+
]),
|
|
155
|
+
planKey.value === 'free'
|
|
156
|
+
? h(Button, { variant: 'outline', size: 'sm', onClick: () => (showUpgrade.value = true) }, () => [t('settings.upgrade', undefined, { defaultValue: 'Upgrade' })])
|
|
157
|
+
: h(ConfirmButton, {
|
|
158
|
+
variant: 'outline',
|
|
159
|
+
size: 'sm',
|
|
160
|
+
label: t('settings.billing.cancel', undefined, { defaultValue: 'Cancel' }),
|
|
161
|
+
confirmLabel: t('settings.billing.cancelConfirm', undefined, {
|
|
162
|
+
defaultValue: 'Cancel your subscription?',
|
|
163
|
+
}),
|
|
164
|
+
onConfirm: handleCancelSubscription,
|
|
165
|
+
'data-mol-id': 'billing-cancel-subscription',
|
|
166
|
+
}),
|
|
167
|
+
]),
|
|
168
|
+
]),
|
|
169
|
+
h(Modal, {
|
|
170
|
+
open: showUpgrade.value,
|
|
171
|
+
onClose: () => (showUpgrade.value = false),
|
|
172
|
+
title: t('settings.billing.upgradeTitle', undefined, {
|
|
173
|
+
defaultValue: 'Upgrade your plan',
|
|
174
|
+
}),
|
|
175
|
+
}, {
|
|
176
|
+
default: () => [
|
|
177
|
+
upgradeError.value
|
|
178
|
+
? h(Alert, { status: 'error', className: cm.sp('mb', 4) }, () => [upgradeError.value])
|
|
179
|
+
: null,
|
|
180
|
+
tiers.value.length === 0
|
|
181
|
+
? h('p', { class: cm.cn(cm.textSize('sm'), cm.textMuted) }, [
|
|
182
|
+
t('settings.billing.noTiers', undefined, {
|
|
183
|
+
defaultValue: 'No paid plans configured.',
|
|
184
|
+
}),
|
|
185
|
+
])
|
|
186
|
+
: h('ul', { class: cm.stack(3) }, tiers.value
|
|
187
|
+
.filter((tier) => tier.planKey !== 'free')
|
|
188
|
+
.flatMap((tier) => tier.prices.filter((p) => p.stripePriceId).map((price) => ({ tier, price })))
|
|
189
|
+
.map(({ tier, price }) => h('li', { key: `${tier.planKey}-${price.stripePriceId}`, class: cm.sp('p', 4) }, [
|
|
190
|
+
h(Flex, { align: 'center', justify: 'between' }, () => [
|
|
191
|
+
h('div', [
|
|
192
|
+
h('p', { class: cm.fontWeight('semibold') }, [
|
|
193
|
+
`${tier.name} (${price.interval})`,
|
|
194
|
+
]),
|
|
195
|
+
h('p', { class: cm.cn(cm.textSize('xs'), cm.textMuted) }, [
|
|
196
|
+
price.priceLabel,
|
|
197
|
+
]),
|
|
198
|
+
]),
|
|
199
|
+
h(Button, {
|
|
200
|
+
size: 'sm',
|
|
201
|
+
loading: upgradeLoading.value === price.stripePriceId,
|
|
202
|
+
onClick: () => {
|
|
203
|
+
if (price.stripePriceId)
|
|
204
|
+
void handleStartCheckout(price.stripePriceId);
|
|
205
|
+
},
|
|
206
|
+
}, () => [
|
|
207
|
+
t('settings.billing.subscribe', undefined, {
|
|
208
|
+
defaultValue: 'Subscribe',
|
|
209
|
+
}),
|
|
210
|
+
]),
|
|
211
|
+
]),
|
|
212
|
+
]))),
|
|
213
|
+
],
|
|
214
|
+
}),
|
|
215
|
+
];
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
//# sourceMappingURL=TiersUpgradeSection.js.map
|
|
@@ -0,0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