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EACNe,OAAQ,KACRlD,UAAWuC,EACXY,oBAAqBC,CAAAA,EAAAA,EAAAA,EAAAA,EACnBnB,EACAE,EACAI,EAEJ,GACArD,EAAW,kBACXmC,SAASgC,IAAI,CAAGN,EACZjD,GACFwD,EAAAA,EAAQA,CAACC,MAAM,CAACC,GAAG,CAAC,CAClB,CAACpB,EAAAA,EAAgBA,CAACC,EAAE,GAAKvC,EAAO,UAAYA,EAAK,CAAEA,EACnDE,UAAWA,CACb,EAEJ,CAAE,MAAOyD,EAAK,CACZC,QAAQtE,KAAK,CAACqE,GACdpE,EAAS,0CACX,CACF,CAOF,GAAGsE,IAAI,CAACC,CAAAA,EAAAA,EAAAA,CAAAA,EAAS,IAAMC,EAAAA,CAAKA,KAMhC,OAFAjD,IAEO,KACLA,EAAKkD,WAAW,EAClB,CACF,EAAG,CACDpF,EACAC,EACAa,EACAG,EACAG,EACAL,EACAO,EACAV,EACD,EAEDW,CAAAA,EAAAA,EAAAA,SAAAA,EAAU,KACRvB,EAAYuC,OAAO,CAAC8C,UAAU,EAChC,EAAG,CAACrF,EAAY,EAGd,UAACsF,MAAAA,CAAIC,UCpJc,U,SDqJhB,EAOC,uB,UACG7E,EACD,UAAC8E,KAAAA,CAAAA,GACD,UAACC,EAAAA,EAAMA,CAAAA,CAACC,QAAQ,UAAUC,QAAS,IAAM9E,EAAY+E,GAAKA,EAAI,G,SAAI,O,MATpE,uB,UACGrF,EACD,UAACiF,KAAAA,CAAAA,GACD,UAACK,EAAAA,EAAOA,CAAAA,CAACC,KAAM,E,OAazB,C","sources":["webpack://@affine/web/../core/src/pages/subscribe.tsx","webpack://@affine/web/../core/src/pages/subscribe.css.ts"],"sourcesContent":["import { Button, Loading } from '@affine/component';\nimport { SubscriptionPlan, SubscriptionRecurring } from '@affine/graphql';\nimport { effect, fromPromise, useServices } from '@toeverything/infra';\nimport { nanoid } from 'nanoid';\nimport { useEffect, useMemo, useState } from 'react';\nimport { useSearchParams } from 'react-router-dom';\nimport { EMPTY, mergeMap, switchMap } from 'rxjs';\n\nimport { generateSubscriptionCallbackLink } from '../hooks/affine/use-subscription-notify';\nimport { RouteLogic, useNavigateHelper } from '../hooks/use-navigate-helper';\nimport { mixpanel, track } from '../mixpanel';\nimport { AuthService, SubscriptionService } from '../modules/cloud';\nimport { container } from './subscribe.css';\n\nexport const Component = () => {\n const { authService, subscriptionService } = useServices({\n AuthService,\n SubscriptionService,\n });\n const [searchParams] = useSearchParams();\n const [message, setMessage] = useState('');\n const [error, setError] = useState('');\n const [retryKey, setRetryKey] = useState(0);\n const { jumpToSignIn, jumpToIndex } = useNavigateHelper();\n const idempotencyKey = useMemo(() => nanoid(), []);\n\n const plan = searchParams.get('plan') as string | null;\n const recurring = searchParams.get('recurring') as string | null;\n\n useEffect(() => {\n const allowedPlan = ['ai', 'pro'];\n const allowedRecurring = ['monthly', 'yearly', 'lifetime'];\n const receivedPlan = plan?.toLowerCase() ?? '';\n const receivedRecurring = recurring?.toLowerCase() ?? '';\n\n const invalids = [];\n if (!allowedPlan.includes(receivedPlan)) invalids.push('plan');\n if (!allowedRecurring.includes(receivedRecurring))\n invalids.push('recurring');\n if (invalids.length) {\n setError(`Invalid ${invalids.join(', ')}`);\n return;\n }\n\n const call = effect(\n switchMap(() => {\n return fromPromise(async signal => {\n retryKey;\n // TODO(@eyhn): i18n\n setMessage('Checking account status...');\n setError('');\n await authService.session.waitForRevalidation(signal);\n const loggedIn =\n authService.session.status$.value === 'authenticated';\n if (!loggedIn) {\n setMessage('Redirecting to sign in...');\n jumpToSignIn(\n location.pathname + location.search,\n RouteLogic.REPLACE\n );\n return;\n }\n setMessage('Checking subscription status...');\n await subscriptionService.subscription.waitForRevalidation(signal);\n const subscribed =\n receivedPlan === 'ai'\n ? !!subscriptionService.subscription.ai$.value\n : receivedRecurring === 'lifetime'\n ? !!subscriptionService.subscription.isBeliever$.value\n : !!subscriptionService.subscription.pro$.value;\n if (!subscribed) {\n setMessage('Creating checkout...');\n\n try {\n const account = authService.session.account$.value;\n // should never reach\n if (!account) throw new Error('No account');\n const targetPlan =\n receivedPlan === 'ai'\n ? SubscriptionPlan.AI\n : SubscriptionPlan.Pro;\n const targetRecurring =\n receivedRecurring === 'monthly'\n ? SubscriptionRecurring.Monthly\n : receivedRecurring === 'yearly'\n ? SubscriptionRecurring.Yearly\n : SubscriptionRecurring.Lifetime;\n\n track.subscriptionLanding.$.$.checkout({\n control: 'pricing',\n plan: targetPlan,\n recurring: targetRecurring,\n });\n\n const checkout = await subscriptionService.createCheckoutSession({\n idempotencyKey,\n plan: targetPlan,\n coupon: null,\n recurring: targetRecurring,\n successCallbackLink: generateSubscriptionCallbackLink(\n account,\n targetPlan,\n targetRecurring\n ),\n });\n setMessage('Redirecting...');\n location.href = checkout;\n if (plan) {\n mixpanel.people.set({\n [SubscriptionPlan.AI === plan ? 'ai plan' : plan]: plan,\n recurring: recurring,\n });\n }\n } catch (err) {\n console.error(err);\n setError('Something went wrong. Please try again.');\n }\n } else {\n setMessage('Your account is already subscribed. Redirecting...');\n await new Promise(resolve => {\n setTimeout(resolve, 5000);\n });\n jumpToIndex(RouteLogic.REPLACE);\n }\n }).pipe(mergeMap(() => EMPTY));\n })\n );\n\n call();\n\n return () => {\n call.unsubscribe();\n };\n }, [\n authService,\n subscriptionService,\n jumpToSignIn,\n idempotencyKey,\n plan,\n jumpToIndex,\n recurring,\n retryKey,\n ]);\n\n useEffect(() => {\n authService.session.revalidate();\n }, [authService]);\n\n return (\n
\n {!error ? (\n <>\n {message}\n
\n \n \n ) : (\n <>\n {error}\n
\n \n \n )}\n
\n );\n};\n","import \"../core/src/pages/subscribe.css.ts.vanilla.css!=!../../../../../node_modules/@vanilla-extract/webpack-plugin/virtualFileLoader/dist/vanilla-extract-webpack-plugin-virtualFileLoader.cjs.js?{\\\"fileName\\\":\\\"../core/src/pages/subscribe.css.ts.vanilla.css\\\",\\\"source\\\":\\\"LnJka3BibjAgewogIGRpc3BsYXk6IGZsZXg7CiAgZmxleC1kaXJlY3Rpb246IGNvbHVtbjsKICBhbGlnbi1pdGVtczogY2VudGVyOwogIGp1c3RpZnktY29udGVudDogY2VudGVyOwogIGhlaWdodDogMTAwdmg7CiAgd2lkdGg6IDEwMCU7CiAgbGluZS1oZWlnaHQ6IDQ7CiAgY29sb3I6IHZhcigtLWFmZmluZS10ZXh0LXNlY29uZGFyeS1jb2xvcik7Cn0=\\\"}!../../../../../node_modules/@vanilla-extract/webpack-plugin/extracted.js\"\nexport var container = 'rdkpbn0';"],"names":["Component","authService","subscriptionService","useServices","AuthService","SubscriptionService","searchParams","useSearchParams","message","setMessage","useState","error","setError","retryKey","setRetryKey","jumpToSignIn","jumpToIndex","useNavigateHelper","idempotencyKey","useMemo","nanoid","plan","get","recurring","useEffect","receivedPlan","toLowerCase","receivedRecurring","invalids","allowedPlan","includes","push","allowedRecurring","length","join","call","effect","switchMap","fromPromise","signal","session","waitForRevalidation","status$","value","location","pathname","search","RouteLogic","REPLACE","subscription","ai$","isBeliever$","pro$","Promise","resolve","setTimeout","account","account$","targetPlan","SubscriptionPlan","AI","Pro","targetRecurring","SubscriptionRecurring","Monthly","Yearly","Lifetime","track","subscriptionLanding","$","checkout","control","createCheckoutSession","coupon","successCallbackLink","generateSubscriptionCallbackLink","href","mixpanel","people","set","err","console","pipe","mergeMap","EMPTY","unsubscribe","revalidate","div","className","br","Button","variant","onClick","i","Loading","size"],"sourceRoot":""}