@blocklet/launcher-workflow 2.3.8 → 2.3.9

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.
@@ -30,7 +30,8 @@ export default function ConfirmDialog({
30
30
  params: initialParams,
31
31
  onCancel,
32
32
  onConfirm,
33
- locale
33
+ locale,
34
+ disableCancel
34
35
  }) {
35
36
  const {
36
37
  locale: innerLocale
@@ -58,7 +59,7 @@ export default function ConfirmDialog({
58
59
  style: {
59
60
  padding: '8px 24px 24px'
60
61
  },
61
- children: [/*#__PURE__*/_jsx(Button, {
62
+ children: [!disableCancel && /*#__PURE__*/_jsx(Button, {
62
63
  onClick: () => onCallback(onCancel),
63
64
  children: cancel || get(translations, `${innerLocale}.cancel`)
64
65
  }), /*#__PURE__*/_jsx(Button, {
@@ -82,7 +83,8 @@ ConfirmDialog.propTypes = {
82
83
  // This object holds states managed in the dialog
83
84
  onCancel: PropTypes.func,
84
85
  onConfirm: PropTypes.func.isRequired,
85
- locale: PropTypes.oneOf(['en', 'zh'])
86
+ locale: PropTypes.oneOf(['en', 'zh']),
87
+ disableCancel: PropTypes.bool
86
88
  };
87
89
  ConfirmDialog.defaultProps = {
88
90
  onCancel: () => {},
@@ -90,5 +92,6 @@ ConfirmDialog.defaultProps = {
90
92
  confirm: '',
91
93
  color: 'error',
92
94
  params: {},
93
- locale: 'en'
95
+ locale: 'en',
96
+ disableCancel: false
94
97
  };
package/es/locales/en.js CHANGED
@@ -29,7 +29,8 @@ export default {
29
29
  space: 'Space',
30
30
  subscription: 'Subscription',
31
31
  price: 'Pricing',
32
- unitPrice: 'Unit'
32
+ unitPrice: 'Unit',
33
+ visit: 'Visit'
33
34
  },
34
35
  license: {
35
36
  title: 'End User License Agreement',
@@ -134,6 +135,15 @@ export default {
134
135
  },
135
136
  paid: {
136
137
  redirecting: 'Payment success, redirecting...'
138
+ },
139
+ unexpectedLaunchSession: {
140
+ purchaseNewSpace: 'Purchase New Space',
141
+ paid: 'Current order has been paid',
142
+ paidDescription: 'The current order has been paid, you can choose to purchase a new space or continue the launch process.',
143
+ installed: 'Order has been installed',
144
+ installedDescription: 'The current order has been successfully installed, you can choose to purchase a new space or jump to the current application.',
145
+ expired: 'Order has been expired',
146
+ expiredDescription: 'The current order has expired, you can choose to purchase a new space.'
137
147
  }
138
148
  },
139
149
  checkout: {
package/es/locales/zh.js CHANGED
@@ -29,7 +29,8 @@ export default {
29
29
  space: '空间',
30
30
  subscription: '订阅',
31
31
  payWith: '用{currency}支付',
32
- unitPrice: '单价'
32
+ unitPrice: '单价',
33
+ visit: '访问'
33
34
  },
34
35
  license: {
35
36
  title: '空间用户协议',
@@ -133,6 +134,15 @@ export default {
133
134
  },
134
135
  paid: {
135
136
  redirecting: '支付成功,正在跳转...'
137
+ },
138
+ unexpectedLaunchSession: {
139
+ purchaseNewSpace: '购买新空间',
140
+ paid: '订单已支付',
141
+ paidDescription: '检测当前订单已经支付,您可以选择购买新的空间,或者继续启动流程',
142
+ installed: '订单已安装',
143
+ installedDescription: '检测当前订单已经安装成功,您可以选择购买新的空间,或者跳转到当前应用。',
144
+ expired: '订单已过期',
145
+ expiredDescription: '检测当前订单已经过期,您可以选择购买新的空间。'
136
146
  }
137
147
  },
138
148
  checkout: {
package/es/prepare.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import Center from '@arcblock/ux/lib/Center';
2
- import { getBlockletLogoUrl, getBlockletMetaUrlFromQuery, getDefaultTrialEnd } from '@blocklet/launcher-util/es/util';
2
+ import { LAUNCH_STATUS } from '@blocklet/launcher-util/es/constant';
3
+ import { getBlockletAdminURL, getBlockletLogoUrl, getBlockletMetaUrlFromQuery, getDefaultTrialEnd } from '@blocklet/launcher-util/es/util';
3
4
  import CheckoutOnDemand from '@blocklet/launcher-ux/lib/payment/checkout/on-demand';
4
5
  import { CheckoutTable, PaymentProvider } from '@blocklet/payment-react';
5
6
  import styled from '@emotion/styled';
@@ -9,11 +10,12 @@ import Stack from '@mui/material/Stack';
9
10
  import ToggleButton from '@mui/material/ToggleButton';
10
11
  import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
11
12
  import PropTypes from 'prop-types';
12
- import { useEffect } from 'react';
13
+ import { useCallback, useEffect } from 'react';
13
14
  import { Link, useNavigate, useSearchParams } from 'react-router-dom';
14
15
  import useAsync from 'react-use/lib/useAsync';
15
16
  import useSetState from 'react-use/lib/useSetState';
16
17
  import joinURL from 'url-join';
18
+ import ConfirmDialog from './components/confirm';
17
19
  import Body from './components/layout/body';
18
20
  import Header from './components/layout/header';
19
21
  import { useLocaleContext } from './contexts/locale';
@@ -72,7 +74,7 @@ function Content({
72
74
  });
73
75
  }
74
76
  }, [defaultProductType, params, setParams, setState]);
75
- const getLaunchState = useAsync(async () => {
77
+ const launchState = useAsync(async () => {
76
78
  const createPromiseFn = (fn, ...args) => new Promise((resolve, reject) => {
77
79
  fn(...args, (err, value) => {
78
80
  if (err) {
@@ -89,8 +91,14 @@ function Content({
89
91
  const launch = await createPromiseFn(launchSession.create, launchSessionAPI, routerPrefix, blockletMetaUrl);
90
92
  return launch;
91
93
  });
94
+ const getPurchaseNewLink = useCallback(() => {
95
+ window.location = launchState?.value?.app?.appURL;
96
+ const urlObj = new URL(window.location.href);
97
+ urlObj.searchParams.delete('sessionId');
98
+ return urlObj.href;
99
+ }, [launchState?.value?.app?.appURL]);
92
100
  useEffect(() => {
93
- const tmpLaunch = getLaunchState.value;
101
+ const tmpLaunch = launchState.value;
94
102
  if (!tmpLaunch) {
95
103
  return;
96
104
  }
@@ -100,14 +108,14 @@ function Content({
100
108
  replace: true
101
109
  });
102
110
  }
103
- }, [getLaunchState.value, params, setParams]);
104
- if (getLaunchState.loading || blocklet.loading) {
111
+ }, [launchState.value, params, setParams]);
112
+ if (launchState.loading || blocklet.loading) {
105
113
  return /*#__PURE__*/_jsx(Center, {
106
114
  relative: "parent",
107
115
  children: /*#__PURE__*/_jsx(CircularProgress, {})
108
116
  });
109
117
  }
110
- if (getLaunchState.error) {
118
+ if (launchState.error) {
111
119
  return t('common.serviceError');
112
120
  }
113
121
  const handlePaid = () => {
@@ -128,7 +136,47 @@ function Content({
128
136
 
129
137
  // TODO: PaymentKitV2 处理支付失败的情况
130
138
 
131
- const launch = getLaunchState.value;
139
+ const launch = launchState.value;
140
+ if ([LAUNCH_STATUS.paid, LAUNCH_STATUS.nftMinted, LAUNCH_STATUS.allocated].includes(launch.status)) {
141
+ return /*#__PURE__*/_jsx(ConfirmDialog, {
142
+ title: t('purchase.unexpectedLaunchSession.paid'),
143
+ description: t('purchase.unexpectedLaunchSession.paidDescription'),
144
+ color: "primary",
145
+ cancel: t('purchase.unexpectedLaunchSession.purchaseNewSpace'),
146
+ confirm: t('common.continue'),
147
+ onCancel: () => {
148
+ window.location = getPurchaseNewLink();
149
+ },
150
+ onConfirm: handlePaid
151
+ });
152
+ }
153
+ if (launch.status === LAUNCH_STATUS.installed) {
154
+ return /*#__PURE__*/_jsx(ConfirmDialog, {
155
+ title: t('purchase.unexpectedLaunchSession.installed'),
156
+ description: t('purchase.unexpectedLaunchSession.installedDescription'),
157
+ color: "primary",
158
+ cancel: t('purchase.unexpectedLaunchSession.purchaseNewSpace'),
159
+ confirm: t('common.visit'),
160
+ onCancel: () => {
161
+ window.location = getPurchaseNewLink();
162
+ },
163
+ onConfirm: () => {
164
+ window.location = getBlockletAdminURL(launch?.app?.appURL);
165
+ }
166
+ });
167
+ }
168
+ if ([LAUNCH_STATUS.expired, LAUNCH_STATUS.terminated, LAUNCH_STATUS.timeout].includes(launch.status)) {
169
+ return /*#__PURE__*/_jsx(ConfirmDialog, {
170
+ title: t('purchase.unexpectedLaunchSession.expired'),
171
+ description: t('purchase.unexpectedLaunchSession.expiredDescription'),
172
+ color: "primary",
173
+ confirm: t('purchase.unexpectedLaunchSession.purchaseNewSpace'),
174
+ disableCancel: true,
175
+ onConfirm: () => {
176
+ window.location = getPurchaseNewLink();
177
+ }
178
+ });
179
+ }
132
180
  return /*#__PURE__*/_jsx(Root, {
133
181
  children: /*#__PURE__*/_jsxs(Stack, {
134
182
  direction: "column",
@@ -38,7 +38,8 @@ function ConfirmDialog(_ref) {
38
38
  params: initialParams,
39
39
  onCancel,
40
40
  onConfirm,
41
- locale
41
+ locale,
42
+ disableCancel
42
43
  } = _ref;
43
44
  const {
44
45
  locale: innerLocale
@@ -66,7 +67,7 @@ function ConfirmDialog(_ref) {
66
67
  style: {
67
68
  padding: '8px 24px 24px'
68
69
  },
69
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
70
+ children: [!disableCancel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
70
71
  onClick: () => onCallback(onCancel),
71
72
  children: cancel || (0, _lodash.default)(translations, "".concat(innerLocale, ".cancel"))
72
73
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
@@ -90,7 +91,8 @@ ConfirmDialog.propTypes = {
90
91
  // This object holds states managed in the dialog
91
92
  onCancel: _propTypes.default.func,
92
93
  onConfirm: _propTypes.default.func.isRequired,
93
- locale: _propTypes.default.oneOf(['en', 'zh'])
94
+ locale: _propTypes.default.oneOf(['en', 'zh']),
95
+ disableCancel: _propTypes.default.bool
94
96
  };
95
97
  ConfirmDialog.defaultProps = {
96
98
  onCancel: () => {},
@@ -98,5 +100,6 @@ ConfirmDialog.defaultProps = {
98
100
  confirm: '',
99
101
  color: 'error',
100
102
  params: {},
101
- locale: 'en'
103
+ locale: 'en',
104
+ disableCancel: false
102
105
  };
package/lib/locales/en.js CHANGED
@@ -35,7 +35,8 @@ var _default = exports.default = {
35
35
  space: 'Space',
36
36
  subscription: 'Subscription',
37
37
  price: 'Pricing',
38
- unitPrice: 'Unit'
38
+ unitPrice: 'Unit',
39
+ visit: 'Visit'
39
40
  },
40
41
  license: {
41
42
  title: 'End User License Agreement',
@@ -140,6 +141,15 @@ var _default = exports.default = {
140
141
  },
141
142
  paid: {
142
143
  redirecting: 'Payment success, redirecting...'
144
+ },
145
+ unexpectedLaunchSession: {
146
+ purchaseNewSpace: 'Purchase New Space',
147
+ paid: 'Current order has been paid',
148
+ paidDescription: 'The current order has been paid, you can choose to purchase a new space or continue the launch process.',
149
+ installed: 'Order has been installed',
150
+ installedDescription: 'The current order has been successfully installed, you can choose to purchase a new space or jump to the current application.',
151
+ expired: 'Order has been expired',
152
+ expiredDescription: 'The current order has expired, you can choose to purchase a new space.'
143
153
  }
144
154
  },
145
155
  checkout: {
package/lib/locales/zh.js CHANGED
@@ -35,7 +35,8 @@ var _default = exports.default = {
35
35
  space: '空间',
36
36
  subscription: '订阅',
37
37
  payWith: '用{currency}支付',
38
- unitPrice: '单价'
38
+ unitPrice: '单价',
39
+ visit: '访问'
39
40
  },
40
41
  license: {
41
42
  title: '空间用户协议',
@@ -139,6 +140,15 @@ var _default = exports.default = {
139
140
  },
140
141
  paid: {
141
142
  redirecting: '支付成功,正在跳转...'
143
+ },
144
+ unexpectedLaunchSession: {
145
+ purchaseNewSpace: '购买新空间',
146
+ paid: '订单已支付',
147
+ paidDescription: '检测当前订单已经支付,您可以选择购买新的空间,或者继续启动流程',
148
+ installed: '订单已安装',
149
+ installedDescription: '检测当前订单已经安装成功,您可以选择购买新的空间,或者跳转到当前应用。',
150
+ expired: '订单已过期',
151
+ expiredDescription: '检测当前订单已经过期,您可以选择购买新的空间。'
142
152
  }
143
153
  },
144
154
  checkout: {
package/lib/prepare.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _Center = _interopRequireDefault(require("@arcblock/ux/lib/Center"));
8
+ var _constant = require("@blocklet/launcher-util/es/constant");
8
9
  var _util = require("@blocklet/launcher-util/es/util");
9
10
  var _onDemand = _interopRequireDefault(require("@blocklet/launcher-ux/lib/payment/checkout/on-demand"));
10
11
  var _paymentReact = require("@blocklet/payment-react");
@@ -20,6 +21,7 @@ var _reactRouterDom = require("react-router-dom");
20
21
  var _useAsync = _interopRequireDefault(require("react-use/lib/useAsync"));
21
22
  var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
22
23
  var _urlJoin = _interopRequireDefault(require("url-join"));
24
+ var _confirm = _interopRequireDefault(require("./components/confirm"));
23
25
  var _body = _interopRequireDefault(require("./components/layout/body"));
24
26
  var _header = _interopRequireDefault(require("./components/layout/header"));
25
27
  var _locale = require("./contexts/locale");
@@ -33,7 +35,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
35
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
34
36
  const Root = (0, _styled.default)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 100%;\n height: 100%;\n padding-top: 0;\n\n @media (max-width: 960px) {\n width: 100%;\n }\n"])));
35
37
  function Content(_ref) {
36
- var _window$blocklet, _ref2, _window$blocklet2, _window$blocklet3, _window$blocklet4;
38
+ var _window$blocklet, _launchState$value2, _ref2, _window$blocklet2, _window$blocklet3, _window$blocklet4;
37
39
  let {
38
40
  blocklet
39
41
  } = _ref;
@@ -75,7 +77,7 @@ function Content(_ref) {
75
77
  });
76
78
  }
77
79
  }, [defaultProductType, params, setParams, setState]);
78
- const getLaunchState = (0, _useAsync.default)(async () => {
80
+ const launchState = (0, _useAsync.default)(async () => {
79
81
  const createPromiseFn = function createPromiseFn(fn) {
80
82
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
81
83
  args[_key - 1] = arguments[_key];
@@ -97,8 +99,15 @@ function Content(_ref) {
97
99
  const launch = await createPromiseFn(_util2.launchSession.create, launchSessionAPI, routerPrefix, blockletMetaUrl);
98
100
  return launch;
99
101
  });
102
+ const getPurchaseNewLink = (0, _react.useCallback)(() => {
103
+ var _launchState$value;
104
+ window.location = launchState === null || launchState === void 0 || (_launchState$value = launchState.value) === null || _launchState$value === void 0 || (_launchState$value = _launchState$value.app) === null || _launchState$value === void 0 ? void 0 : _launchState$value.appURL;
105
+ const urlObj = new URL(window.location.href);
106
+ urlObj.searchParams.delete('sessionId');
107
+ return urlObj.href;
108
+ }, [launchState === null || launchState === void 0 || (_launchState$value2 = launchState.value) === null || _launchState$value2 === void 0 || (_launchState$value2 = _launchState$value2.app) === null || _launchState$value2 === void 0 ? void 0 : _launchState$value2.appURL]);
100
109
  (0, _react.useEffect)(() => {
101
- const tmpLaunch = getLaunchState.value;
110
+ const tmpLaunch = launchState.value;
102
111
  if (!tmpLaunch) {
103
112
  return;
104
113
  }
@@ -108,14 +117,14 @@ function Content(_ref) {
108
117
  replace: true
109
118
  });
110
119
  }
111
- }, [getLaunchState.value, params, setParams]);
112
- if (getLaunchState.loading || blocklet.loading) {
120
+ }, [launchState.value, params, setParams]);
121
+ if (launchState.loading || blocklet.loading) {
113
122
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
114
123
  relative: "parent",
115
124
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {})
116
125
  });
117
126
  }
118
- if (getLaunchState.error) {
127
+ if (launchState.error) {
119
128
  return t('common.serviceError');
120
129
  }
121
130
  const handlePaid = () => {
@@ -136,7 +145,48 @@ function Content(_ref) {
136
145
 
137
146
  // TODO: PaymentKitV2 处理支付失败的情况
138
147
 
139
- const launch = getLaunchState.value;
148
+ const launch = launchState.value;
149
+ if ([_constant.LAUNCH_STATUS.paid, _constant.LAUNCH_STATUS.nftMinted, _constant.LAUNCH_STATUS.allocated].includes(launch.status)) {
150
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_confirm.default, {
151
+ title: t('purchase.unexpectedLaunchSession.paid'),
152
+ description: t('purchase.unexpectedLaunchSession.paidDescription'),
153
+ color: "primary",
154
+ cancel: t('purchase.unexpectedLaunchSession.purchaseNewSpace'),
155
+ confirm: t('common.continue'),
156
+ onCancel: () => {
157
+ window.location = getPurchaseNewLink();
158
+ },
159
+ onConfirm: handlePaid
160
+ });
161
+ }
162
+ if (launch.status === _constant.LAUNCH_STATUS.installed) {
163
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_confirm.default, {
164
+ title: t('purchase.unexpectedLaunchSession.installed'),
165
+ description: t('purchase.unexpectedLaunchSession.installedDescription'),
166
+ color: "primary",
167
+ cancel: t('purchase.unexpectedLaunchSession.purchaseNewSpace'),
168
+ confirm: t('common.visit'),
169
+ onCancel: () => {
170
+ window.location = getPurchaseNewLink();
171
+ },
172
+ onConfirm: () => {
173
+ var _launch$app;
174
+ window.location = (0, _util.getBlockletAdminURL)(launch === null || launch === void 0 || (_launch$app = launch.app) === null || _launch$app === void 0 ? void 0 : _launch$app.appURL);
175
+ }
176
+ });
177
+ }
178
+ if ([_constant.LAUNCH_STATUS.expired, _constant.LAUNCH_STATUS.terminated, _constant.LAUNCH_STATUS.timeout].includes(launch.status)) {
179
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_confirm.default, {
180
+ title: t('purchase.unexpectedLaunchSession.expired'),
181
+ description: t('purchase.unexpectedLaunchSession.expiredDescription'),
182
+ color: "primary",
183
+ confirm: t('purchase.unexpectedLaunchSession.purchaseNewSpace'),
184
+ disableCancel: true,
185
+ onConfirm: () => {
186
+ window.location = getPurchaseNewLink();
187
+ }
188
+ });
189
+ }
140
190
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Root, {
141
191
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Stack.default, {
142
192
  direction: "column",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-workflow",
3
- "version": "2.3.8",
3
+ "version": "2.3.9",
4
4
  "description": "Purchase components for Launcher UI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -46,9 +46,9 @@
46
46
  "@arcblock/license": "^2.9.64",
47
47
  "@arcblock/react-hooks": "^2.9.64",
48
48
  "@arcblock/ux": "^2.9.64",
49
- "@blocklet/launcher-layout": "2.3.8",
50
- "@blocklet/launcher-util": "2.3.8",
51
- "@blocklet/launcher-ux": "2.3.8",
49
+ "@blocklet/launcher-layout": "2.3.9",
50
+ "@blocklet/launcher-util": "2.3.9",
51
+ "@blocklet/launcher-ux": "2.3.9",
52
52
  "@blocklet/payment": "^1.13.210",
53
53
  "@blocklet/payment-react": "^1.13.210",
54
54
  "@emotion/react": "^11.11.4",
@@ -106,5 +106,5 @@
106
106
  "require": "./lib/locales/index.js"
107
107
  }
108
108
  },
109
- "gitHead": "2035c69d9a53daa1e1777886f04470a0edf72af0"
109
+ "gitHead": "a9859828087d0e65bafe0b9fa2947b33f0cba7da"
110
110
  }