fix(core): close popup window when upgrade success (#11199)
This commit is contained in:
@@ -23,6 +23,8 @@ export const Component = () => {
|
|||||||
} else {
|
} else {
|
||||||
jumpToIndex();
|
jumpToIndex();
|
||||||
}
|
}
|
||||||
|
// close popup window
|
||||||
|
window.close();
|
||||||
}, [jumpToIndex, jumpToOpenInApp, params]);
|
}, [jumpToIndex, jumpToOpenInApp, params]);
|
||||||
|
|
||||||
const subtitle = (
|
const subtitle = (
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
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 { getSubscriptionInfo } from '@affine/core/components/hooks/affine/use-subscription-notify';
|
|
||||||
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';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
|
||||||
|
|
||||||
import * as styles from './styles.css';
|
import * as styles from './styles.css';
|
||||||
|
|
||||||
@@ -15,27 +12,11 @@ import * as styles from './styles.css';
|
|||||||
*/
|
*/
|
||||||
export const Component = () => {
|
export const Component = () => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const [params] = useSearchParams();
|
|
||||||
const subscriptionInfo = getSubscriptionInfo(params);
|
|
||||||
|
|
||||||
const { jumpToPage, jumpToOpenInApp, jumpToIndex } = useNavigateHelper();
|
|
||||||
const openWorkspace = useCallback(() => {
|
const openWorkspace = useCallback(() => {
|
||||||
if (params.get('schema')) {
|
// close popup window
|
||||||
jumpToOpenInApp('bring-to-front');
|
window.close();
|
||||||
} else {
|
}, []);
|
||||||
if (subscriptionInfo.workspaceId) {
|
|
||||||
jumpToPage(subscriptionInfo.workspaceId, 'all');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
jumpToIndex();
|
|
||||||
}
|
|
||||||
}, [
|
|
||||||
jumpToIndex,
|
|
||||||
jumpToOpenInApp,
|
|
||||||
jumpToPage,
|
|
||||||
params,
|
|
||||||
subscriptionInfo.workspaceId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const subtitle = (
|
const subtitle = (
|
||||||
<div className={styles.leftContentText}>
|
<div className={styles.leftContentText}>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import { AuthPageContainer } from '@affine/component/auth-components';
|
import { AuthPageContainer } from '@affine/component/auth-components';
|
||||||
import { useSignOut } from '@affine/core/components/hooks/affine/use-sign-out';
|
import { useSignOut } from '@affine/core/components/hooks/affine/use-sign-out';
|
||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||||
|
import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-helper';
|
||||||
import { useWorkspaceInfo } from '@affine/core/components/hooks/use-workspace-info';
|
import { useWorkspaceInfo } from '@affine/core/components/hooks/use-workspace-info';
|
||||||
import { PureWorkspaceCard } from '@affine/core/components/workspace-selector/workspace-card';
|
import { PureWorkspaceCard } from '@affine/core/components/workspace-selector/workspace-card';
|
||||||
import { AuthService } from '@affine/core/modules/cloud';
|
import { AuthService } from '@affine/core/modules/cloud';
|
||||||
@@ -27,7 +28,7 @@ import { SubscriptionPlan, SubscriptionRecurring } from '@affine/graphql';
|
|||||||
import { type I18nString, Trans, useI18n } from '@affine/i18n';
|
import { type I18nString, Trans, useI18n } from '@affine/i18n';
|
||||||
import { DoneIcon, NewPageIcon, SignOutIcon } from '@blocksuite/icons/rc';
|
import { DoneIcon, NewPageIcon, SignOutIcon } from '@blocksuite/icons/rc';
|
||||||
import { useLiveData, useService } from '@toeverything/infra';
|
import { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { Upgrade } from '../../dialogs/setting/general-setting/plans/plan-card';
|
import { Upgrade } from '../../dialogs/setting/general-setting/plans/plan-card';
|
||||||
@@ -142,8 +143,7 @@ export const UpgradeToTeam = ({ recurring }: { recurring: string | null }) => {
|
|||||||
recurring={recurring}
|
recurring={recurring}
|
||||||
open={openUpgrade}
|
open={openUpgrade}
|
||||||
onOpenChange={setOpenUpgrade}
|
onOpenChange={setOpenUpgrade}
|
||||||
workspaceName={name}
|
selectedWorkspace={selectedWorkspace}
|
||||||
workspaceId={selectedWorkspace?.id ?? ''}
|
|
||||||
/>
|
/>
|
||||||
<CreateWorkspaceDialog
|
<CreateWorkspaceDialog
|
||||||
open={openCreate}
|
open={openCreate}
|
||||||
@@ -172,21 +172,52 @@ export const UpgradeToTeam = ({ recurring }: { recurring: string | null }) => {
|
|||||||
const UpgradeDialog = ({
|
const UpgradeDialog = ({
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
workspaceName,
|
selectedWorkspace,
|
||||||
workspaceId,
|
|
||||||
recurring,
|
recurring,
|
||||||
}: {
|
}: {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
workspaceName: string;
|
selectedWorkspace: WorkspaceMetadata | null;
|
||||||
workspaceId: string;
|
|
||||||
recurring: string | null;
|
recurring: string | null;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
const workspacesService = useService(WorkspacesService);
|
||||||
|
const { jumpToPage } = useNavigateHelper();
|
||||||
|
|
||||||
|
const profile = selectedWorkspace
|
||||||
|
? workspacesService.getProfile(selectedWorkspace)
|
||||||
|
: undefined;
|
||||||
|
const workspaceInfo = useLiveData(profile?.profile$);
|
||||||
|
const isTeam = workspaceInfo?.isTeam;
|
||||||
|
const workspaceName = workspaceInfo?.name;
|
||||||
|
const workspaceId = selectedWorkspace?.id;
|
||||||
|
|
||||||
const onClose = useCallback(() => {
|
const onClose = useCallback(() => {
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
}, [onOpenChange]);
|
}, [onOpenChange]);
|
||||||
|
|
||||||
|
const revalidate = useCallback(() => {
|
||||||
|
profile?.revalidate();
|
||||||
|
}, [profile]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
revalidate();
|
||||||
|
}, [selectedWorkspace, revalidate]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('focus', revalidate);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('focus', revalidate);
|
||||||
|
};
|
||||||
|
}, [revalidate]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isTeam && selectedWorkspace) {
|
||||||
|
onClose();
|
||||||
|
return jumpToPage(selectedWorkspace.id, 'all');
|
||||||
|
}
|
||||||
|
}, [isTeam, jumpToPage, onClose, selectedWorkspace]);
|
||||||
|
|
||||||
const currentRecurring =
|
const currentRecurring =
|
||||||
recurring &&
|
recurring &&
|
||||||
recurring.toLowerCase() === SubscriptionRecurring.Yearly.toLowerCase()
|
recurring.toLowerCase() === SubscriptionRecurring.Yearly.toLowerCase()
|
||||||
|
|||||||
Reference in New Issue
Block a user