mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 22:18:54 +08:00
feat(core): support lifetime subscription from external link (#7585)
close AF-1101
This commit is contained in:
@@ -28,6 +28,20 @@ export const Component = () => {
|
|||||||
const recurring = searchParams.get('recurring') as string | null;
|
const recurring = searchParams.get('recurring') as string | null;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const allowedPlan = ['ai', 'pro'];
|
||||||
|
const allowedRecurring = ['monthly', 'yearly', 'lifetime'];
|
||||||
|
const receivedPlan = plan?.toLowerCase() ?? '';
|
||||||
|
const receivedRecurring = recurring?.toLowerCase() ?? '';
|
||||||
|
|
||||||
|
const invalids = [];
|
||||||
|
if (!allowedPlan.includes(receivedPlan)) invalids.push('plan');
|
||||||
|
if (!allowedRecurring.includes(receivedRecurring))
|
||||||
|
invalids.push('recurring');
|
||||||
|
if (invalids.length) {
|
||||||
|
setError(`Invalid ${invalids.join(', ')}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const call = effect(
|
const call = effect(
|
||||||
switchMap(() => {
|
switchMap(() => {
|
||||||
return fromPromise(async signal => {
|
return fromPromise(async signal => {
|
||||||
@@ -49,9 +63,11 @@ export const Component = () => {
|
|||||||
setMessage('Checking subscription status...');
|
setMessage('Checking subscription status...');
|
||||||
await subscriptionService.subscription.waitForRevalidation(signal);
|
await subscriptionService.subscription.waitForRevalidation(signal);
|
||||||
const subscribed =
|
const subscribed =
|
||||||
plan?.toLowerCase() === 'ai'
|
receivedPlan === 'ai'
|
||||||
? !!subscriptionService.subscription.ai$.value
|
? !!subscriptionService.subscription.ai$.value
|
||||||
: !!subscriptionService.subscription.pro$.value;
|
: receivedRecurring === 'lifetime'
|
||||||
|
? !!subscriptionService.subscription.isBeliever$.value
|
||||||
|
: !!subscriptionService.subscription.pro$.value;
|
||||||
if (!subscribed) {
|
if (!subscribed) {
|
||||||
setMessage('Creating checkout...');
|
setMessage('Creating checkout...');
|
||||||
mixpanel.track('PlanUpgradeStarted', {
|
mixpanel.track('PlanUpgradeStarted', {
|
||||||
@@ -63,13 +79,15 @@ export const Component = () => {
|
|||||||
// should never reach
|
// should never reach
|
||||||
if (!account) throw new Error('No account');
|
if (!account) throw new Error('No account');
|
||||||
const targetPlan =
|
const targetPlan =
|
||||||
plan?.toLowerCase() === 'ai'
|
receivedPlan === 'ai'
|
||||||
? SubscriptionPlan.AI
|
? SubscriptionPlan.AI
|
||||||
: SubscriptionPlan.Pro;
|
: SubscriptionPlan.Pro;
|
||||||
const targetRecurring =
|
const targetRecurring =
|
||||||
recurring?.toLowerCase() === 'monthly'
|
receivedRecurring === 'monthly'
|
||||||
? SubscriptionRecurring.Monthly
|
? SubscriptionRecurring.Monthly
|
||||||
: SubscriptionRecurring.Yearly;
|
: receivedRecurring === 'yearly'
|
||||||
|
? SubscriptionRecurring.Yearly
|
||||||
|
: SubscriptionRecurring.Lifetime;
|
||||||
const checkout = await subscriptionService.createCheckoutSession({
|
const checkout = await subscriptionService.createCheckoutSession({
|
||||||
idempotencyKey,
|
idempotencyKey,
|
||||||
plan: targetPlan,
|
plan: targetPlan,
|
||||||
|
|||||||
Reference in New Issue
Block a user