Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

add(PlanSelector):with-auth-signup-flow

Aswin Asok046ee08c88af
diff --git a/web/apps/photos/src/components/PlanSelector.tsx b/web/apps/photos/src/components/PlanSelector.tsx
index 22247c7487..cd7393150d 100644
--- a/web/apps/photos/src/components/PlanSelector.tsx
+++ b/web/apps/photos/src/components/PlanSelector.tsx
@@ -88,20 +88,23 @@ export const PlanSelector: React.FC<PlanSelectorProps> = ({
backdrop: { sx: { backdropFilter: "blur(30px) opacity(95%)" } },
}}
>
- <PlanSelectorCard {...{ onClose, setLoading, onManageFamily }} />
+ <PlanSelectorContents
+ {...{ onClose, setLoading, onManageFamily }}
+ />
</Dialog>
);
};
-type PlanSelectorCardProps = Pick<
+export type PlanSelectorContentsProps = Pick<
PlanSelectorProps,
"onClose" | "setLoading" | "onManageFamily"
->;
+> & { onBeginCheckout?: () => void };
-const PlanSelectorCard: React.FC<PlanSelectorCardProps> = ({
+export const PlanSelectorContents: React.FC<PlanSelectorContentsProps> = ({
onClose,
setLoading,
onManageFamily,
+ onBeginCheckout,
}) => {
const { showMiniDialog } = useBaseContext();
@@ -161,6 +164,7 @@ const PlanSelectorCard: React.FC<PlanSelectorCardProps> = ({
switch (planSelectionOutcome(subscription)) {
case "buyPlan":
try {
+ onBeginCheckout?.();
setLoading(true);
await redirectToPaymentsApp(plan.stripeID!, "buy");
} catch (e) {
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index bfc8133935..4162a7069b 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -62,7 +62,7 @@ import { IconButton, Link, Stack, Typography } from "@mui/material";
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
import {
getAndClearIsFirstLogin,
- getAndClearJustSignedUp,
+ savedJustSignedUp,
} from "ente-accounts/services/accounts-db";
import { stashRedirect } from "ente-accounts/services/redirect";
import { isSessionInvalid } from "ente-accounts/services/session";
@@ -492,6 +492,11 @@ const Page: React.FC = () => {
return;
}
+ if (savedJustSignedUp()) {
+ void router.replace("/plan");
+ return;
+ }
+
if (!(await validateKey())) {
logout();
return;
@@ -505,10 +510,6 @@ const Page: React.FC = () => {
setIsFirstLoad(getAndClearIsFirstLogin());
- if (getAndClearJustSignedUp()) {
- showPlanSelector();
- }
-
const user = ensureLocalUser();
const masterKey = await masterKeyFromSession();
if (masterKey) {
diff --git a/web/apps/photos/src/pages/generate.tsx b/web/apps/photos/src/pages/generate.tsx
index 90b8f29cfc..c3560bea85 100644
--- a/web/apps/photos/src/pages/generate.tsx
+++ b/web/apps/photos/src/pages/generate.tsx
@@ -4,6 +4,7 @@ import type { RecoveryKeyPresentationProps } from "ente-accounts/components/Reco
import { RecoveryKeyForm } from "ente-accounts/components/auth/RecoveryKeyForm";
import { SetPasswordForm } from "ente-accounts/components/auth/SetPasswordForm";
import AccountsGeneratePage from "ente-accounts/pages/generate";
+import { useRouter } from "next/router";
import type React from "react";
function RecoveryKeyPresentation(
@@ -27,10 +28,17 @@ function SetPasswordPresentation(
}
function GeneratePage(): React.JSX.Element {
+ const router = useRouter();
+
+ function handleRecoveryKeyClose() {
+ void router.push("/plan");
+ }
+
return (
<AccountsGeneratePage
passwordPresentation={SetPasswordPresentation}
recoveryKeyPresentation={RecoveryKeyPresentation}
+ onRecoveryKeyClose={handleRecoveryKeyClose}
/>
);
}
diff --git a/web/apps/photos/src/pages/plan.tsx b/web/apps/photos/src/pages/plan.tsx
new file mode 100644
index 0000000000..9374a70706
--- /dev/null
+++ b/web/apps/photos/src/pages/plan.tsx
@@ -0,0 +1,59 @@
+import { PhotosAuthShell } from "@/components/PhotosAuthShell";
+import { PlanSelectorContents } from "@/components/PlanSelector";
+import {
+ getAndClearJustSignedUp,
+ savedJustSignedUp,
+} from "ente-accounts/services/accounts-db";
+import {
+ LoadingIndicator,
+ TranslucentLoadingOverlay,
+} from "ente-base/components/loaders";
+import { haveMasterKeyInSession } from "ente-base/session";
+import { savedAuthToken } from "ente-base/token";
+import { useRouter } from "next/router";
+import { useEffect, useState, type JSX } from "react";
+
+function PlanPage(): JSX.Element {
+ const router = useRouter();
+ const [isReady, setIsReady] = useState(false);
+ const [isLoading, setIsLoading] = useState(false);
+
+ useEffect(() => {
+ void (async () => {
+ if (!haveMasterKeyInSession() || !(await savedAuthToken())) {
+ await router.replace("/");
+ } else if (!savedJustSignedUp()) {
+ await router.replace("/gallery");
+ } else {
+ setIsReady(true);
+ }
+ })();
+ }, [router]);
+
+ function handleContinue() {
+ getAndClearJustSignedUp();
+ void router.push("/gallery");
+ }
+
+ function handleBeginCheckout() {
+ getAndClearJustSignedUp();
+ }
+
+ if (!isReady) return <LoadingIndicator />;
+
+ return (
+ <>
+ <PhotosAuthShell contentWidth={420}>
+ <PlanSelectorContents
+ onClose={handleContinue}
+ setLoading={setIsLoading}
+ onManageFamily={handleContinue}
+ onBeginCheckout={handleBeginCheckout}
+ />
+ </PhotosAuthShell>
+ {isLoading && <TranslucentLoadingOverlay />}
+ </>
+ );
+}
+
+export default PlanPage;
diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsx
index 3a89e8e793..b70f2bed07 100644
--- a/web/packages/accounts/pages/generate.tsx
+++ b/web/packages/accounts/pages/generate.tsx
@@ -47,11 +47,13 @@ import {
export interface GeneratePageProps {
passwordPresentation?: ComponentType<NewPasswordPresentationProps>;
recoveryKeyPresentation?: ComponentType<RecoveryKeyPresentationProps>;
+ onRecoveryKeyClose?: () => void;
}
const Page: React.FC<GeneratePageProps> = ({
passwordPresentation,
recoveryKeyPresentation,
+ onRecoveryKeyClose,
}) => {
const { logout, showMiniDialog } = useBaseContext();
@@ -106,7 +108,11 @@ const Page: React.FC<GeneratePageProps> = ({
);
function handleRecoveryKeyClose() {
- void router.push(appHomeRoute);
+ if (onRecoveryKeyClose) {
+ onRecoveryKeyClose();
+ } else {
+ void router.push(appHomeRoute);
+ }
}
if (openRecoveryKey && recoveryKeyPresentation) {
diff --git a/web/packages/new/photos/services/user-details.ts b/web/packages/new/photos/services/user-details.ts
index 895cf68e4f..44c313724d 100644
--- a/web/packages/new/photos/services/user-details.ts
+++ b/web/packages/new/photos/services/user-details.ts
@@ -217,7 +217,8 @@ export const cancelStripeSubscription = async () => {
return pullUserDetails();
};
-const paymentsAppOrigin = "https://payments.ente.com";
+const paymentsAppOrigin =
+ process.env.NEXT_PUBLIC_PAYMENTS_APP_ORIGIN ?? "https://payments.ente.com";
export const redirectToPaymentsApp = async (
productID: string,