mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-23 09:17:06 +08:00
feat(core): open desktop directly in subscription landing page (#6661)
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { Button, type ButtonProps } from '@affine/component';
|
import { Button, type ButtonProps } from '@affine/component';
|
||||||
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
||||||
import { SubscriptionService } from '@affine/core/modules/cloud';
|
import { SubscriptionService } from '@affine/core/modules/cloud';
|
||||||
import { getAffineCloudBaseUrl } from '@affine/core/modules/cloud/services/fetch';
|
|
||||||
import { popupWindow } from '@affine/core/utils';
|
import { popupWindow } from '@affine/core/utils';
|
||||||
import { SubscriptionPlan, SubscriptionRecurring } from '@affine/graphql';
|
import { SubscriptionPlan, SubscriptionRecurring } from '@affine/graphql';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
@@ -43,7 +42,7 @@ export const AISubscribe = ({ ...btnProps }: AISubscribeProps) => {
|
|||||||
idempotencyKey,
|
idempotencyKey,
|
||||||
plan: SubscriptionPlan.AI,
|
plan: SubscriptionPlan.AI,
|
||||||
coupon: null,
|
coupon: null,
|
||||||
successCallbackLink: getAffineCloudBaseUrl() + '/ai-upgrade-success',
|
successCallbackLink: null,
|
||||||
});
|
});
|
||||||
popupWindow(session);
|
popupWindow(session);
|
||||||
setOpenedExternalWindow(true);
|
setOpenedExternalWindow(true);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
|
|||||||
import { Trans } from '@affine/i18n';
|
import { Trans } from '@affine/i18n';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { type ReactNode, useCallback } from 'react';
|
import { type ReactNode, useCallback } from 'react';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
import * as styles from './styles.css';
|
import * as styles from './styles.css';
|
||||||
|
|
||||||
@@ -15,11 +16,16 @@ const UpgradeSuccessLayout = ({
|
|||||||
description?: ReactNode;
|
description?: ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const [params] = useSearchParams();
|
||||||
|
|
||||||
const { jumpToIndex } = useNavigateHelper();
|
const { jumpToIndex, openInApp } = useNavigateHelper();
|
||||||
const openAffine = useCallback(() => {
|
const openAffine = useCallback(() => {
|
||||||
jumpToIndex();
|
if (params.get('schema')) {
|
||||||
}, [jumpToIndex]);
|
openInApp(params.get('schema') ?? 'affine', 'bring-to-front');
|
||||||
|
} else {
|
||||||
|
jumpToIndex();
|
||||||
|
}
|
||||||
|
}, [jumpToIndex, openInApp, params]);
|
||||||
|
|
||||||
const subtitle = (
|
const subtitle = (
|
||||||
<div className={styles.leftContentText}>
|
<div className={styles.leftContentText}>
|
||||||
|
|||||||
@@ -155,6 +155,14 @@ export function useNavigateHelper() {
|
|||||||
[navigate]
|
[navigate]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const openInApp = useCallback(
|
||||||
|
(schema: string, path: string) => {
|
||||||
|
const encodedUrl = encodeURIComponent(`${schema}://${path}`);
|
||||||
|
return navigate(`/open-app/url?schema=${schema}&url=${encodedUrl}`);
|
||||||
|
},
|
||||||
|
[navigate]
|
||||||
|
);
|
||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
jumpToPage,
|
jumpToPage,
|
||||||
@@ -169,6 +177,7 @@ export function useNavigateHelper() {
|
|||||||
jumpToCollections,
|
jumpToCollections,
|
||||||
jumpToTags,
|
jumpToTags,
|
||||||
jumpToTag,
|
jumpToTag,
|
||||||
|
openInApp,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
jumpToPage,
|
jumpToPage,
|
||||||
@@ -183,6 +192,7 @@ export function useNavigateHelper() {
|
|||||||
jumpToCollections,
|
jumpToCollections,
|
||||||
jumpToTags,
|
jumpToTags,
|
||||||
jumpToTag,
|
jumpToTag,
|
||||||
|
openInApp,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type {
|
import type {
|
||||||
CreateCheckoutSessionInput,
|
CreateCheckoutSessionInput,
|
||||||
SubscriptionPlan,
|
|
||||||
SubscriptionRecurring,
|
SubscriptionRecurring,
|
||||||
} from '@affine/graphql';
|
} from '@affine/graphql';
|
||||||
import {
|
import {
|
||||||
@@ -8,6 +7,7 @@ import {
|
|||||||
createCheckoutSessionMutation,
|
createCheckoutSessionMutation,
|
||||||
pricesQuery,
|
pricesQuery,
|
||||||
resumeSubscriptionMutation,
|
resumeSubscriptionMutation,
|
||||||
|
SubscriptionPlan,
|
||||||
subscriptionQuery,
|
subscriptionQuery,
|
||||||
updateSubscriptionMutation,
|
updateSubscriptionMutation,
|
||||||
} from '@affine/graphql';
|
} from '@affine/graphql';
|
||||||
@@ -15,10 +15,24 @@ import type { GlobalCacheService } from '@toeverything/infra';
|
|||||||
import { Store } from '@toeverything/infra';
|
import { Store } from '@toeverything/infra';
|
||||||
|
|
||||||
import type { SubscriptionType } from '../entities/subscription';
|
import type { SubscriptionType } from '../entities/subscription';
|
||||||
|
import { getAffineCloudBaseUrl } from '../services/fetch';
|
||||||
import type { GraphQLService } from '../services/graphql';
|
import type { GraphQLService } from '../services/graphql';
|
||||||
|
|
||||||
const SUBSCRIPTION_CACHE_KEY = 'subscription:';
|
const SUBSCRIPTION_CACHE_KEY = 'subscription:';
|
||||||
|
|
||||||
|
const getDefaultSubscriptionSuccessCallbackLink = (
|
||||||
|
plan: SubscriptionPlan | null
|
||||||
|
) => {
|
||||||
|
const path =
|
||||||
|
plan === SubscriptionPlan.AI ? '/ai-upgrade-success' : '/upgrade-success';
|
||||||
|
const urlString = getAffineCloudBaseUrl() + path;
|
||||||
|
const url = new URL(urlString);
|
||||||
|
if (environment.isDesktop) {
|
||||||
|
url.searchParams.set('schema', window.appInfo.schema);
|
||||||
|
}
|
||||||
|
return url.toString();
|
||||||
|
};
|
||||||
|
|
||||||
export class SubscriptionStore extends Store {
|
export class SubscriptionStore extends Store {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly gqlService: GraphQLService,
|
private readonly gqlService: GraphQLService,
|
||||||
@@ -112,7 +126,14 @@ export class SubscriptionStore extends Store {
|
|||||||
async createCheckoutSession(input: CreateCheckoutSessionInput) {
|
async createCheckoutSession(input: CreateCheckoutSessionInput) {
|
||||||
const data = await this.gqlService.gql({
|
const data = await this.gqlService.gql({
|
||||||
query: createCheckoutSessionMutation,
|
query: createCheckoutSessionMutation,
|
||||||
variables: { input },
|
variables: {
|
||||||
|
input: {
|
||||||
|
...input,
|
||||||
|
successCallbackLink:
|
||||||
|
input.successCallbackLink ||
|
||||||
|
getDefaultSubscriptionSuccessCallbackLink(input.plan),
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return data.createCheckoutSession;
|
return data.createCheckoutSession;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import { RouterProvider } from 'react-router-dom';
|
|||||||
const desktopWhiteList = [
|
const desktopWhiteList = [
|
||||||
'/desktop-signin',
|
'/desktop-signin',
|
||||||
'/open-app/signin-redirect',
|
'/open-app/signin-redirect',
|
||||||
|
'/open-app/url',
|
||||||
'/upgrade-success',
|
'/upgrade-success',
|
||||||
'/ai-upgrade-success',
|
'/ai-upgrade-success',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ async function handleAffineUrl(url: string) {
|
|||||||
if (urlObj.hostname === 'signin-redirect') {
|
if (urlObj.hostname === 'signin-redirect') {
|
||||||
await handleOauthJwt(url);
|
await handleOauthJwt(url);
|
||||||
}
|
}
|
||||||
|
if (urlObj.hostname === 'bring-to-front') {
|
||||||
|
const mainWindow = await getMainWindow();
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleOauthJwt(url: string) {
|
async function handleOauthJwt(url: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user