@helpdice/theme 1.0.9 → 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/dist/css-baseline/index.js +0 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4025 -6
- package/dist/subscription/SubscriptionContext.d.ts +14 -0
- package/dist/subscription/SubscriptionError.d.ts +5 -0
- package/dist/subscription/UpgradeNotice.d.ts +3 -0
- package/dist/subscription/index.d.ts +3 -0
- package/dist/subscription/index.js +4072 -0
- package/dist/subscription/withSubscription.d.ts +2 -0
- package/dist/themes/index.js +0 -2
- package/dist/themes/presets/index.d.ts +0 -2
- package/dist/themes/shadows.d.ts +0 -2
- package/dist/ui-provider/index.js +3975 -6
- package/dist/use-all-themes/index.js +0 -2
- package/dist/use-media-query/index.js +0 -2
- package/dist/use-theme/index.js +0 -2
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -1
- package/esm/subscription/SubscriptionContext.d.ts +14 -0
- package/esm/subscription/SubscriptionContext.js +66 -0
- package/esm/subscription/SubscriptionError.d.ts +5 -0
- package/esm/subscription/SubscriptionError.js +13 -0
- package/esm/subscription/UpgradeNotice.d.ts +3 -0
- package/esm/subscription/UpgradeNotice.js +15 -0
- package/esm/subscription/index.d.ts +3 -0
- package/esm/subscription/index.js +3 -0
- package/esm/subscription/withSubscription.d.ts +2 -0
- package/esm/subscription/withSubscription.js +44 -0
- package/esm/themes/presets/index.d.ts +0 -2
- package/esm/themes/shadows.d.ts +0 -2
- package/esm/themes/shadows.js +0 -2
- package/esm/ui-provider/ui-provider.js +2 -1
- package/package.json +2 -1
package/dist/use-theme/index.js
CHANGED
package/esm/index.d.ts
CHANGED
|
@@ -22,3 +22,4 @@ export { default as Dropdown } from './shared/dropdown';
|
|
|
22
22
|
export { default as CssTransition } from './shared/css-transition';
|
|
23
23
|
export { default as Backdrop } from './shared/backdrop';
|
|
24
24
|
export { addColorAlpha, colorToRgbValues } from './utils/color';
|
|
25
|
+
export { withSubscription } from './subscription';
|
package/esm/index.js
CHANGED
|
@@ -17,4 +17,5 @@ export { default as Expand } from './shared/expand';
|
|
|
17
17
|
export { default as Dropdown } from './shared/dropdown';
|
|
18
18
|
export { default as CssTransition } from './shared/css-transition';
|
|
19
19
|
export { default as Backdrop } from './shared/backdrop';
|
|
20
|
-
export { addColorAlpha, colorToRgbValues } from './utils/color';
|
|
20
|
+
export { addColorAlpha, colorToRgbValues } from './utils/color';
|
|
21
|
+
export { withSubscription } from './subscription';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type SubscriptionState = {
|
|
3
|
+
status: 'loading';
|
|
4
|
+
} | {
|
|
5
|
+
status: 'active' | 'expired' | 'trial' | 'inactive';
|
|
6
|
+
} | {
|
|
7
|
+
status: 'error';
|
|
8
|
+
reason: 'OFFLINE' | 'SERVER_DOWN' | 'UNAUTHORIZED';
|
|
9
|
+
};
|
|
10
|
+
export declare const SubscriptionProvider: React.FC<{
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const useSubscription: () => SubscriptionState;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
// context/SubscriptionContext.tsx
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
5
|
+
import { Account } from '@helpdice/sdk';
|
|
6
|
+
var SubscriptionContext = /*#__PURE__*/createContext({
|
|
7
|
+
status: 'loading'
|
|
8
|
+
});
|
|
9
|
+
export var SubscriptionProvider = function SubscriptionProvider(_ref) {
|
|
10
|
+
var children = _ref.children;
|
|
11
|
+
var _useState = useState({
|
|
12
|
+
status: 'loading'
|
|
13
|
+
}),
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
15
|
+
state = _useState2[0],
|
|
16
|
+
setState = _useState2[1];
|
|
17
|
+
useEffect(function () {
|
|
18
|
+
var controller = new AbortController();
|
|
19
|
+
try {
|
|
20
|
+
Account.verifySubscription({
|
|
21
|
+
config: {
|
|
22
|
+
signal: controller.signal,
|
|
23
|
+
// AbortController supported in axios v1+
|
|
24
|
+
timeout: 8000 // prevents hanging forever
|
|
25
|
+
},
|
|
26
|
+
onSuccess: function onSuccess(res) {
|
|
27
|
+
setState({
|
|
28
|
+
status: res === null || res === void 0 ? void 0 : res.data.status
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
onError: function onError(err) {
|
|
32
|
+
// Request cancelled
|
|
33
|
+
if (axios.isCancel(err)) {
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// No response → server down or CORS or offline
|
|
38
|
+
if (!err.response) {
|
|
39
|
+
if (!navigator.onLine) throw 'OFFLINE';
|
|
40
|
+
throw 'SERVER_DOWN';
|
|
41
|
+
}
|
|
42
|
+
if (err.response.status === 401) throw 'UNAUTHORIZED';
|
|
43
|
+
if (err.response.status >= 500) throw 'SERVER_DOWN';
|
|
44
|
+
throw 'UNKNOWN';
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
} catch (reason) {
|
|
48
|
+
if (reason !== 'AbortError') {
|
|
49
|
+
setState({
|
|
50
|
+
status: 'error',
|
|
51
|
+
reason: reason !== null && reason !== void 0 ? reason : 'SERVER_DOWN'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
;
|
|
56
|
+
return function () {
|
|
57
|
+
return controller.abort();
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
return /*#__PURE__*/React.createElement(SubscriptionContext.Provider, {
|
|
61
|
+
value: state
|
|
62
|
+
}, children);
|
|
63
|
+
};
|
|
64
|
+
export var useSubscription = function useSubscription() {
|
|
65
|
+
return useContext(SubscriptionContext);
|
|
66
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// components/SubscriptionError.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
var SubscriptionError = function SubscriptionError(_ref) {
|
|
4
|
+
var reason = _ref.reason;
|
|
5
|
+
if (reason === 'OFFLINE') {
|
|
6
|
+
return /*#__PURE__*/React.createElement("p", null, "No internet connection. Please check your network.");
|
|
7
|
+
}
|
|
8
|
+
if (reason === 'SERVER_DOWN') {
|
|
9
|
+
return /*#__PURE__*/React.createElement("p", null, "Service temporarily unavailable. Try again later.");
|
|
10
|
+
}
|
|
11
|
+
return /*#__PURE__*/React.createElement("p", null, "Unable to verify subscription.");
|
|
12
|
+
};
|
|
13
|
+
export default SubscriptionError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// components/UpgradeNotice.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
var UpgradeNotice = function UpgradeNotice() {
|
|
4
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
5
|
+
style: {
|
|
6
|
+
padding: 24,
|
|
7
|
+
textAlign: 'center'
|
|
8
|
+
}
|
|
9
|
+
}, /*#__PURE__*/React.createElement("h2", null, "Upgrade Required"), /*#__PURE__*/React.createElement("p", null, "This feature is available for pro users."), /*#__PURE__*/React.createElement("button", {
|
|
10
|
+
onClick: function onClick() {
|
|
11
|
+
return window.location.href = 'https://ui.helpdice.com/pro';
|
|
12
|
+
}
|
|
13
|
+
}, "Upgrade Now"));
|
|
14
|
+
};
|
|
15
|
+
export default UpgradeNotice;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// hoc/withSubscription.tsx
|
|
2
|
+
|
|
3
|
+
// import React from 'react';
|
|
4
|
+
// import { useSubscription } from './SubscriptionContext';
|
|
5
|
+
// import UpgradeNotice from './UpgradeNotice';
|
|
6
|
+
|
|
7
|
+
// export const withSubscription =
|
|
8
|
+
// (Component: React.FC) =>
|
|
9
|
+
// (props: any) => {
|
|
10
|
+
// const status = useSubscription();
|
|
11
|
+
|
|
12
|
+
// if (status === 'loading') {
|
|
13
|
+
// return <div>Loading...</div>;
|
|
14
|
+
// }
|
|
15
|
+
|
|
16
|
+
// if (status !== 'active') {
|
|
17
|
+
// return <UpgradeNotice />;
|
|
18
|
+
// }
|
|
19
|
+
|
|
20
|
+
// return <Component {...props} />;
|
|
21
|
+
// };
|
|
22
|
+
|
|
23
|
+
// hoc/withSubscription.tsx
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import { useSubscription } from './SubscriptionContext';
|
|
26
|
+
import UpgradeNotice from './UpgradeNotice';
|
|
27
|
+
import SubscriptionError from './SubscriptionError';
|
|
28
|
+
export var withSubscription = function withSubscription(Component) {
|
|
29
|
+
return function (props) {
|
|
30
|
+
var sub = useSubscription();
|
|
31
|
+
if (sub.status === 'loading') {
|
|
32
|
+
return /*#__PURE__*/React.createElement("div", null, "Checking subscription...");
|
|
33
|
+
}
|
|
34
|
+
if (sub.status === 'error') {
|
|
35
|
+
return /*#__PURE__*/React.createElement(SubscriptionError, {
|
|
36
|
+
reason: sub.reason
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (sub.status !== 'active') {
|
|
40
|
+
return /*#__PURE__*/React.createElement(UpgradeNotice, null);
|
|
41
|
+
}
|
|
42
|
+
return /*#__PURE__*/React.createElement(Component, props);
|
|
43
|
+
};
|
|
44
|
+
};
|
package/esm/themes/shadows.d.ts
CHANGED
package/esm/themes/shadows.js
CHANGED
|
@@ -6,6 +6,7 @@ import { HUIContent, defaultToastLayout } from '../utils/use-hd-ui-context';
|
|
|
6
6
|
import ThemeProvider from './theme-provider';
|
|
7
7
|
import useCurrentState from '../utils/use-current-state';
|
|
8
8
|
import ToastContainer from '../use-toasts/toast-container';
|
|
9
|
+
import { SubscriptionProvider } from '../subscription';
|
|
9
10
|
var HuiProvider = function HuiProvider(_ref) {
|
|
10
11
|
var themes = _ref.themes,
|
|
11
12
|
themeType = _ref.themeType,
|
|
@@ -50,6 +51,6 @@ var HuiProvider = function HuiProvider(_ref) {
|
|
|
50
51
|
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
51
52
|
themes: themes,
|
|
52
53
|
themeType: themeType
|
|
53
|
-
}, children, /*#__PURE__*/React.createElement(ToastContainer, null)));
|
|
54
|
+
}, /*#__PURE__*/React.createElement(SubscriptionProvider, null, children), /*#__PURE__*/React.createElement(ToastContainer, null)));
|
|
54
55
|
};
|
|
55
56
|
export default HuiProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpdice/theme",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "esm/index.d.ts",
|
|
6
6
|
"unpkg": "dist/index.min.js",
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
"tslib": "^2.8.1"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
+
"@helpdice/sdk": "^0.4.3",
|
|
104
105
|
"react": "^18.3.1 || ^19.1.0"
|
|
105
106
|
},
|
|
106
107
|
"jest": {
|