fix(core): fix upgrade popup (#11227)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { notify } from '@affine/component';
|
||||||
import { SettingRow } from '@affine/component/setting-components';
|
import { SettingRow } from '@affine/component/setting-components';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -7,6 +8,7 @@ import {
|
|||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||||
import { SubscriptionService } from '@affine/core/modules/cloud';
|
import { SubscriptionService } from '@affine/core/modules/cloud';
|
||||||
import { UrlService } from '@affine/core/modules/url';
|
import { UrlService } from '@affine/core/modules/url';
|
||||||
|
import { UserFriendlyError } from '@affine/error';
|
||||||
import { createCustomerPortalMutation } from '@affine/graphql';
|
import { createCustomerPortalMutation } from '@affine/graphql';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { ArrowRightSmallIcon } from '@blocksuite/icons/rc';
|
import { ArrowRightSmallIcon } from '@blocksuite/icons/rc';
|
||||||
@@ -92,8 +94,11 @@ export const PaymentMethodUpdater = ({
|
|||||||
const update = useAsyncCallback(async () => {
|
const update = useAsyncCallback(async () => {
|
||||||
await trigger(null, {
|
await trigger(null, {
|
||||||
onSuccess: data => {
|
onSuccess: data => {
|
||||||
urlService.openPopupWindow(data.createCustomerPortal);
|
urlService.openExternal(data.createCustomerPortal);
|
||||||
},
|
},
|
||||||
|
}).catch(e => {
|
||||||
|
const userFriendlyError = UserFriendlyError.fromAny(e);
|
||||||
|
notify.error(userFriendlyError);
|
||||||
});
|
});
|
||||||
}, [trigger, urlService]);
|
}, [trigger, urlService]);
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export const CheckoutSlot = ({
|
|||||||
idempotencyKey,
|
idempotencyKey,
|
||||||
...checkoutOptions,
|
...checkoutOptions,
|
||||||
});
|
});
|
||||||
urlService.openPopupWindow(session);
|
urlService.openExternal(session);
|
||||||
setOpenedExternalWindow(true);
|
setOpenedExternalWindow(true);
|
||||||
setIdempotencyKey(nanoid());
|
setIdempotencyKey(nanoid());
|
||||||
onCheckoutSuccess?.();
|
onCheckoutSuccess?.();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { Button } from '@affine/component';
|
import { Button, notify } from '@affine/component';
|
||||||
import { SettingRow } from '@affine/component/setting-components';
|
import { SettingRow } from '@affine/component/setting-components';
|
||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||||
import { useMutation } from '@affine/core/components/hooks/use-mutation';
|
import { useMutation } from '@affine/core/components/hooks/use-mutation';
|
||||||
import { UrlService } from '@affine/core/modules/url';
|
import { UrlService } from '@affine/core/modules/url';
|
||||||
|
import { UserFriendlyError } from '@affine/error';
|
||||||
import { createCustomerPortalMutation } from '@affine/graphql';
|
import { createCustomerPortalMutation } from '@affine/graphql';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { useService } from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
@@ -19,8 +20,11 @@ export const PaymentMethodUpdater = () => {
|
|||||||
const update = useAsyncCallback(async () => {
|
const update = useAsyncCallback(async () => {
|
||||||
await trigger(null, {
|
await trigger(null, {
|
||||||
onSuccess: data => {
|
onSuccess: data => {
|
||||||
urlService.openPopupWindow(data.createCustomerPortal);
|
urlService.openExternal(data.createCustomerPortal);
|
||||||
},
|
},
|
||||||
|
}).catch(e => {
|
||||||
|
const userFriendlyError = UserFriendlyError.fromAny(e);
|
||||||
|
notify.error(userFriendlyError);
|
||||||
});
|
});
|
||||||
}, [trigger, urlService]);
|
}, [trigger, urlService]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Button } from '@affine/component';
|
import { Button, notify } from '@affine/component';
|
||||||
import {
|
import {
|
||||||
SettingHeader,
|
SettingHeader,
|
||||||
SettingRow,
|
SettingRow,
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
import { WorkspacePermissionService } from '@affine/core/modules/permissions';
|
import { WorkspacePermissionService } from '@affine/core/modules/permissions';
|
||||||
import { UrlService } from '@affine/core/modules/url';
|
import { UrlService } from '@affine/core/modules/url';
|
||||||
import { WorkspaceService } from '@affine/core/modules/workspace';
|
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||||
|
import { UserFriendlyError } from '@affine/error';
|
||||||
import {
|
import {
|
||||||
createSelfhostCustomerPortalMutation,
|
createSelfhostCustomerPortalMutation,
|
||||||
SubscriptionPlan,
|
SubscriptionPlan,
|
||||||
@@ -111,12 +112,13 @@ const PaymentMethodUpdater = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: data => {
|
onSuccess: data => {
|
||||||
urlService.openPopupWindow(
|
urlService.openExternal(data.createSelfhostWorkspaceCustomerPortal);
|
||||||
data.createSelfhostWorkspaceCustomerPortal
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
).catch(e => {
|
||||||
|
const userFriendlyError = UserFriendlyError.fromAny(e);
|
||||||
|
notify.error(userFriendlyError);
|
||||||
|
});
|
||||||
}, [trigger, urlService, workspace.id]);
|
}, [trigger, urlService, workspace.id]);
|
||||||
|
|
||||||
if (!isTeam) {
|
if (!isTeam) {
|
||||||
|
|||||||
@@ -16,15 +16,14 @@ export const Component = () => {
|
|||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
|
|
||||||
const { jumpToOpenInApp } = useNavigateHelper();
|
const { jumpToIndex, jumpToOpenInApp } = useNavigateHelper();
|
||||||
const openAFFiNE = useCallback(() => {
|
const openAFFiNE = useCallback(() => {
|
||||||
if (params.get('client')) {
|
if (params.get('client')) {
|
||||||
return jumpToOpenInApp('bring-to-front');
|
return jumpToOpenInApp('bring-to-front');
|
||||||
} else {
|
} else {
|
||||||
// close popup window
|
jumpToIndex();
|
||||||
return window.close();
|
|
||||||
}
|
}
|
||||||
}, [jumpToOpenInApp, params]);
|
}, [jumpToIndex, jumpToOpenInApp, params]);
|
||||||
|
|
||||||
const subtitle = (
|
const subtitle = (
|
||||||
<div className={styles.leftContentText}>
|
<div className={styles.leftContentText}>
|
||||||
|
|||||||
@@ -157,8 +157,7 @@ export const Component = () => {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
setMessage('Redirecting...');
|
setMessage('Redirecting...');
|
||||||
urlService.openPopupWindow(checkout);
|
urlService.openExternal(checkout);
|
||||||
jumpToIndex();
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const e = UserFriendlyError.fromAny(err);
|
const e = UserFriendlyError.fromAny(err);
|
||||||
setMessage(e.message);
|
setMessage(e.message);
|
||||||
|
|||||||
@@ -15,16 +15,15 @@ import * as styles from './styles.css';
|
|||||||
export const Component = () => {
|
export const Component = () => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
|
const { jumpToIndex, jumpToOpenInApp } = useNavigateHelper();
|
||||||
|
|
||||||
const { jumpToOpenInApp } = useNavigateHelper();
|
|
||||||
const openAFFiNE = useCallback(() => {
|
const openAFFiNE = useCallback(() => {
|
||||||
if (params.get('client')) {
|
if (params.get('client')) {
|
||||||
return jumpToOpenInApp('bring-to-front');
|
return jumpToOpenInApp('bring-to-front');
|
||||||
} else {
|
} else {
|
||||||
// close popup window
|
jumpToIndex();
|
||||||
return window.close();
|
|
||||||
}
|
}
|
||||||
}, [jumpToOpenInApp, params]);
|
}, [jumpToIndex, jumpToOpenInApp, params]);
|
||||||
|
|
||||||
const subtitle = (
|
const subtitle = (
|
||||||
<div className={styles.leftContentText}>
|
<div className={styles.leftContentText}>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Button } from '@affine/component';
|
import { Button } from '@affine/component';
|
||||||
import { AuthPageContainer } from '@affine/component/auth-components';
|
import { AuthPageContainer } from '@affine/component/auth-components';
|
||||||
|
import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-helper';
|
||||||
import { Trans, useI18n } from '@affine/i18n';
|
import { Trans, useI18n } from '@affine/i18n';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
@@ -12,11 +13,11 @@ import * as styles from './styles.css';
|
|||||||
*/
|
*/
|
||||||
export const Component = () => {
|
export const Component = () => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
const { jumpToIndex } = useNavigateHelper();
|
||||||
|
|
||||||
const openWorkspace = useCallback(() => {
|
const openWorkspace = useCallback(() => {
|
||||||
// close popup window
|
jumpToIndex();
|
||||||
window.close();
|
}, [jumpToIndex]);
|
||||||
}, []);
|
|
||||||
|
|
||||||
const subtitle = (
|
const subtitle = (
|
||||||
<div className={styles.leftContentText}>
|
<div className={styles.leftContentText}>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ export class UrlService extends Service {
|
|||||||
* open a popup window, provide different implementations in different environments.
|
* open a popup window, provide different implementations in different environments.
|
||||||
* e.g. in electron, use system default browser to open a popup window.
|
* e.g. in electron, use system default browser to open a popup window.
|
||||||
*
|
*
|
||||||
|
* !IMPORTANT: browser will block popup windows in async callbacks, so you should use openExternal instead.
|
||||||
|
*
|
||||||
* @param url only full url with http/https protocol is supported
|
* @param url only full url with http/https protocol is supported
|
||||||
*/
|
*/
|
||||||
openPopupWindow(url: string) {
|
openPopupWindow(url: string) {
|
||||||
@@ -28,4 +30,19 @@ export class UrlService extends Service {
|
|||||||
}
|
}
|
||||||
this.popupWindowProvider?.open(url);
|
this.popupWindowProvider?.open(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens an external URL with different implementations based on the environment.
|
||||||
|
* Unlike openPopupWindow, openExternal opens the URL in the current browser tab,
|
||||||
|
* making it more suitable for cases where popup windows might be blocked by browsers.
|
||||||
|
*
|
||||||
|
* @param url only full url with http/https protocol is supported
|
||||||
|
*/
|
||||||
|
openExternal(url: string) {
|
||||||
|
if (BUILD_CONFIG.isWeb || BUILD_CONFIG.isMobileWeb) {
|
||||||
|
location.href = url;
|
||||||
|
} else {
|
||||||
|
this.popupWindowProvider?.open(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user