diff --git a/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx b/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx index 5042ea992..c0e901a7b 100644 --- a/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx +++ b/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx @@ -1,23 +1,63 @@ import { FunctionalComponent } from "preact"; import { Text } from '@/preferences/components'; import { Button } from '@/components/Button'; +import { WebApplication } from "@/ui_models/application"; +import { useState } from "preact/hooks"; +import { isDesktopApplication } from "@/utils"; -export const NoSubscription: FunctionalComponent = () => ( - <> - You don't have a Standard Notes subscription yet. -
-
- -); +export const NoSubscription: FunctionalComponent<{ + application: WebApplication; +}> = ({ application }) => { + const [isLoadingPurchaseFlow, setIsLoadingPurchaseFlow] = useState(false); + const [purchaseFlowError, setPurchaseFlowError] = useState(undefined); + + const onPurchaseClick = async () => { + const errorMessage = 'There was an error when attempting to redirect you to the subscription page.'; + setIsLoadingPurchaseFlow(true); + try { + const url = await application.getPurchaseFlowUrl(); + if (url) { + const currentUrl = window.location.href; + const successUrl = isDesktopApplication() ? `standardnotes://${currentUrl}` : currentUrl; + console.log(successUrl); + window.location.assign(`${url}&success_url=${successUrl}`); + } else { + setPurchaseFlowError(errorMessage); + } + } catch (e) { + setPurchaseFlowError(errorMessage); + } finally { + setIsLoadingPurchaseFlow(false); + } + }; + + return ( + <> + You don't have a Standard Notes subscription yet. + {isLoadingPurchaseFlow && ( + + Redirecting you to the subscription page... + + )} + {purchaseFlowError && ( + + {purchaseFlowError} + + )} +
+
+ + ); +}; diff --git a/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx b/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx index a063d1a06..0e9ce9126 100644 --- a/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx +++ b/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx @@ -77,7 +77,7 @@ export const Subscription: FunctionComponent = observer(({ ) : userSubscription && userSubscription.endsAt > now ? ( ) : ( - + )}