From 6d289d73db79c985faeb0da17decfa2d1a156c77 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 15:48:49 +0530 Subject: [PATCH 01/28] Add a new type --- web/packages/shared/apps/constants.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/packages/shared/apps/constants.ts b/web/packages/shared/apps/constants.ts index b679fb912..e62e34eb2 100644 --- a/web/packages/shared/apps/constants.ts +++ b/web/packages/shared/apps/constants.ts @@ -1,5 +1,11 @@ import { ACCOUNTS_PAGES, AUTH_PAGES, PHOTOS_PAGES } from "../constants/pages"; +/** + * Arbitrary names that we used as keys for indexing various constants for each + * of our apps. + */ +export type AppName = "account" | "albums" | "auth" | "photos"; + export enum APPS { PHOTOS = "PHOTOS", AUTH = "AUTH", From b2fda16561da67af48d50eda28009d17cae508f6 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 15:55:41 +0530 Subject: [PATCH 02/28] Home route --- web/packages/shared/apps/constants.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/web/packages/shared/apps/constants.ts b/web/packages/shared/apps/constants.ts index e62e34eb2..3fcf0dcdd 100644 --- a/web/packages/shared/apps/constants.ts +++ b/web/packages/shared/apps/constants.ts @@ -1,11 +1,23 @@ import { ACCOUNTS_PAGES, AUTH_PAGES, PHOTOS_PAGES } from "../constants/pages"; /** - * Arbitrary names that we used as keys for indexing various constants for each - * of our apps. + * Arbitrary names that we used as keys for indexing various constants + * corresponding to our apps. */ export type AppName = "account" | "albums" | "auth" | "photos"; +/** + * The "home" route for each of our apps. + * + * This is where we redirect to, e.g, after successful authentication. + */ +export const appHomeRoute: Record = { + account: ACCOUNTS_PAGES.PASSKEYS, + albums: "/", + auth: AUTH_PAGES.AUTH, + photos: PHOTOS_PAGES.GALLERY, +}; + export enum APPS { PHOTOS = "PHOTOS", AUTH = "AUTH", From babe378301b7f3b384caeff783753196340ca1b3 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 16:03:16 +0530 Subject: [PATCH 03/28] Move --- web/packages/accounts/services/redirect.ts | 24 ++++++++++++++++++++++ web/packages/next/types/app.ts | 5 +++++ web/packages/shared/apps/constants.ts | 18 ---------------- 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 web/packages/accounts/services/redirect.ts create mode 100644 web/packages/next/types/app.ts diff --git a/web/packages/accounts/services/redirect.ts b/web/packages/accounts/services/redirect.ts new file mode 100644 index 000000000..084d001ec --- /dev/null +++ b/web/packages/accounts/services/redirect.ts @@ -0,0 +1,24 @@ +import type { AppName } from "@/next/types/app"; +import { + ACCOUNTS_PAGES, + AUTH_PAGES, + PHOTOS_PAGES, +} from "@ente/shared/constants/pages"; + +/** + * The "home" route for each of our apps. + * + * This is where we redirect to after successful authentication. + */ +export const appHomeRoute = (appName: AppName): string => { + switch (appName) { + case "account": + return ACCOUNTS_PAGES.PASSKEYS; + case "albums": + return "/"; + case "auth": + return AUTH_PAGES.AUTH; + case "photos": + return PHOTOS_PAGES.GALLERY; + } +}; diff --git a/web/packages/next/types/app.ts b/web/packages/next/types/app.ts new file mode 100644 index 000000000..8818a09e5 --- /dev/null +++ b/web/packages/next/types/app.ts @@ -0,0 +1,5 @@ +/** + * Arbitrary names that we used as keys for indexing various constants + * corresponding to our apps. + */ +export type AppName = "account" | "albums" | "auth" | "photos"; diff --git a/web/packages/shared/apps/constants.ts b/web/packages/shared/apps/constants.ts index 3fcf0dcdd..b679fb912 100644 --- a/web/packages/shared/apps/constants.ts +++ b/web/packages/shared/apps/constants.ts @@ -1,23 +1,5 @@ import { ACCOUNTS_PAGES, AUTH_PAGES, PHOTOS_PAGES } from "../constants/pages"; -/** - * Arbitrary names that we used as keys for indexing various constants - * corresponding to our apps. - */ -export type AppName = "account" | "albums" | "auth" | "photos"; - -/** - * The "home" route for each of our apps. - * - * This is where we redirect to, e.g, after successful authentication. - */ -export const appHomeRoute: Record = { - account: ACCOUNTS_PAGES.PASSKEYS, - albums: "/", - auth: AUTH_PAGES.AUTH, - photos: PHOTOS_PAGES.GALLERY, -}; - export enum APPS { PHOTOS = "PHOTOS", AUTH = "AUTH", From 5bbe768acb80f84c6266991e78b21f29b97e28db Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 16:06:29 +0530 Subject: [PATCH 04/28] Scaffold --- web/packages/shared/apps/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/packages/shared/apps/types.ts b/web/packages/shared/apps/types.ts index 6c6e4fe1a..b2ac97649 100644 --- a/web/packages/shared/apps/types.ts +++ b/web/packages/shared/apps/types.ts @@ -1,6 +1,7 @@ import { TwoFactorType } from "@ente/accounts/constants/twofactor"; import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types"; import { APPS } from "./constants"; +import type { AppName } from "@/next/types/app"; export interface PageProps { appContext: { @@ -10,5 +11,6 @@ export interface PageProps { logout: () => void; }; appName: APPS; + appName2?: AppName; twoFactorType?: TwoFactorType; } From 6bf6f781475e2385f54a43cb87440ae6c9558c56 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 17:53:49 +0530 Subject: [PATCH 05/28] Refactor app context types --- web/apps/accounts/src/pages/_app.tsx | 31 +++++++------ web/apps/auth/src/pages/_app.tsx | 42 +++++++++-------- web/apps/photos/src/pages/_app.tsx | 69 +++++++++++++++------------- web/packages/next/types/app.ts | 19 +++++++- web/packages/shared/apps/types.ts | 2 - 5 files changed, 94 insertions(+), 69 deletions(-) diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsx index c743000ac..8cf45b741 100644 --- a/web/apps/accounts/src/pages/_app.tsx +++ b/web/apps/accounts/src/pages/_app.tsx @@ -1,6 +1,7 @@ import { CustomHead } from "@/next/components/Head"; import { setupI18n } from "@/next/i18n"; import { logUnhandledErrorsAndRejections } from "@/next/log-web"; +import type { AppName, BaseAppContextT } from "@/next/types/app"; import { PAGES } from "@ente/accounts/constants/pages"; import { accountLogout } from "@ente/accounts/services/logout"; import { APPS, APP_TITLES } from "@ente/shared/apps/constants"; @@ -22,16 +23,15 @@ import { useRouter } from "next/router"; import { createContext, useEffect, useState } from "react"; import "styles/global.css"; -interface AppContextProps { - isMobile: boolean; - showNavBar: (show: boolean) => void; - setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void; - logout: () => void; -} +/** The accounts app has no extra properties on top of the base context. */ +type AppContextT = BaseAppContextT; -export const AppContext = createContext({} as AppContextProps); +/** The React {@link Context} available to all pages. */ +export const AppContext = createContext(undefined); export default function App({ Component, pageProps }: AppProps) { + const appName: AppName = "account"; + const [isI18nReady, setIsI18nReady] = useState(false); const [showNavbar, setShowNavBar] = useState(false); @@ -83,6 +83,14 @@ export default function App({ Component, pageProps }: AppProps) { void accountLogout().then(() => router.push(PAGES.ROOT)); }; + const appContext = { + appName, + logout, + showNavBar, + isMobile, + setDialogBoxAttributesV2, + }; + // TODO: This string doesn't actually exist const title = isI18nReady ? t("title", { context: "accounts" }) @@ -101,14 +109,7 @@ export default function App({ Component, pageProps }: AppProps) { attributes={dialogBoxAttributeV2 as any} /> - + {!isI18nReady && ( ({ diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx index af7289791..6aa1246d3 100644 --- a/web/apps/auth/src/pages/_app.tsx +++ b/web/apps/auth/src/pages/_app.tsx @@ -4,6 +4,7 @@ import { logStartupBanner, logUnhandledErrorsAndRejections, } from "@/next/log-web"; +import type { AppName, BaseAppContextT } from "@/next/types/app"; import { accountLogout } from "@ente/accounts/services/logout"; import { APPS, @@ -32,21 +33,23 @@ import { createContext, useEffect, useRef, useState } from "react"; import LoadingBar, { type LoadingBarRef } from "react-top-loading-bar"; import "../../public/css/global.css"; -type AppContextType = { - showNavBar: (show: boolean) => void; +/** + * Properties available via the {@link AppContext} to the Auth app's React tree. + */ +type AppContextT = BaseAppContextT & { startLoading: () => void; finishLoading: () => void; - isMobile: boolean; themeColor: THEME_COLOR; setThemeColor: (themeColor: THEME_COLOR) => void; somethingWentWrong: () => void; - setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void; - logout: () => void; }; -export const AppContext = createContext(undefined); +/** The React {@link Context} available to all pages. */ +export const AppContext = createContext(undefined); export default function App({ Component, pageProps }: AppProps) { + const appName: AppName = "auth"; + const router = useRouter(); const [isI18nReady, setIsI18nReady] = useState(false); const [loading, setLoading] = useState(false); @@ -131,6 +134,19 @@ export default function App({ Component, pageProps }: AppProps) { void accountLogout().then(() => router.push(PAGES.ROOT)); }; + const appContext = { + appName, + logout, + showNavBar, + isMobile, + setDialogBoxAttributesV2, + startLoading, + finishLoading, + themeColor, + setThemeColor, + somethingWentWrong, + }; + // TODO: Refactor this to have a fallback const title = isI18nReady ? t("title", { context: "auth" }) @@ -156,19 +172,7 @@ export default function App({ Component, pageProps }: AppProps) { attributes={dialogBoxAttributeV2} /> - + {(loading || !isI18nReady) && ( ({ diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx index b8f151339..521a6fc3e 100644 --- a/web/apps/photos/src/pages/_app.tsx +++ b/web/apps/photos/src/pages/_app.tsx @@ -5,6 +5,7 @@ import { logStartupBanner, logUnhandledErrorsAndRejections, } from "@/next/log-web"; +import type { AppName, BaseAppContextT } from "@/next/types/app"; import { AppUpdate } from "@/next/types/ipc"; import { APPS, @@ -74,8 +75,11 @@ const redirectMap = new Map([ [REDIRECTS.FAMILIES, getFamilyPortalRedirectURL], ]); -type AppContextType = { - showNavBar: (show: boolean) => void; +/** + * Properties available via the {@link AppContext} to the Photos app's React + * tree. + */ +type AppContextT = BaseAppContextT & { mlSearchEnabled: boolean; mapEnabled: boolean; updateMlSearchEnabled: (enabled: boolean) => Promise; @@ -89,19 +93,19 @@ type AppContextType = { setWatchFolderView: (isOpen: boolean) => void; watchFolderFiles: FileList; setWatchFolderFiles: (files: FileList) => void; - isMobile: boolean; themeColor: THEME_COLOR; setThemeColor: (themeColor: THEME_COLOR) => void; somethingWentWrong: () => void; - setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void; isCFProxyDisabled: boolean; setIsCFProxyDisabled: (disabled: boolean) => void; - logout: () => void; }; -export const AppContext = createContext(null); +/** The React {@link Context} available to all pages. */ +export const AppContext = createContext(undefined); export default function App({ Component, pageProps }: AppProps) { + const appName: AppName = "photos"; + const router = useRouter(); const [isI18nReady, setIsI18nReady] = useState(false); const [loading, setLoading] = useState(false); @@ -324,6 +328,32 @@ export default function App({ Component, pageProps }: AppProps) { void photosLogout().then(() => router.push(PAGES.ROOT)); }; + const appContext = { + appName, + showNavBar, + mlSearchEnabled, + updateMlSearchEnabled, + startLoading, + finishLoading, + closeMessageDialog, + setDialogMessage, + watchFolderView, + setWatchFolderView, + watchFolderFiles, + setWatchFolderFiles, + isMobile, + setNotificationAttributes, + themeColor, + setThemeColor, + somethingWentWrong, + setDialogBoxAttributesV2, + mapEnabled, + updateMapEnabled, + isCFProxyDisabled, + setIsCFProxyDisabled, + logout, + }; + const title = isI18nReady ? t("title", { context: "photos" }) : APP_TITLES.get(APPS.PHOTOS); @@ -359,32 +389,7 @@ export default function App({ Component, pageProps }: AppProps) { attributes={notificationAttributes} /> - + {(loading || !isI18nReady) && ( ({ diff --git a/web/packages/next/types/app.ts b/web/packages/next/types/app.ts index 8818a09e5..5175cb26c 100644 --- a/web/packages/next/types/app.ts +++ b/web/packages/next/types/app.ts @@ -1,5 +1,22 @@ +import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types"; + /** * Arbitrary names that we used as keys for indexing various constants - * corresponding to our apps. + * corresponding to our apps that rely on this package. */ export type AppName = "account" | "albums" | "auth" | "photos"; + +/** + * Properties guaranteed to be present in the AppContext types for apps that are + * listed in {@link AppName}. + */ +export interface BaseAppContextT { + /** The unique key for the app. */ + appName: AppName; + /** Perform the (possibly app specific) logout sequence. */ + logout: () => void; + /** Show or hide the app's navigation bar. */ + showNavBar: (show: boolean) => void; + isMobile: boolean; + setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void; +} diff --git a/web/packages/shared/apps/types.ts b/web/packages/shared/apps/types.ts index b2ac97649..6c6e4fe1a 100644 --- a/web/packages/shared/apps/types.ts +++ b/web/packages/shared/apps/types.ts @@ -1,7 +1,6 @@ import { TwoFactorType } from "@ente/accounts/constants/twofactor"; import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types"; import { APPS } from "./constants"; -import type { AppName } from "@/next/types/app"; export interface PageProps { appContext: { @@ -11,6 +10,5 @@ export interface PageProps { logout: () => void; }; appName: APPS; - appName2?: AppName; twoFactorType?: TwoFactorType; } From 4f31bd625d763f0d683f63db1a49b5b43a74f2ed Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:05:04 +0530 Subject: [PATCH 06/28] Context --- web/packages/shared/apps/types.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/web/packages/shared/apps/types.ts b/web/packages/shared/apps/types.ts index 6c6e4fe1a..cde24788d 100644 --- a/web/packages/shared/apps/types.ts +++ b/web/packages/shared/apps/types.ts @@ -1,14 +1,9 @@ +import type { BaseAppContextT } from "@/next/types/app"; import { TwoFactorType } from "@ente/accounts/constants/twofactor"; -import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types"; import { APPS } from "./constants"; export interface PageProps { - appContext: { - showNavBar: (show: boolean) => void; - isMobile: boolean; - setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void; - logout: () => void; - }; + appContext: BaseAppContextT; appName: APPS; twoFactorType?: TwoFactorType; } From 452872156ae1a3b5e53dc66eb820c8c984ee98ff Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:10:22 +0530 Subject: [PATCH 07/28] login --- web/packages/accounts/components/Login.tsx | 72 ------------------ web/packages/accounts/pages/login.tsx | 85 ++++++++++++++++++++-- web/packages/shared/apps/constants.ts | 14 ++++ 3 files changed, 94 insertions(+), 77 deletions(-) diff --git a/web/packages/accounts/components/Login.tsx b/web/packages/accounts/components/Login.tsx index 676b62db1..e69de29bb 100644 --- a/web/packages/accounts/components/Login.tsx +++ b/web/packages/accounts/components/Login.tsx @@ -1,72 +0,0 @@ -import log from "@/next/log"; -import { APPS } from "@ente/shared/apps/constants"; -import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; -import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; -import LinkButton from "@ente/shared/components/LinkButton"; -import SingleInputForm, { - type SingleInputFormProps, -} from "@ente/shared/components/SingleInputForm"; -import { LS_KEYS, setData } from "@ente/shared/storage/localStorage"; -import { Input } from "@mui/material"; -import { t } from "i18next"; -import { useRouter } from "next/router"; -import { getSRPAttributes } from "../api/srp"; -import { sendOtt } from "../api/user"; -import { PAGES } from "../constants/pages"; - -interface LoginProps { - signUp: () => void; - appName: APPS; -} - -export default function Login(props: LoginProps) { - const router = useRouter(); - - const loginUser: SingleInputFormProps["callback"] = async ( - email, - setFieldError, - ) => { - try { - setData(LS_KEYS.USER, { email }); - const srpAttributes = await getSRPAttributes(email); - log.debug(() => ` srpAttributes: ${JSON.stringify(srpAttributes)}`); - if (!srpAttributes || srpAttributes.isEmailMFAEnabled) { - await sendOtt(props.appName, email); - router.push(PAGES.VERIFY); - } else { - setData(LS_KEYS.SRP_ATTRIBUTES, srpAttributes); - router.push(PAGES.CREDENTIALS); - } - } catch (e) { - if (e instanceof Error) { - setFieldError(`${t("UNKNOWN_ERROR")} (reason:${e.message})`); - } else { - setFieldError( - `${t("UNKNOWN_ERROR")} (reason:${JSON.stringify(e)})`, - ); - } - } - }; - - return ( - <> - {t("LOGIN")} - - } - /> - - - - {t("NO_ACCOUNT")} - - - - ); -} diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx index 0a7d3cd4d..87976641b 100644 --- a/web/packages/accounts/pages/login.tsx +++ b/web/packages/accounts/pages/login.tsx @@ -1,14 +1,28 @@ +import log from "@/next/log"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; -import { LS_KEYS, getData } from "@ente/shared/storage/localStorage"; +import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; +import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; +import LinkButton from "@ente/shared/components/LinkButton"; +import SingleInputForm, { + type SingleInputFormProps, +} from "@ente/shared/components/SingleInputForm"; +import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; +import { Input } from "@mui/material"; +import { t } from "i18next"; import { useRouter } from "next/router"; -import { useEffect, useState } from "react"; -import Login from "../components/Login"; +import type { AppName } from "packages/next/types/app"; +import React, { useEffect, useState } from "react"; +import { getSRPAttributes } from "../api/srp"; +import { sendOtt } from "../api/user"; import { PAGES } from "../constants/pages"; +import { appNameToAppNameOld } from "@ente/shared/apps/constants"; + +const Page: React.FC = ({ appContext }) => { + const { appName, showNavBar } = appContext; -export default function LoginPage({ appContext, appName }: PageProps) { const [loading, setLoading] = useState(true); const router = useRouter(); @@ -19,7 +33,7 @@ export default function LoginPage({ appContext, appName }: PageProps) { router.push(PAGES.VERIFY); } setLoading(false); - appContext.showNavBar(true); + showNavBar(true); }, []); const register = () => { @@ -37,4 +51,65 @@ export default function LoginPage({ appContext, appName }: PageProps) { ); +}; + +export default Page; + +interface LoginProps { + signUp: () => void; + appName: AppName; +} + +function Login(props: LoginProps) { + const router = useRouter(); + + const appNameOld = appNameToAppNameOld(props.appName); + + const loginUser: SingleInputFormProps["callback"] = async ( + email, + setFieldError, + ) => { + try { + setData(LS_KEYS.USER, { email }); + const srpAttributes = await getSRPAttributes(email); + log.debug(() => ` srpAttributes: ${JSON.stringify(srpAttributes)}`); + if (!srpAttributes || srpAttributes.isEmailMFAEnabled) { + await sendOtt(appNameOld, email); + router.push(PAGES.VERIFY); + } else { + setData(LS_KEYS.SRP_ATTRIBUTES, srpAttributes); + router.push(PAGES.CREDENTIALS); + } + } catch (e) { + if (e instanceof Error) { + setFieldError(`${t("UNKNOWN_ERROR")} (reason:${e.message})`); + } else { + setFieldError( + `${t("UNKNOWN_ERROR")} (reason:${JSON.stringify(e)})`, + ); + } + } + }; + + return ( + <> + {t("LOGIN")} + + } + /> + + + + {t("NO_ACCOUNT")} + + + + ); } diff --git a/web/packages/shared/apps/constants.ts b/web/packages/shared/apps/constants.ts index b679fb912..f627db073 100644 --- a/web/packages/shared/apps/constants.ts +++ b/web/packages/shared/apps/constants.ts @@ -1,3 +1,4 @@ +import type { AppName } from "packages/next/types/app"; import { ACCOUNTS_PAGES, AUTH_PAGES, PHOTOS_PAGES } from "../constants/pages"; export enum APPS { @@ -7,6 +8,19 @@ export enum APPS { ACCOUNTS = "ACCOUNTS", } +export const appNameToAppNameOld = (appName: AppName): APPS => { + switch (appName) { + case "account": + return APPS.ACCOUNTS; + case "albums": + return APPS.ALBUMS; + case "photos": + return APPS.PHOTOS; + case "auth": + return APPS.AUTH; + } +}; + export const CLIENT_PACKAGE_NAMES = new Map([ [APPS.ALBUMS, "io.ente.albums.web"], [APPS.PHOTOS, "io.ente.photos.web"], From 14cf59c1e55988d3ad18ee13af2b40e33f13867b Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:13:02 +0530 Subject: [PATCH 08/28] recover --- web/packages/accounts/pages/login.tsx | 2 +- web/packages/accounts/pages/recover.tsx | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx index 87976641b..103f8ab14 100644 --- a/web/packages/accounts/pages/login.tsx +++ b/web/packages/accounts/pages/login.tsx @@ -1,4 +1,5 @@ import log from "@/next/log"; +import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; @@ -18,7 +19,6 @@ import React, { useEffect, useState } from "react"; import { getSRPAttributes } from "../api/srp"; import { sendOtt } from "../api/user"; import { PAGES } from "../constants/pages"; -import { appNameToAppNameOld } from "@ente/shared/apps/constants"; const Page: React.FC = ({ appContext }) => { const { appName, showNavBar } = appContext; diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsx index 09e000487..d56d0c880 100644 --- a/web/packages/accounts/pages/recover.tsx +++ b/web/packages/accounts/pages/recover.tsx @@ -2,7 +2,7 @@ import log from "@/next/log"; import { ensure } from "@/utils/ensure"; import { sendOtt } from "@ente/accounts/api/user"; import { PAGES } from "@ente/accounts/constants/pages"; -import { APP_HOMES } from "@ente/shared/apps/constants"; +import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -29,13 +29,16 @@ const bip39 = require("bip39"); // mobile client library only supports english. bip39.setDefaultWordlist("english"); -export default function Recover({ appContext, appName }: PageProps) { +const Page: React.FC = ({ appContext }) => { const [keyAttributes, setKeyAttributes] = useState< KeyAttributes | undefined >(); const router = useRouter(); + const appNameOld = appNameToAppNameOld(appContext.appName); + + useEffect(() => { const user: User = getData(LS_KEYS.USER); const keyAttributes: KeyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES); @@ -45,7 +48,7 @@ export default function Recover({ appContext, appName }: PageProps) { return; } if (!user?.encryptedToken && !user?.token) { - sendOtt(appName, user.email); + sendOtt(appNameOld, user.email); InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.RECOVER); router.push(PAGES.VERIFY); return; @@ -54,7 +57,7 @@ export default function Recover({ appContext, appName }: PageProps) { router.push(PAGES.GENERATE); } else if (key) { // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); + router.push(APP_HOMES.get(appNameOld) ?? "/"); } else { setKeyAttributes(keyAttributes); } @@ -127,4 +130,6 @@ export default function Recover({ appContext, appName }: PageProps) { ); -} +}; + +export default Page; From ba1af5eaf0669d6248eb3f1b59a88e50505ae031 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:14:34 +0530 Subject: [PATCH 09/28] Move --- web/packages/accounts/components/Login.tsx | 0 web/packages/accounts/components/SignUp.tsx | 316 -------------------- web/packages/accounts/pages/signup.tsx | 316 +++++++++++++++++++- 3 files changed, 314 insertions(+), 318 deletions(-) delete mode 100644 web/packages/accounts/components/Login.tsx delete mode 100644 web/packages/accounts/components/SignUp.tsx diff --git a/web/packages/accounts/components/Login.tsx b/web/packages/accounts/components/Login.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/packages/accounts/components/SignUp.tsx b/web/packages/accounts/components/SignUp.tsx deleted file mode 100644 index af63f4991..000000000 --- a/web/packages/accounts/components/SignUp.tsx +++ /dev/null @@ -1,316 +0,0 @@ -import log from "@/next/log"; -import { sendOtt } from "@ente/accounts/api/user"; -import { PasswordStrengthHint } from "@ente/accounts/components/PasswordStrength"; -import { PAGES } from "@ente/accounts/constants/pages"; -import { isWeakPassword } from "@ente/accounts/utils"; -import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; -import { APPS } from "@ente/shared/apps/constants"; -import { VerticallyCentered } from "@ente/shared/components//Container"; -import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; -import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; -import ShowHidePassword from "@ente/shared/components/Form/ShowHidePassword"; -import LinkButton from "@ente/shared/components/LinkButton"; -import SubmitButton from "@ente/shared/components/SubmitButton"; -import { - generateAndSaveIntermediateKeyAttributes, - saveKeyInSessionStore, -} from "@ente/shared/crypto/helpers"; -import { LS_KEYS, setData } from "@ente/shared/storage/localStorage"; -import { - setJustSignedUp, - setLocalReferralSource, -} from "@ente/shared/storage/localStorage/helpers"; -import { SESSION_KEYS } from "@ente/shared/storage/sessionStorage"; -import InfoOutlined from "@mui/icons-material/InfoOutlined"; -import { - Box, - Checkbox, - FormControlLabel, - FormGroup, - IconButton, - InputAdornment, - Link, - TextField, - Tooltip, - Typography, -} from "@mui/material"; -import { Formik, type FormikHelpers } from "formik"; -import { t } from "i18next"; -import type { NextRouter } from "next/router"; -import React, { useState } from "react"; -import { Trans } from "react-i18next"; -import * as Yup from "yup"; - -interface FormValues { - email: string; - passphrase: string; - confirm: string; - referral: string; -} - -interface SignUpProps { - router: NextRouter; - login: () => void; - appName: APPS; -} - -export default function SignUp({ router, appName, login }: SignUpProps) { - const [acceptTerms, setAcceptTerms] = useState(false); - const [loading, setLoading] = useState(false); - const [showPassword, setShowPassword] = useState(false); - - const handleClickShowPassword = () => { - setShowPassword(!showPassword); - }; - - const handleMouseDownPassword = ( - event: React.MouseEvent, - ) => { - event.preventDefault(); - }; - - const registerUser = async ( - { email, passphrase, confirm, referral }: FormValues, - { setFieldError }: FormikHelpers, - ) => { - try { - if (passphrase !== confirm) { - setFieldError("confirm", t("PASSPHRASE_MATCH_ERROR")); - return; - } - setLoading(true); - try { - setData(LS_KEYS.USER, { email }); - setLocalReferralSource(referral); - await sendOtt(appName, email); - } catch (e) { - const message = e instanceof Error ? e.message : ""; - setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`); - throw e; - } - try { - const { keyAttributes, masterKey, srpSetupAttributes } = - await generateKeyAndSRPAttributes(passphrase); - - setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); - setData(LS_KEYS.SRP_SETUP_ATTRIBUTES, srpSetupAttributes); - await generateAndSaveIntermediateKeyAttributes( - passphrase, - keyAttributes, - masterKey, - ); - - await saveKeyInSessionStore( - SESSION_KEYS.ENCRYPTION_KEY, - masterKey, - ); - setJustSignedUp(true); - router.push(PAGES.VERIFY); - } catch (e) { - setFieldError("confirm", t("PASSWORD_GENERATION_FAILED")); - throw e; - } - } catch (e) { - log.error("signup failed", e); - } - setLoading(false); - }; - - return ( - <> - {t("SIGN_UP")} - - initialValues={{ - email: "", - passphrase: "", - confirm: "", - referral: "", - }} - validationSchema={Yup.object().shape({ - email: Yup.string() - .email(t("EMAIL_ERROR")) - .required(t("REQUIRED")), - passphrase: Yup.string().required(t("REQUIRED")), - confirm: Yup.string().required(t("REQUIRED")), - })} - validateOnChange={false} - validateOnBlur={false} - onSubmit={registerUser} - > - {({ - values, - errors, - handleChange, - handleSubmit, - }): JSX.Element => ( -
- - - - - ), - }} - /> - - - - - - - {t("REFERRAL_CODE_HINT")} - - - - - - - - - ), - }} - fullWidth - name="referral" - type="text" - value={values.referral} - onChange={handleChange("referral")} - error={Boolean(errors.referral)} - disabled={loading} - /> - - - - setAcceptTerms(e.target.checked) - } - color="accent" - /> - } - label={ - - - ), - b: ( - - ), - }} - /> - - } - /> - - - - - {loading && ( - - {t("KEY_GENERATION_IN_PROGRESS_MESSAGE")} - - )} - -
- )} - - - - {t("ACCOUNT_EXISTS")} - - - ); -} diff --git a/web/packages/accounts/pages/signup.tsx b/web/packages/accounts/pages/signup.tsx index fe86df3e7..c99f6e3b0 100644 --- a/web/packages/accounts/pages/signup.tsx +++ b/web/packages/accounts/pages/signup.tsx @@ -1,12 +1,50 @@ -import SignUp from "@ente/accounts/components/SignUp"; +import log from "@/next/log"; +import { sendOtt } from "@ente/accounts/api/user"; +import { PasswordStrengthHint } from "@ente/accounts/components/PasswordStrength"; import { PAGES } from "@ente/accounts/constants/pages"; +import { isWeakPassword } from "@ente/accounts/utils"; +import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; import { LS_KEYS, getData } from "@ente/shared//storage/localStorage"; +import { APPS } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; +import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; +import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; +import ShowHidePassword from "@ente/shared/components/Form/ShowHidePassword"; +import LinkButton from "@ente/shared/components/LinkButton"; +import SubmitButton from "@ente/shared/components/SubmitButton"; +import { + generateAndSaveIntermediateKeyAttributes, + saveKeyInSessionStore, +} from "@ente/shared/crypto/helpers"; +import { setData } from "@ente/shared/storage/localStorage"; +import { + setJustSignedUp, + setLocalReferralSource, +} from "@ente/shared/storage/localStorage/helpers"; +import { SESSION_KEYS } from "@ente/shared/storage/sessionStorage"; +import InfoOutlined from "@mui/icons-material/InfoOutlined"; +import { + Box, + Checkbox, + FormControlLabel, + FormGroup, + IconButton, + InputAdornment, + Link, + TextField, + Tooltip, + Typography, +} from "@mui/material"; +import { Formik, type FormikHelpers } from "formik"; +import { t } from "i18next"; +import type { NextRouter } from "next/router"; import { useRouter } from "next/router"; -import { useEffect, useState } from "react"; +import React, { useEffect, useState } from "react"; +import { Trans } from "react-i18next"; +import * as Yup from "yup"; export default function SignUpPage({ appContext, appName }: PageProps) { const [loading, setLoading] = useState(true); @@ -38,3 +76,277 @@ export default function SignUpPage({ appContext, appName }: PageProps) { ); } + +interface FormValues { + email: string; + passphrase: string; + confirm: string; + referral: string; +} + +interface SignUpProps { + router: NextRouter; + login: () => void; + appName: APPS; +} + +function SignUp({ router, appName, login }: SignUpProps) { + const [acceptTerms, setAcceptTerms] = useState(false); + const [loading, setLoading] = useState(false); + const [showPassword, setShowPassword] = useState(false); + + const handleClickShowPassword = () => { + setShowPassword(!showPassword); + }; + + const handleMouseDownPassword = ( + event: React.MouseEvent, + ) => { + event.preventDefault(); + }; + + const registerUser = async ( + { email, passphrase, confirm, referral }: FormValues, + { setFieldError }: FormikHelpers, + ) => { + try { + if (passphrase !== confirm) { + setFieldError("confirm", t("PASSPHRASE_MATCH_ERROR")); + return; + } + setLoading(true); + try { + setData(LS_KEYS.USER, { email }); + setLocalReferralSource(referral); + await sendOtt(appName, email); + } catch (e) { + const message = e instanceof Error ? e.message : ""; + setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`); + throw e; + } + try { + const { keyAttributes, masterKey, srpSetupAttributes } = + await generateKeyAndSRPAttributes(passphrase); + + setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); + setData(LS_KEYS.SRP_SETUP_ATTRIBUTES, srpSetupAttributes); + await generateAndSaveIntermediateKeyAttributes( + passphrase, + keyAttributes, + masterKey, + ); + + await saveKeyInSessionStore( + SESSION_KEYS.ENCRYPTION_KEY, + masterKey, + ); + setJustSignedUp(true); + router.push(PAGES.VERIFY); + } catch (e) { + setFieldError("confirm", t("PASSWORD_GENERATION_FAILED")); + throw e; + } + } catch (e) { + log.error("signup failed", e); + } + setLoading(false); + }; + + return ( + <> + {t("SIGN_UP")} + + initialValues={{ + email: "", + passphrase: "", + confirm: "", + referral: "", + }} + validationSchema={Yup.object().shape({ + email: Yup.string() + .email(t("EMAIL_ERROR")) + .required(t("REQUIRED")), + passphrase: Yup.string().required(t("REQUIRED")), + confirm: Yup.string().required(t("REQUIRED")), + })} + validateOnChange={false} + validateOnBlur={false} + onSubmit={registerUser} + > + {({ + values, + errors, + handleChange, + handleSubmit, + }): JSX.Element => ( +
+ + + + + ), + }} + /> + + + + + + + {t("REFERRAL_CODE_HINT")} + + + + + + + + + ), + }} + fullWidth + name="referral" + type="text" + value={values.referral} + onChange={handleChange("referral")} + error={Boolean(errors.referral)} + disabled={loading} + /> + + + + setAcceptTerms(e.target.checked) + } + color="accent" + /> + } + label={ + + + ), + b: ( + + ), + }} + /> + + } + /> + + + + + {loading && ( + + {t("KEY_GENERATION_IN_PROGRESS_MESSAGE")} + + )} + +
+ )} + + + + {t("ACCOUNT_EXISTS")} + + + ); +} From d3d3e4dbedd6ac7b8c571dc0daa4f86fe59e2bd5 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:19:12 +0530 Subject: [PATCH 10/28] signup --- web/packages/accounts/pages/login.tsx | 4 ++-- web/packages/accounts/pages/recover.tsx | 5 ++--- web/packages/accounts/pages/signup.tsx | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx index 103f8ab14..506cc81bc 100644 --- a/web/packages/accounts/pages/login.tsx +++ b/web/packages/accounts/pages/login.tsx @@ -61,10 +61,10 @@ interface LoginProps { } function Login(props: LoginProps) { - const router = useRouter(); - const appNameOld = appNameToAppNameOld(props.appName); + const router = useRouter(); + const loginUser: SingleInputFormProps["callback"] = async ( email, setFieldError, diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsx index d56d0c880..53596ef6c 100644 --- a/web/packages/accounts/pages/recover.tsx +++ b/web/packages/accounts/pages/recover.tsx @@ -30,15 +30,14 @@ const bip39 = require("bip39"); bip39.setDefaultWordlist("english"); const Page: React.FC = ({ appContext }) => { + const appNameOld = appNameToAppNameOld(appContext.appName); + const [keyAttributes, setKeyAttributes] = useState< KeyAttributes | undefined >(); const router = useRouter(); - const appNameOld = appNameToAppNameOld(appContext.appName); - - useEffect(() => { const user: User = getData(LS_KEYS.USER); const keyAttributes: KeyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES); diff --git a/web/packages/accounts/pages/signup.tsx b/web/packages/accounts/pages/signup.tsx index c99f6e3b0..02f810250 100644 --- a/web/packages/accounts/pages/signup.tsx +++ b/web/packages/accounts/pages/signup.tsx @@ -5,7 +5,7 @@ import { PAGES } from "@ente/accounts/constants/pages"; import { isWeakPassword } from "@ente/accounts/utils"; import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; import { LS_KEYS, getData } from "@ente/shared//storage/localStorage"; -import { APPS } from "@ente/shared/apps/constants"; +import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; @@ -42,11 +42,14 @@ import { Formik, type FormikHelpers } from "formik"; import { t } from "i18next"; import type { NextRouter } from "next/router"; import { useRouter } from "next/router"; +import type { AppName } from "packages/next/types/app"; import React, { useEffect, useState } from "react"; import { Trans } from "react-i18next"; import * as Yup from "yup"; -export default function SignUpPage({ appContext, appName }: PageProps) { +const Page: React.FC = ({ appContext }) => { + const { appName } = appContext; + const [loading, setLoading] = useState(true); const router = useRouter(); @@ -75,7 +78,9 @@ export default function SignUpPage({ appContext, appName }: PageProps) { )} ); -} +}; + +export default Page; interface FormValues { email: string; @@ -87,10 +92,12 @@ interface FormValues { interface SignUpProps { router: NextRouter; login: () => void; - appName: APPS; + appName: AppName; } function SignUp({ router, appName, login }: SignUpProps) { + const appNameOld = appNameToAppNameOld(appName); + const [acceptTerms, setAcceptTerms] = useState(false); const [loading, setLoading] = useState(false); const [showPassword, setShowPassword] = useState(false); @@ -118,7 +125,7 @@ function SignUp({ router, appName, login }: SignUpProps) { try { setData(LS_KEYS.USER, { email }); setLocalReferralSource(referral); - await sendOtt(appName, email); + await sendOtt(appNameOld, email); } catch (e) { const message = e instanceof Error ? e.message : ""; setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`); From b99c573d3a30161ca96887d919362a07496256bc Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:22:07 +0530 Subject: [PATCH 11/28] verify --- web/packages/accounts/pages/recover.tsx | 4 +++- web/packages/accounts/pages/verify.tsx | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsx index 53596ef6c..a93cf53cc 100644 --- a/web/packages/accounts/pages/recover.tsx +++ b/web/packages/accounts/pages/recover.tsx @@ -30,7 +30,9 @@ const bip39 = require("bip39"); bip39.setDefaultWordlist("english"); const Page: React.FC = ({ appContext }) => { - const appNameOld = appNameToAppNameOld(appContext.appName); + const { appName } = appContext; + + const appNameOld = appNameToAppNameOld(appName); const [keyAttributes, setKeyAttributes] = useState< KeyAttributes | undefined diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx index 2fff513be..025b39961 100644 --- a/web/packages/accounts/pages/verify.tsx +++ b/web/packages/accounts/pages/verify.tsx @@ -1,5 +1,6 @@ import { ensure } from "@/utils/ensure"; import type { UserVerificationResponse } from "@ente/accounts/types/user"; +import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; @@ -32,8 +33,10 @@ import { PAGES } from "../constants/pages"; import { configureSRP } from "../services/srp"; import type { SRPSetupAttributes } from "../types/srp"; -export default function VerifyPage({ appContext, appName }: PageProps) { - const { logout } = appContext; +const Page: React.FC = ({ appContext }) => { + const { appName, logout } = appContext; + + const appNameOld = appNameToAppNameOld(appName); const [email, setEmail] = useState(""); const [resend, setResend] = useState(0); @@ -148,7 +151,7 @@ export default function VerifyPage({ appContext, appName }: PageProps) { const resendEmail = async () => { setResend(1); - await sendOtt(appName, email); + await sendOtt(appNameOld, email); setResend(2); setTimeout(() => setResend(0), 3000); }; @@ -199,4 +202,6 @@ export default function VerifyPage({ appContext, appName }: PageProps) { ); -} +}; + +export default Page; From 17b49595a01d4e60731b0d5ea53b55cf0546249b Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:23:55 +0530 Subject: [PATCH 12/28] generate --- web/packages/accounts/pages/generate.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsx index 21c803bc6..e367813e7 100644 --- a/web/packages/accounts/pages/generate.tsx +++ b/web/packages/accounts/pages/generate.tsx @@ -7,7 +7,7 @@ import SetPasswordForm, { import { PAGES } from "@ente/accounts/constants/pages"; import { configureSRP } from "@ente/accounts/services/srp"; import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; -import { APP_HOMES } from "@ente/shared/apps/constants"; +import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; @@ -31,8 +31,10 @@ import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; -export default function Generate({ appContext, appName }: PageProps) { - const { logout } = appContext; +const Page: React.FC = ({ appContext }) => { + const { appName, logout } = appContext; + + const appNameOld = appNameToAppNameOld(appName); const [token, setToken] = useState(); const [user, setUser] = useState(); @@ -57,7 +59,7 @@ export default function Generate({ appContext, appName }: PageProps) { setLoading(false); } else { // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); + router.push(APP_HOMES.get(appNameOld) ?? "/"); } } else if (keyAttributes?.encryptedKey) { router.push(PAGES.CREDENTIALS); @@ -108,7 +110,7 @@ export default function Generate({ appContext, appName }: PageProps) { onHide={() => { setRecoveryModalView(false); // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); + router.push(APP_HOMES.get(appNameOld) ?? "/"); }} /* TODO: Why is this error being ignored */ somethingWentWrong={() => {}} @@ -132,4 +134,6 @@ export default function Generate({ appContext, appName }: PageProps) { )} ); -} +}; + +export default Page; From ca00b3b55859cdba2fc6bb4746bf5b2286e50bc8 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:55:20 +0530 Subject: [PATCH 13/28] creds --- web/packages/accounts/pages/credentials.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx index 91fcc56ae..05d846dce 100644 --- a/web/packages/accounts/pages/credentials.tsx +++ b/web/packages/accounts/pages/credentials.tsx @@ -1,7 +1,7 @@ import { isDevBuild } from "@/next/env"; import log from "@/next/log"; import { ensure } from "@/utils/ensure"; -import { APP_HOMES } from "@ente/shared/apps/constants"; +import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; @@ -53,8 +53,10 @@ import { } from "../services/srp"; import type { SRPAttributes } from "../types/srp"; -export default function Credentials({ appContext, appName }: PageProps) { - const { logout } = appContext; +const Page: React.FC = ({ appContext }) => { + const { appName, logout } = appContext; + + const appNameOld = appNameToAppNameOld(appName); const [srpAttributes, setSrpAttributes] = useState(); const [keyAttributes, setKeyAttributes] = useState(); @@ -88,7 +90,7 @@ export default function Credentials({ appContext, appName }: PageProps) { const token = getToken(); if (key && token) { // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); + router.push(APP_HOMES.get(appNameOld) ?? "/"); return; } const kekEncryptedAttributes: B64EncryptionResult = getKey( @@ -248,7 +250,7 @@ export default function Credentials({ appContext, appName }: PageProps) { } const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL); InMemoryStore.delete(MS_KEYS.REDIRECT_URL); - router.push(redirectURL ?? APP_HOMES.get(appName)); + router.push(redirectURL ?? APP_HOMES.get(appNameOld)); } catch (e) { log.error("useMasterPassword failed", e); } @@ -295,6 +297,8 @@ export default function Credentials({ appContext, appName }: PageProps) { ); } +export default Page; + const Header: React.FC = ({ children }) => { return ( From 3a5311cdcc438e4d988d406d4b4d47d49c11dd46 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 18:58:57 +0530 Subject: [PATCH 14/28] cp --- web/packages/accounts/pages/change-password.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsx index ec367f6c8..b0e6dcb70 100644 --- a/web/packages/accounts/pages/change-password.tsx +++ b/web/packages/accounts/pages/change-password.tsx @@ -13,7 +13,7 @@ import { convertBase64ToBuffer, convertBufferToBase64, } from "@ente/accounts/utils"; -import { APP_HOMES } from "@ente/shared/apps/constants"; +import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -35,7 +35,11 @@ import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; -export default function ChangePassword({ appName }: PageProps) { +const Page: React.FC = ({ appContext }) => { + const { appName } = appContext; + + const appNameOld = appNameToAppNameOld(appName); + const [token, setToken] = useState(); const [user, setUser] = useState(); @@ -123,7 +127,7 @@ export default function ChangePassword({ appName }: PageProps) { const redirectToAppHome = () => { setData(LS_KEYS.SHOW_BACK_BUTTON, { value: true }); // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); + router.push(APP_HOMES.get(appNameOld) ?? "/"); }; // TODO: Handle the case where user is not loaded yet. @@ -146,4 +150,6 @@ export default function ChangePassword({ appName }: PageProps) { ); -} +}; + +export default Page; From 49133b7b86bc049b7cde8e9b41a3a5d1c8f7e462 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 19:02:47 +0530 Subject: [PATCH 15/28] Move --- .../accounts/components/ChangeEmail.tsx | 184 ------------------ web/packages/accounts/pages/change-email.tsx | 181 ++++++++++++++++- 2 files changed, 178 insertions(+), 187 deletions(-) delete mode 100644 web/packages/accounts/components/ChangeEmail.tsx diff --git a/web/packages/accounts/components/ChangeEmail.tsx b/web/packages/accounts/components/ChangeEmail.tsx deleted file mode 100644 index 1fb3e734a..000000000 --- a/web/packages/accounts/components/ChangeEmail.tsx +++ /dev/null @@ -1,184 +0,0 @@ -import { ensure } from "@/utils/ensure"; -import { wait } from "@/utils/promise"; -import { changeEmail, sendOTTForEmailChange } from "@ente/accounts/api/user"; -import { APP_HOMES } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; -import { VerticallyCentered } from "@ente/shared/components/Container"; -import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; -import LinkButton from "@ente/shared/components/LinkButton"; -import SubmitButton from "@ente/shared/components/SubmitButton"; -import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; -import { Alert, Box, TextField } from "@mui/material"; -import { Formik, type FormikHelpers } from "formik"; -import { t } from "i18next"; -import { useRouter } from "next/router"; -import { useState } from "react"; -import { Trans } from "react-i18next"; -import * as Yup from "yup"; - -interface formValues { - email: string; - ott?: string; -} - -function ChangeEmailForm({ appName }: PageProps) { - const [loading, setLoading] = useState(false); - const [ottInputVisible, setShowOttInputVisibility] = useState(false); - const [email, setEmail] = useState(null); - const [showMessage, setShowMessage] = useState(false); - const [success, setSuccess] = useState(false); - - const router = useRouter(); - - const requestOTT = async ( - { email }: formValues, - { setFieldError }: FormikHelpers, - ) => { - try { - setLoading(true); - await sendOTTForEmailChange(email); - setEmail(email); - setShowOttInputVisibility(true); - setShowMessage(true); - // TODO: What was this meant to focus on? The ref referred to an - // Form element that was removed. Is this still needed. - // setTimeout(() => { - // ottInputRef.current?.focus(); - // }, 250); - } catch (e) { - setFieldError("email", t("EMAIl_ALREADY_OWNED")); - } - setLoading(false); - }; - - const requestEmailChange = async ( - { email, ott }: formValues, - { setFieldError }: FormikHelpers, - ) => { - try { - setLoading(true); - await changeEmail(email, ensure(ott)); - setData(LS_KEYS.USER, { ...getData(LS_KEYS.USER), email }); - setLoading(false); - setSuccess(true); - await wait(1000); - goToApp(); - } catch (e) { - setLoading(false); - setFieldError("ott", t("INCORRECT_CODE")); - } - }; - - const goToApp = () => { - // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); - }; - - return ( - - initialValues={{ email: "" }} - validationSchema={ - ottInputVisible - ? Yup.object().shape({ - email: Yup.string() - .email(t("EMAIL_ERROR")) - .required(t("REQUIRED")), - ott: Yup.string().required(t("REQUIRED")), - }) - : Yup.object().shape({ - email: Yup.string() - .email(t("EMAIL_ERROR")) - .required(t("REQUIRED")), - }) - } - validateOnChange={false} - validateOnBlur={false} - onSubmit={!ottInputVisible ? requestOTT : requestEmailChange} - > - {({ values, errors, handleChange, handleSubmit }) => ( - <> - {showMessage && ( - setShowMessage(false)} - > - - ), - }} - values={{ email }} - /> - - )} -
- - - {ottInputVisible && ( - - )} - - -
- - - {ottInputVisible && ( - setShowOttInputVisibility(false)} - > - {t("CHANGE_EMAIL")}? - - )} - - {t("GO_BACK")} - - - - )} - - ); -} - -export default ChangeEmailForm; diff --git a/web/packages/accounts/pages/change-email.tsx b/web/packages/accounts/pages/change-email.tsx index a15ad2a59..572f797de 100644 --- a/web/packages/accounts/pages/change-email.tsx +++ b/web/packages/accounts/pages/change-email.tsx @@ -1,13 +1,23 @@ -import ChangeEmailForm from "@ente/accounts/components/ChangeEmail"; +import { ensure } from "@/utils/ensure"; +import { wait } from "@/utils/promise"; +import { changeEmail, sendOTTForEmailChange } from "@ente/accounts/api/user"; import { PAGES } from "@ente/accounts/constants/pages"; +import { APP_HOMES } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; +import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; -import { getData, LS_KEYS } from "@ente/shared/storage/localStorage"; +import LinkButton from "@ente/shared/components/LinkButton"; +import SubmitButton from "@ente/shared/components/SubmitButton"; +import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; +import { Alert, Box, TextField } from "@mui/material"; +import { Formik, type FormikHelpers } from "formik"; import { t } from "i18next"; import { useRouter } from "next/router"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; +import { Trans } from "react-i18next"; +import * as Yup from "yup"; function ChangeEmailPage({ appName, appContext }: PageProps) { const router = useRouter(); @@ -30,3 +40,168 @@ function ChangeEmailPage({ appName, appContext }: PageProps) { } export default ChangeEmailPage; + +interface formValues { + email: string; + ott?: string; +} + +function ChangeEmailForm({ appName }: PageProps) { + const [loading, setLoading] = useState(false); + const [ottInputVisible, setShowOttInputVisibility] = useState(false); + const [email, setEmail] = useState(null); + const [showMessage, setShowMessage] = useState(false); + const [success, setSuccess] = useState(false); + + const router = useRouter(); + + const requestOTT = async ( + { email }: formValues, + { setFieldError }: FormikHelpers, + ) => { + try { + setLoading(true); + await sendOTTForEmailChange(email); + setEmail(email); + setShowOttInputVisibility(true); + setShowMessage(true); + // TODO: What was this meant to focus on? The ref referred to an + // Form element that was removed. Is this still needed. + // setTimeout(() => { + // ottInputRef.current?.focus(); + // }, 250); + } catch (e) { + setFieldError("email", t("EMAIl_ALREADY_OWNED")); + } + setLoading(false); + }; + + const requestEmailChange = async ( + { email, ott }: formValues, + { setFieldError }: FormikHelpers, + ) => { + try { + setLoading(true); + await changeEmail(email, ensure(ott)); + setData(LS_KEYS.USER, { ...getData(LS_KEYS.USER), email }); + setLoading(false); + setSuccess(true); + await wait(1000); + goToApp(); + } catch (e) { + setLoading(false); + setFieldError("ott", t("INCORRECT_CODE")); + } + }; + + const goToApp = () => { + // TODO: Refactor the type of APP_HOMES to not require the ?? + router.push(APP_HOMES.get(appName) ?? "/"); + }; + + return ( + + initialValues={{ email: "" }} + validationSchema={ + ottInputVisible + ? Yup.object().shape({ + email: Yup.string() + .email(t("EMAIL_ERROR")) + .required(t("REQUIRED")), + ott: Yup.string().required(t("REQUIRED")), + }) + : Yup.object().shape({ + email: Yup.string() + .email(t("EMAIL_ERROR")) + .required(t("REQUIRED")), + }) + } + validateOnChange={false} + validateOnBlur={false} + onSubmit={!ottInputVisible ? requestOTT : requestEmailChange} + > + {({ values, errors, handleChange, handleSubmit }) => ( + <> + {showMessage && ( + setShowMessage(false)} + > + + ), + }} + values={{ email }} + /> + + )} +
+ + + {ottInputVisible && ( + + )} + + +
+ + + {ottInputVisible && ( + setShowOttInputVisibility(false)} + > + {t("CHANGE_EMAIL")}? + + )} + + {t("GO_BACK")} + + + + )} + + ); +} From 345c7068141520ca4d076fa2ff0248d3b5a156be Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 19:07:48 +0530 Subject: [PATCH 16/28] ce --- web/packages/accounts/pages/change-email.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/web/packages/accounts/pages/change-email.tsx b/web/packages/accounts/pages/change-email.tsx index 572f797de..073bef30e 100644 --- a/web/packages/accounts/pages/change-email.tsx +++ b/web/packages/accounts/pages/change-email.tsx @@ -2,7 +2,11 @@ import { ensure } from "@/utils/ensure"; import { wait } from "@/utils/promise"; import { changeEmail, sendOTTForEmailChange } from "@ente/accounts/api/user"; import { PAGES } from "@ente/accounts/constants/pages"; -import { APP_HOMES } from "@ente/shared/apps/constants"; +import { + APP_HOMES, + appNameToAppNameOld, + type APPS, +} from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -19,7 +23,11 @@ import { useEffect, useState } from "react"; import { Trans } from "react-i18next"; import * as Yup from "yup"; -function ChangeEmailPage({ appName, appContext }: PageProps) { +const Page: React.FC = ({ appContext }) => { + const { appName } = appContext; + + const appNameOld = appNameToAppNameOld(appName); + const router = useRouter(); useEffect(() => { @@ -33,20 +41,20 @@ function ChangeEmailPage({ appName, appContext }: PageProps) { {t("CHANGE_EMAIL")} - + ); -} +}; -export default ChangeEmailPage; +export default Page; interface formValues { email: string; ott?: string; } -function ChangeEmailForm({ appName }: PageProps) { +function ChangeEmailForm({ appName }: { appName: APPS }) { const [loading, setLoading] = useState(false); const [ottInputVisible, setShowOttInputVisibility] = useState(false); const [email, setEmail] = useState(null); From 27127ff3d44b759468c1ea4f8341488428442698 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 19:10:50 +0530 Subject: [PATCH 17/28] 2fa --- web/packages/accounts/pages/two-factor/setup.tsx | 14 ++++++++++---- web/packages/accounts/pages/two-factor/verify.tsx | 9 +++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/web/packages/accounts/pages/two-factor/setup.tsx b/web/packages/accounts/pages/two-factor/setup.tsx index 66e24caf5..193bfb60f 100644 --- a/web/packages/accounts/pages/two-factor/setup.tsx +++ b/web/packages/accounts/pages/two-factor/setup.tsx @@ -6,7 +6,7 @@ import VerifyTwoFactor, { } from "@ente/accounts/components/two-factor/VerifyForm"; import { TwoFactorSetup } from "@ente/accounts/components/two-factor/setup"; import type { TwoFactorSecret } from "@ente/accounts/types/user"; -import { APP_HOMES } from "@ente/shared/apps/constants"; +import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import LinkButton from "@ente/shared/components/LinkButton"; @@ -23,7 +23,11 @@ export enum SetupMode { MANUAL_CODE, } -export default function SetupTwoFactor({ appName }: PageProps) { +const Page: React.FC = ({ appContext }) => { + const { appName } = appContext; + + const appNameOld = appNameToAppNameOld(appName); + const [twoFactorSecret, setTwoFactorSecret] = useState< TwoFactorSecret | undefined >(); @@ -59,7 +63,7 @@ export default function SetupTwoFactor({ appName }: PageProps) { isTwoFactorEnabled: true, }); // TODO: Refactor the type of APP_HOMES to not require the ?? - router.push(APP_HOMES.get(appName) ?? "/"); + router.push(APP_HOMES.get(appNameOld) ?? "/"); }; return ( @@ -85,4 +89,6 @@ export default function SetupTwoFactor({ appName }: PageProps) { ); -} +}; + +export default Page; diff --git a/web/packages/accounts/pages/two-factor/verify.tsx b/web/packages/accounts/pages/two-factor/verify.tsx index 510eaf60f..322b25ffc 100644 --- a/web/packages/accounts/pages/two-factor/verify.tsx +++ b/web/packages/accounts/pages/two-factor/verify.tsx @@ -1,10 +1,9 @@ +import { ensure } from "@/utils/ensure"; import { verifyTwoFactor } from "@ente/accounts/api/user"; import VerifyTwoFactor, { type VerifyTwoFactorCallback, } from "@ente/accounts/components/two-factor/VerifyForm"; import { PAGES } from "@ente/accounts/constants/pages"; - -import { ensure } from "@/utils/ensure"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -20,9 +19,7 @@ import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; -export const TwoFactorVerify: React.FC = ({ - appContext, -}: PageProps) => { +const Page: React.FC = ({ appContext }) => { const { logout } = appContext; const [sessionID, setSessionID] = useState(""); @@ -93,4 +90,4 @@ export const TwoFactorVerify: React.FC = ({ ); }; -export default TwoFactorVerify; +export default Page; From 55bdb070ce9fea653ac83351e146b135b1ef4510 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 19:14:35 +0530 Subject: [PATCH 18/28] Wrap --- web/packages/accounts/pages/passkeys/finish.tsx | 4 ++-- web/packages/accounts/pages/two-factor/recover.tsx | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/web/packages/accounts/pages/passkeys/finish.tsx b/web/packages/accounts/pages/passkeys/finish.tsx index 4e85e3e43..3f8ae8548 100644 --- a/web/packages/accounts/pages/passkeys/finish.tsx +++ b/web/packages/accounts/pages/passkeys/finish.tsx @@ -6,7 +6,7 @@ import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; import { useRouter } from "next/router"; import { useEffect } from "react"; -const PasskeysFinishPage = () => { +const Page = () => { const router = useRouter(); const init = async () => { @@ -43,4 +43,4 @@ const PasskeysFinishPage = () => { ); }; -export default PasskeysFinishPage; +export default Page; diff --git a/web/packages/accounts/pages/two-factor/recover.tsx b/web/packages/accounts/pages/two-factor/recover.tsx index dd69d6b36..ffad62625 100644 --- a/web/packages/accounts/pages/two-factor/recover.tsx +++ b/web/packages/accounts/pages/two-factor/recover.tsx @@ -29,10 +29,10 @@ const bip39 = require("bip39"); // mobile client library only supports english. bip39.setDefaultWordlist("english"); -export default function Recover({ +const Page: React.FC = ({ appContext, twoFactorType = TwoFactorType.TOTP, -}: PageProps) { +}) => { const { logout } = appContext; const [encryptedTwoFactorSecret, setEncryptedTwoFactorSecret] = @@ -182,4 +182,6 @@ export default function Recover({ ); -} +}; + +export default Page; From 693ef45e2c4f8b12c6f758c8b44157f9258aa9f3 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 19:31:05 +0530 Subject: [PATCH 19/28] Refactor --- web/apps/accounts/src/pages/credentials.tsx | 8 ++++++++ web/apps/accounts/src/pages/credentials/index.tsx | 9 --------- web/apps/accounts/src/pages/generate.tsx | 8 ++++++++ web/apps/accounts/src/pages/generate/index.tsx | 9 --------- web/apps/accounts/src/pages/login.tsx | 8 ++++++++ web/apps/accounts/src/pages/login/index.tsx | 9 --------- web/apps/accounts/src/pages/recover.tsx | 8 ++++++++ web/apps/accounts/src/pages/recover/index.tsx | 9 --------- web/apps/accounts/src/pages/signup.tsx | 8 ++++++++ web/apps/accounts/src/pages/signup/index.tsx | 9 --------- web/apps/accounts/src/pages/two-factor/recover.tsx | 8 ++++++++ .../accounts/src/pages/two-factor/recover/index.tsx | 11 ----------- web/apps/accounts/src/pages/two-factor/setup.tsx | 8 ++++++++ .../accounts/src/pages/two-factor/setup/index.tsx | 11 ----------- web/apps/accounts/src/pages/two-factor/verify.tsx | 8 ++++++++ .../accounts/src/pages/two-factor/verify/index.tsx | 11 ----------- web/apps/accounts/src/pages/verify.tsx | 8 ++++++++ web/apps/accounts/src/pages/verify/index.tsx | 9 --------- web/packages/shared/apps/types.ts | 2 +- 19 files changed, 73 insertions(+), 88 deletions(-) create mode 100644 web/apps/accounts/src/pages/credentials.tsx delete mode 100644 web/apps/accounts/src/pages/credentials/index.tsx create mode 100644 web/apps/accounts/src/pages/generate.tsx delete mode 100644 web/apps/accounts/src/pages/generate/index.tsx create mode 100644 web/apps/accounts/src/pages/login.tsx delete mode 100644 web/apps/accounts/src/pages/login/index.tsx create mode 100644 web/apps/accounts/src/pages/recover.tsx delete mode 100644 web/apps/accounts/src/pages/recover/index.tsx create mode 100644 web/apps/accounts/src/pages/signup.tsx delete mode 100644 web/apps/accounts/src/pages/signup/index.tsx create mode 100644 web/apps/accounts/src/pages/two-factor/recover.tsx delete mode 100644 web/apps/accounts/src/pages/two-factor/recover/index.tsx create mode 100644 web/apps/accounts/src/pages/two-factor/setup.tsx delete mode 100644 web/apps/accounts/src/pages/two-factor/setup/index.tsx create mode 100644 web/apps/accounts/src/pages/two-factor/verify.tsx delete mode 100644 web/apps/accounts/src/pages/two-factor/verify/index.tsx create mode 100644 web/apps/accounts/src/pages/verify.tsx delete mode 100644 web/apps/accounts/src/pages/verify/index.tsx diff --git a/web/apps/accounts/src/pages/credentials.tsx b/web/apps/accounts/src/pages/credentials.tsx new file mode 100644 index 000000000..7d21b33ac --- /dev/null +++ b/web/apps/accounts/src/pages/credentials.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/credentials"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/credentials/index.tsx b/web/apps/accounts/src/pages/credentials/index.tsx deleted file mode 100644 index 306efc7b8..000000000 --- a/web/apps/accounts/src/pages/credentials/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import CredentialPage from "@ente/accounts/pages/credentials"; -import { APPS } from "@ente/shared/apps/constants"; -import { useContext } from "react"; -import { AppContext } from "../_app"; - -export default function Credential() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/accounts/src/pages/generate.tsx b/web/apps/accounts/src/pages/generate.tsx new file mode 100644 index 000000000..718172d49 --- /dev/null +++ b/web/apps/accounts/src/pages/generate.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/generate"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/generate/index.tsx b/web/apps/accounts/src/pages/generate/index.tsx deleted file mode 100644 index ff1b6aa1f..000000000 --- a/web/apps/accounts/src/pages/generate/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import GeneratePage from "@ente/accounts/pages/generate"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Generate() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/accounts/src/pages/login.tsx b/web/apps/accounts/src/pages/login.tsx new file mode 100644 index 000000000..b40b9f914 --- /dev/null +++ b/web/apps/accounts/src/pages/login.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/login"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/login/index.tsx b/web/apps/accounts/src/pages/login/index.tsx deleted file mode 100644 index 0631a7bd1..000000000 --- a/web/apps/accounts/src/pages/login/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import LoginPage from "@ente/accounts/pages/login"; -import { APPS } from "@ente/shared/apps/constants"; -import { useContext } from "react"; -import { AppContext } from "../_app"; - -export default function Login() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/accounts/src/pages/recover.tsx b/web/apps/accounts/src/pages/recover.tsx new file mode 100644 index 000000000..cc6d8da82 --- /dev/null +++ b/web/apps/accounts/src/pages/recover.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/recover"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/recover/index.tsx b/web/apps/accounts/src/pages/recover/index.tsx deleted file mode 100644 index 2692225b2..000000000 --- a/web/apps/accounts/src/pages/recover/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import RecoverPage from "@ente/accounts/pages/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Recover() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/accounts/src/pages/signup.tsx b/web/apps/accounts/src/pages/signup.tsx new file mode 100644 index 000000000..8cc5202a8 --- /dev/null +++ b/web/apps/accounts/src/pages/signup.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/signup"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/signup/index.tsx b/web/apps/accounts/src/pages/signup/index.tsx deleted file mode 100644 index 40d073cf5..000000000 --- a/web/apps/accounts/src/pages/signup/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import SignupPage from "@ente/accounts/pages/signup"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Sigup() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/accounts/src/pages/two-factor/recover.tsx b/web/apps/accounts/src/pages/two-factor/recover.tsx new file mode 100644 index 000000000..aa9c6faf9 --- /dev/null +++ b/web/apps/accounts/src/pages/two-factor/recover.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/two-factor/recover"; +import { useContext } from "react"; +import { AppContext } from "../_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/recover/index.tsx b/web/apps/accounts/src/pages/two-factor/recover/index.tsx deleted file mode 100644 index af5765323..000000000 --- a/web/apps/accounts/src/pages/two-factor/recover/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import TwoFactorRecoverPage from "@ente/accounts/pages/two-factor/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function TwoFactorRecover() { - const appContext = useContext(AppContext); - return ( - - ); -} diff --git a/web/apps/accounts/src/pages/two-factor/setup.tsx b/web/apps/accounts/src/pages/two-factor/setup.tsx new file mode 100644 index 000000000..35a24149f --- /dev/null +++ b/web/apps/accounts/src/pages/two-factor/setup.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/two-factor/setup"; +import { useContext } from "react"; +import { AppContext } from "../_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/setup/index.tsx b/web/apps/accounts/src/pages/two-factor/setup/index.tsx deleted file mode 100644 index f1283e870..000000000 --- a/web/apps/accounts/src/pages/two-factor/setup/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import TwoFactorSetupPage from "@ente/accounts/pages/two-factor/setup"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function TwoFactorSetup() { - const appContext = useContext(AppContext); - return ( - - ); -} diff --git a/web/apps/accounts/src/pages/two-factor/verify.tsx b/web/apps/accounts/src/pages/two-factor/verify.tsx new file mode 100644 index 000000000..3f4ed7e39 --- /dev/null +++ b/web/apps/accounts/src/pages/two-factor/verify.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/two-factor/verify"; +import { useContext } from "react"; +import { AppContext } from "../_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/verify/index.tsx b/web/apps/accounts/src/pages/two-factor/verify/index.tsx deleted file mode 100644 index fd4c2ce09..000000000 --- a/web/apps/accounts/src/pages/two-factor/verify/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import TwoFactorVerifyPage from "@ente/accounts/pages/two-factor/verify"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function TwoFactorVerify() { - const appContext = useContext(AppContext); - return ( - - ); -} diff --git a/web/apps/accounts/src/pages/verify.tsx b/web/apps/accounts/src/pages/verify.tsx new file mode 100644 index 000000000..5fb2ed10d --- /dev/null +++ b/web/apps/accounts/src/pages/verify.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/verify"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/accounts/src/pages/verify/index.tsx b/web/apps/accounts/src/pages/verify/index.tsx deleted file mode 100644 index b09480858..000000000 --- a/web/apps/accounts/src/pages/verify/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import VerifyPage from "@ente/accounts/pages/verify"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Verify() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/packages/shared/apps/types.ts b/web/packages/shared/apps/types.ts index cde24788d..54424f146 100644 --- a/web/packages/shared/apps/types.ts +++ b/web/packages/shared/apps/types.ts @@ -4,6 +4,6 @@ import { APPS } from "./constants"; export interface PageProps { appContext: BaseAppContextT; - appName: APPS; + appName?: APPS; twoFactorType?: TwoFactorType; } From 19a104374d7188861e0eed5abcd72a75811f6863 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 19:48:12 +0530 Subject: [PATCH 20/28] Refactor --- web/apps/auth/src/pages/change-email.tsx | 12 ++++-------- web/apps/auth/src/pages/change-password.tsx | 12 ++++-------- web/apps/auth/src/pages/credentials.tsx | 12 ++++-------- web/apps/auth/src/pages/generate.tsx | 12 ++++-------- web/apps/auth/src/pages/login.tsx | 12 ++++-------- web/apps/auth/src/pages/recover.tsx | 12 ++++-------- web/apps/auth/src/pages/signup.tsx | 12 ++++-------- web/apps/auth/src/pages/two-factor/recover.tsx | 12 ++++-------- web/apps/auth/src/pages/two-factor/setup.tsx | 12 ++++-------- web/apps/auth/src/pages/two-factor/verify.tsx | 10 +++------- web/apps/auth/src/pages/verify.tsx | 12 ++++-------- 11 files changed, 43 insertions(+), 87 deletions(-) diff --git a/web/apps/auth/src/pages/change-email.tsx b/web/apps/auth/src/pages/change-email.tsx index bcde88a05..451c5ebfe 100644 --- a/web/apps/auth/src/pages/change-email.tsx +++ b/web/apps/auth/src/pages/change-email.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import ChangeEmailPage from "@ente/accounts/pages/change-email"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/change-email"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/change-password.tsx b/web/apps/auth/src/pages/change-password.tsx index cc0bfe472..ba8e1ac3d 100644 --- a/web/apps/auth/src/pages/change-password.tsx +++ b/web/apps/auth/src/pages/change-password.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import ChangePasswordPage from "@ente/accounts/pages/change-password"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/change-password"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/credentials.tsx b/web/apps/auth/src/pages/credentials.tsx index 5e19957a3..7d21b33ac 100644 --- a/web/apps/auth/src/pages/credentials.tsx +++ b/web/apps/auth/src/pages/credentials.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import CredentialPage from "@ente/accounts/pages/credentials"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/credentials"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/generate.tsx b/web/apps/auth/src/pages/generate.tsx index 4edfa25a2..718172d49 100644 --- a/web/apps/auth/src/pages/generate.tsx +++ b/web/apps/auth/src/pages/generate.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import GeneratePage from "@ente/accounts/pages/generate"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/generate"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/login.tsx b/web/apps/auth/src/pages/login.tsx index 3f87f8247..b40b9f914 100644 --- a/web/apps/auth/src/pages/login.tsx +++ b/web/apps/auth/src/pages/login.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import LoginPage from "@ente/accounts/pages/login"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/login"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/recover.tsx b/web/apps/auth/src/pages/recover.tsx index 8081bd545..cc6d8da82 100644 --- a/web/apps/auth/src/pages/recover.tsx +++ b/web/apps/auth/src/pages/recover.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import RecoverPage from "@ente/accounts/pages/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/recover"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/signup.tsx b/web/apps/auth/src/pages/signup.tsx index 1fcdeb832..8cc5202a8 100644 --- a/web/apps/auth/src/pages/signup.tsx +++ b/web/apps/auth/src/pages/signup.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import SignupPage from "@ente/accounts/pages/signup"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/signup"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/two-factor/recover.tsx b/web/apps/auth/src/pages/two-factor/recover.tsx index 1561922c4..aa9c6faf9 100644 --- a/web/apps/auth/src/pages/two-factor/recover.tsx +++ b/web/apps/auth/src/pages/two-factor/recover.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import TwoFactorRecoverPage from "@ente/accounts/pages/two-factor/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/two-factor/recover"; +import { useContext } from "react"; +import { AppContext } from "../_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/two-factor/setup.tsx b/web/apps/auth/src/pages/two-factor/setup.tsx index 5ef376776..35a24149f 100644 --- a/web/apps/auth/src/pages/two-factor/setup.tsx +++ b/web/apps/auth/src/pages/two-factor/setup.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import TwoFactorSetupPage from "@ente/accounts/pages/two-factor/setup"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/two-factor/setup"; +import { useContext } from "react"; +import { AppContext } from "../_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/two-factor/verify.tsx b/web/apps/auth/src/pages/two-factor/verify.tsx index 5ffd007a3..3f4ed7e39 100644 --- a/web/apps/auth/src/pages/two-factor/verify.tsx +++ b/web/apps/auth/src/pages/two-factor/verify.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import TwoFactorVerifyPage from "@ente/accounts/pages/two-factor/verify"; -import { APPS } from "@ente/shared/apps/constants"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/two-factor/verify"; +import { useContext } from "react"; import { AppContext } from "../_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/verify.tsx b/web/apps/auth/src/pages/verify.tsx index 573ee79d1..5fb2ed10d 100644 --- a/web/apps/auth/src/pages/verify.tsx +++ b/web/apps/auth/src/pages/verify.tsx @@ -1,12 +1,8 @@ import { ensure } from "@/utils/ensure"; -import VerifyPage from "@ente/accounts/pages/verify"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import React, { useContext } from "react"; +import Page_ from "@ente/accounts/pages/verify"; +import { useContext } from "react"; +import { AppContext } from "./_app"; -const Page: React.FC = () => { - const appContext = ensure(useContext(AppContext)); - return ; -}; +const Page = () => ; export default Page; From e836ada0d6c28294deb7c8798b53e3c4a156cd76 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 20:01:23 +0530 Subject: [PATCH 21/28] Refactor --- web/apps/photos/src/pages/change-email.tsx | 8 ++++++++ web/apps/photos/src/pages/change-email/index.tsx | 9 --------- web/apps/photos/src/pages/change-password.tsx | 8 ++++++++ web/apps/photos/src/pages/change-password/index.tsx | 9 --------- web/apps/photos/src/pages/credentials.tsx | 8 ++++++++ web/apps/photos/src/pages/credentials/index.tsx | 9 --------- web/apps/photos/src/pages/generate.tsx | 8 ++++++++ web/apps/photos/src/pages/generate/index.tsx | 9 --------- web/apps/photos/src/pages/login.tsx | 8 ++++++++ web/apps/photos/src/pages/login/index.tsx | 9 --------- web/apps/photos/src/pages/passkeys/finish.tsx | 3 +++ web/apps/photos/src/pages/passkeys/finish/index.tsx | 11 ----------- web/apps/photos/src/pages/recover.tsx | 8 ++++++++ web/apps/photos/src/pages/recover/index.tsx | 10 ---------- web/apps/photos/src/pages/signup.tsx | 8 ++++++++ web/apps/photos/src/pages/signup/index.tsx | 9 --------- web/apps/photos/src/pages/two-factor/recover.tsx | 8 ++++++++ .../photos/src/pages/two-factor/recover/index.tsx | 11 ----------- web/apps/photos/src/pages/two-factor/setup.tsx | 8 ++++++++ web/apps/photos/src/pages/two-factor/setup/index.tsx | 9 --------- web/apps/photos/src/pages/two-factor/verify.tsx | 8 ++++++++ web/apps/photos/src/pages/two-factor/verify/index.tsx | 11 ----------- web/apps/photos/src/pages/verify.tsx | 8 ++++++++ web/apps/photos/src/pages/verify/index.tsx | 9 --------- 24 files changed, 91 insertions(+), 115 deletions(-) create mode 100644 web/apps/photos/src/pages/change-email.tsx delete mode 100644 web/apps/photos/src/pages/change-email/index.tsx create mode 100644 web/apps/photos/src/pages/change-password.tsx delete mode 100644 web/apps/photos/src/pages/change-password/index.tsx create mode 100644 web/apps/photos/src/pages/credentials.tsx delete mode 100644 web/apps/photos/src/pages/credentials/index.tsx create mode 100644 web/apps/photos/src/pages/generate.tsx delete mode 100644 web/apps/photos/src/pages/generate/index.tsx create mode 100644 web/apps/photos/src/pages/login.tsx delete mode 100644 web/apps/photos/src/pages/login/index.tsx create mode 100644 web/apps/photos/src/pages/passkeys/finish.tsx delete mode 100644 web/apps/photos/src/pages/passkeys/finish/index.tsx create mode 100644 web/apps/photos/src/pages/recover.tsx delete mode 100644 web/apps/photos/src/pages/recover/index.tsx create mode 100644 web/apps/photos/src/pages/signup.tsx delete mode 100644 web/apps/photos/src/pages/signup/index.tsx create mode 100644 web/apps/photos/src/pages/two-factor/recover.tsx delete mode 100644 web/apps/photos/src/pages/two-factor/recover/index.tsx create mode 100644 web/apps/photos/src/pages/two-factor/setup.tsx delete mode 100644 web/apps/photos/src/pages/two-factor/setup/index.tsx create mode 100644 web/apps/photos/src/pages/two-factor/verify.tsx delete mode 100644 web/apps/photos/src/pages/two-factor/verify/index.tsx create mode 100644 web/apps/photos/src/pages/verify.tsx delete mode 100644 web/apps/photos/src/pages/verify/index.tsx diff --git a/web/apps/photos/src/pages/change-email.tsx b/web/apps/photos/src/pages/change-email.tsx new file mode 100644 index 000000000..451c5ebfe --- /dev/null +++ b/web/apps/photos/src/pages/change-email.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/change-email"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/change-email/index.tsx b/web/apps/photos/src/pages/change-email/index.tsx deleted file mode 100644 index 6225f053c..000000000 --- a/web/apps/photos/src/pages/change-email/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import ChangeEmailPage from "@ente/accounts/pages/change-email"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function ChangeEmail() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/change-password.tsx b/web/apps/photos/src/pages/change-password.tsx new file mode 100644 index 000000000..ba8e1ac3d --- /dev/null +++ b/web/apps/photos/src/pages/change-password.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/change-password"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/change-password/index.tsx b/web/apps/photos/src/pages/change-password/index.tsx deleted file mode 100644 index 8d8121d6a..000000000 --- a/web/apps/photos/src/pages/change-password/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import ChangePasswordPage from "@ente/accounts/pages/change-password"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function ChangePassword() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/credentials.tsx b/web/apps/photos/src/pages/credentials.tsx new file mode 100644 index 000000000..7d21b33ac --- /dev/null +++ b/web/apps/photos/src/pages/credentials.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/credentials"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/credentials/index.tsx b/web/apps/photos/src/pages/credentials/index.tsx deleted file mode 100644 index 776b2064b..000000000 --- a/web/apps/photos/src/pages/credentials/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import CredentialPage from "@ente/accounts/pages/credentials"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Credential() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/generate.tsx b/web/apps/photos/src/pages/generate.tsx new file mode 100644 index 000000000..718172d49 --- /dev/null +++ b/web/apps/photos/src/pages/generate.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/generate"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/generate/index.tsx b/web/apps/photos/src/pages/generate/index.tsx deleted file mode 100644 index 5d62c93bc..000000000 --- a/web/apps/photos/src/pages/generate/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import GeneratePage from "@ente/accounts/pages/generate"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Generate() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/login.tsx b/web/apps/photos/src/pages/login.tsx new file mode 100644 index 000000000..b40b9f914 --- /dev/null +++ b/web/apps/photos/src/pages/login.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/login"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/login/index.tsx b/web/apps/photos/src/pages/login/index.tsx deleted file mode 100644 index 84539e2f3..000000000 --- a/web/apps/photos/src/pages/login/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import LoginPage from "@ente/accounts/pages/login"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Login() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/passkeys/finish.tsx b/web/apps/photos/src/pages/passkeys/finish.tsx new file mode 100644 index 000000000..866dcf9e3 --- /dev/null +++ b/web/apps/photos/src/pages/passkeys/finish.tsx @@ -0,0 +1,3 @@ +import Page from "@ente/accounts/pages/passkeys/finish"; + +export default Page; diff --git a/web/apps/photos/src/pages/passkeys/finish/index.tsx b/web/apps/photos/src/pages/passkeys/finish/index.tsx deleted file mode 100644 index 289f351de..000000000 --- a/web/apps/photos/src/pages/passkeys/finish/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import PasskeysFinishPage from "@ente/accounts/pages/passkeys/finish"; - -const PasskeysFinish = () => { - return ( - <> - - - ); -}; - -export default PasskeysFinish; diff --git a/web/apps/photos/src/pages/recover.tsx b/web/apps/photos/src/pages/recover.tsx new file mode 100644 index 000000000..cc6d8da82 --- /dev/null +++ b/web/apps/photos/src/pages/recover.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/recover"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/recover/index.tsx b/web/apps/photos/src/pages/recover/index.tsx deleted file mode 100644 index 06d755f7e..000000000 --- a/web/apps/photos/src/pages/recover/index.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import RecoverPage from "@ente/accounts/pages/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Recover() { - const appContext = useContext(AppContext); - - return ; -} diff --git a/web/apps/photos/src/pages/signup.tsx b/web/apps/photos/src/pages/signup.tsx new file mode 100644 index 000000000..8cc5202a8 --- /dev/null +++ b/web/apps/photos/src/pages/signup.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/signup"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/signup/index.tsx b/web/apps/photos/src/pages/signup/index.tsx deleted file mode 100644 index 29b139f86..000000000 --- a/web/apps/photos/src/pages/signup/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import SignupPage from "@ente/accounts/pages/signup"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Sigup() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/two-factor/recover.tsx b/web/apps/photos/src/pages/two-factor/recover.tsx new file mode 100644 index 000000000..aa9c6faf9 --- /dev/null +++ b/web/apps/photos/src/pages/two-factor/recover.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/two-factor/recover"; +import { useContext } from "react"; +import { AppContext } from "../_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/two-factor/recover/index.tsx b/web/apps/photos/src/pages/two-factor/recover/index.tsx deleted file mode 100644 index f3f820d6e..000000000 --- a/web/apps/photos/src/pages/two-factor/recover/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import TwoFactorRecoverPage from "@ente/accounts/pages/two-factor/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function TwoFactorRecover() { - const appContext = useContext(AppContext); - return ( - - ); -} diff --git a/web/apps/photos/src/pages/two-factor/setup.tsx b/web/apps/photos/src/pages/two-factor/setup.tsx new file mode 100644 index 000000000..35a24149f --- /dev/null +++ b/web/apps/photos/src/pages/two-factor/setup.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/two-factor/setup"; +import { useContext } from "react"; +import { AppContext } from "../_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/two-factor/setup/index.tsx b/web/apps/photos/src/pages/two-factor/setup/index.tsx deleted file mode 100644 index 2830560e9..000000000 --- a/web/apps/photos/src/pages/two-factor/setup/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import TwoFactorSetupPage from "@ente/accounts/pages/two-factor/setup"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function TwoFactorSetup() { - const appContext = useContext(AppContext); - return ; -} diff --git a/web/apps/photos/src/pages/two-factor/verify.tsx b/web/apps/photos/src/pages/two-factor/verify.tsx new file mode 100644 index 000000000..3f4ed7e39 --- /dev/null +++ b/web/apps/photos/src/pages/two-factor/verify.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/two-factor/verify"; +import { useContext } from "react"; +import { AppContext } from "../_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/two-factor/verify/index.tsx b/web/apps/photos/src/pages/two-factor/verify/index.tsx deleted file mode 100644 index 65914dcdf..000000000 --- a/web/apps/photos/src/pages/two-factor/verify/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import TwoFactorVerifyPage from "@ente/accounts/pages/two-factor/verify"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function TwoFactorVerify() { - const appContext = useContext(AppContext); - return ( - - ); -} diff --git a/web/apps/photos/src/pages/verify.tsx b/web/apps/photos/src/pages/verify.tsx new file mode 100644 index 000000000..5fb2ed10d --- /dev/null +++ b/web/apps/photos/src/pages/verify.tsx @@ -0,0 +1,8 @@ +import { ensure } from "@/utils/ensure"; +import Page_ from "@ente/accounts/pages/verify"; +import { useContext } from "react"; +import { AppContext } from "./_app"; + +const Page = () => ; + +export default Page; diff --git a/web/apps/photos/src/pages/verify/index.tsx b/web/apps/photos/src/pages/verify/index.tsx deleted file mode 100644 index 081ea9e5e..000000000 --- a/web/apps/photos/src/pages/verify/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import VerifyPage from "@ente/accounts/pages/verify"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; - -export default function Verify() { - const appContext = useContext(AppContext); - return ; -} From e95cba0ace7a2a0c6488efd79895550003dc656c Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 20:21:30 +0530 Subject: [PATCH 22/28] Reduce boilerplate --- web/apps/photos/src/pages/_app.tsx | 6 +++++- web/apps/photos/src/pages/change-email.tsx | 6 ++---- web/apps/photos/src/pages/change-password.tsx | 6 ++---- web/apps/photos/src/pages/credentials.tsx | 6 ++---- web/apps/photos/src/pages/generate.tsx | 6 ++---- web/apps/photos/src/pages/login.tsx | 6 ++---- web/apps/photos/src/pages/recover.tsx | 6 ++---- web/apps/photos/src/pages/signup.tsx | 6 ++---- web/apps/photos/src/pages/two-factor/recover.tsx | 6 ++---- web/apps/photos/src/pages/two-factor/setup.tsx | 6 ++---- web/apps/photos/src/pages/two-factor/verify.tsx | 6 ++---- web/apps/photos/src/pages/verify.tsx | 6 ++---- 12 files changed, 27 insertions(+), 45 deletions(-) diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx index 521a6fc3e..a816d0b46 100644 --- a/web/apps/photos/src/pages/_app.tsx +++ b/web/apps/photos/src/pages/_app.tsx @@ -7,6 +7,7 @@ import { } from "@/next/log-web"; import type { AppName, BaseAppContextT } from "@/next/types/app"; import { AppUpdate } from "@/next/types/ipc"; +import { ensure } from "@/utils/ensure"; import { APPS, APP_TITLES, @@ -45,7 +46,7 @@ import isElectron from "is-electron"; import type { AppProps } from "next/app"; import { useRouter } from "next/router"; import "photoswipe/dist/photoswipe.css"; -import { createContext, useEffect, useRef, useState } from "react"; +import { createContext, useContext, useEffect, useRef, useState } from "react"; import LoadingBar from "react-top-loading-bar"; import DownloadManager from "services/download"; import { resumeExportsIfNeeded } from "services/export"; @@ -103,6 +104,9 @@ type AppContextT = BaseAppContextT & { /** The React {@link Context} available to all pages. */ export const AppContext = createContext(undefined); +/** Utility hook to reduce amount of boilerplate in account related pages. */ +export const useAppContext = () => ensure(useContext(AppContext)); + export default function App({ Component, pageProps }: AppProps) { const appName: AppName = "photos"; diff --git a/web/apps/photos/src/pages/change-email.tsx b/web/apps/photos/src/pages/change-email.tsx index 451c5ebfe..89a765fbf 100644 --- a/web/apps/photos/src/pages/change-email.tsx +++ b/web/apps/photos/src/pages/change-email.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/change-email"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/change-password.tsx b/web/apps/photos/src/pages/change-password.tsx index ba8e1ac3d..ed82edd92 100644 --- a/web/apps/photos/src/pages/change-password.tsx +++ b/web/apps/photos/src/pages/change-password.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/change-password"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/credentials.tsx b/web/apps/photos/src/pages/credentials.tsx index 7d21b33ac..070aace4a 100644 --- a/web/apps/photos/src/pages/credentials.tsx +++ b/web/apps/photos/src/pages/credentials.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/credentials"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/generate.tsx b/web/apps/photos/src/pages/generate.tsx index 718172d49..c6804255a 100644 --- a/web/apps/photos/src/pages/generate.tsx +++ b/web/apps/photos/src/pages/generate.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/generate"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/login.tsx b/web/apps/photos/src/pages/login.tsx index b40b9f914..1a7de0497 100644 --- a/web/apps/photos/src/pages/login.tsx +++ b/web/apps/photos/src/pages/login.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/login"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/recover.tsx b/web/apps/photos/src/pages/recover.tsx index cc6d8da82..d825729e5 100644 --- a/web/apps/photos/src/pages/recover.tsx +++ b/web/apps/photos/src/pages/recover.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/recover"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/signup.tsx b/web/apps/photos/src/pages/signup.tsx index 8cc5202a8..403d3e735 100644 --- a/web/apps/photos/src/pages/signup.tsx +++ b/web/apps/photos/src/pages/signup.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/signup"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/two-factor/recover.tsx b/web/apps/photos/src/pages/two-factor/recover.tsx index aa9c6faf9..d3f40be49 100644 --- a/web/apps/photos/src/pages/two-factor/recover.tsx +++ b/web/apps/photos/src/pages/two-factor/recover.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/recover"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/two-factor/setup.tsx b/web/apps/photos/src/pages/two-factor/setup.tsx index 35a24149f..12716e2df 100644 --- a/web/apps/photos/src/pages/two-factor/setup.tsx +++ b/web/apps/photos/src/pages/two-factor/setup.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/setup"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/two-factor/verify.tsx b/web/apps/photos/src/pages/two-factor/verify.tsx index 3f4ed7e39..7c682b1b9 100644 --- a/web/apps/photos/src/pages/two-factor/verify.tsx +++ b/web/apps/photos/src/pages/two-factor/verify.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/verify"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/photos/src/pages/verify.tsx b/web/apps/photos/src/pages/verify.tsx index 5fb2ed10d..bb2dc8778 100644 --- a/web/apps/photos/src/pages/verify.tsx +++ b/web/apps/photos/src/pages/verify.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/verify"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; From 71a8049a35bda9b71ea65d4cdfffa5152e7e865f Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 20:26:57 +0530 Subject: [PATCH 23/28] reduce accounts --- web/apps/accounts/src/pages/_app.tsx | 6 +++++- web/apps/accounts/src/pages/credentials.tsx | 6 ++---- web/apps/accounts/src/pages/generate.tsx | 6 ++---- web/apps/accounts/src/pages/login.tsx | 6 ++---- web/apps/accounts/src/pages/recover.tsx | 6 ++---- web/apps/accounts/src/pages/signup.tsx | 6 ++---- web/apps/accounts/src/pages/two-factor/recover.tsx | 6 ++---- web/apps/accounts/src/pages/two-factor/setup.tsx | 6 ++---- web/apps/accounts/src/pages/two-factor/verify.tsx | 6 ++---- web/apps/accounts/src/pages/verify.tsx | 6 ++---- 10 files changed, 23 insertions(+), 37 deletions(-) diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsx index 8cf45b741..6fc0936ea 100644 --- a/web/apps/accounts/src/pages/_app.tsx +++ b/web/apps/accounts/src/pages/_app.tsx @@ -2,6 +2,7 @@ import { CustomHead } from "@/next/components/Head"; import { setupI18n } from "@/next/i18n"; import { logUnhandledErrorsAndRejections } from "@/next/log-web"; import type { AppName, BaseAppContextT } from "@/next/types/app"; +import { ensure } from "@/utils/ensure"; import { PAGES } from "@ente/accounts/constants/pages"; import { accountLogout } from "@ente/accounts/services/logout"; import { APPS, APP_TITLES } from "@ente/shared/apps/constants"; @@ -20,7 +21,7 @@ import { ThemeProvider } from "@mui/material/styles"; import { t } from "i18next"; import { AppProps } from "next/app"; import { useRouter } from "next/router"; -import { createContext, useEffect, useState } from "react"; +import { createContext, useContext, useEffect, useState } from "react"; import "styles/global.css"; /** The accounts app has no extra properties on top of the base context. */ @@ -29,6 +30,9 @@ type AppContextT = BaseAppContextT; /** The React {@link Context} available to all pages. */ export const AppContext = createContext(undefined); +/** Utility hook to reduce amount of boilerplate in account related pages. */ +export const useAppContext = () => ensure(useContext(AppContext)); + export default function App({ Component, pageProps }: AppProps) { const appName: AppName = "account"; diff --git a/web/apps/accounts/src/pages/credentials.tsx b/web/apps/accounts/src/pages/credentials.tsx index 7d21b33ac..070aace4a 100644 --- a/web/apps/accounts/src/pages/credentials.tsx +++ b/web/apps/accounts/src/pages/credentials.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/credentials"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/generate.tsx b/web/apps/accounts/src/pages/generate.tsx index 718172d49..c6804255a 100644 --- a/web/apps/accounts/src/pages/generate.tsx +++ b/web/apps/accounts/src/pages/generate.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/generate"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/login.tsx b/web/apps/accounts/src/pages/login.tsx index b40b9f914..1a7de0497 100644 --- a/web/apps/accounts/src/pages/login.tsx +++ b/web/apps/accounts/src/pages/login.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/login"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/recover.tsx b/web/apps/accounts/src/pages/recover.tsx index cc6d8da82..d825729e5 100644 --- a/web/apps/accounts/src/pages/recover.tsx +++ b/web/apps/accounts/src/pages/recover.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/recover"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/signup.tsx b/web/apps/accounts/src/pages/signup.tsx index 8cc5202a8..403d3e735 100644 --- a/web/apps/accounts/src/pages/signup.tsx +++ b/web/apps/accounts/src/pages/signup.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/signup"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/recover.tsx b/web/apps/accounts/src/pages/two-factor/recover.tsx index aa9c6faf9..d3f40be49 100644 --- a/web/apps/accounts/src/pages/two-factor/recover.tsx +++ b/web/apps/accounts/src/pages/two-factor/recover.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/recover"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/setup.tsx b/web/apps/accounts/src/pages/two-factor/setup.tsx index 35a24149f..12716e2df 100644 --- a/web/apps/accounts/src/pages/two-factor/setup.tsx +++ b/web/apps/accounts/src/pages/two-factor/setup.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/setup"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/verify.tsx b/web/apps/accounts/src/pages/two-factor/verify.tsx index 3f4ed7e39..7c682b1b9 100644 --- a/web/apps/accounts/src/pages/two-factor/verify.tsx +++ b/web/apps/accounts/src/pages/two-factor/verify.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/verify"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/verify.tsx b/web/apps/accounts/src/pages/verify.tsx index 5fb2ed10d..bb2dc8778 100644 --- a/web/apps/accounts/src/pages/verify.tsx +++ b/web/apps/accounts/src/pages/verify.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/verify"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; From b28f6c3d8c301fa476dac8b21f4339814a060ee4 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 20:29:53 +0530 Subject: [PATCH 24/28] reduce auth --- web/apps/auth/src/pages/_app.tsx | 6 +++++- web/apps/auth/src/pages/change-email.tsx | 6 ++---- web/apps/auth/src/pages/change-password.tsx | 6 ++---- web/apps/auth/src/pages/credentials.tsx | 6 ++---- web/apps/auth/src/pages/generate.tsx | 6 ++---- web/apps/auth/src/pages/login.tsx | 6 ++---- web/apps/auth/src/pages/recover.tsx | 6 ++---- web/apps/auth/src/pages/signup.tsx | 6 ++---- web/apps/auth/src/pages/two-factor/recover.tsx | 6 ++---- web/apps/auth/src/pages/two-factor/setup.tsx | 6 ++---- web/apps/auth/src/pages/two-factor/verify.tsx | 6 ++---- web/apps/auth/src/pages/verify.tsx | 6 ++---- 12 files changed, 27 insertions(+), 45 deletions(-) diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx index 6aa1246d3..0ada75c3f 100644 --- a/web/apps/auth/src/pages/_app.tsx +++ b/web/apps/auth/src/pages/_app.tsx @@ -5,6 +5,7 @@ import { logUnhandledErrorsAndRejections, } from "@/next/log-web"; import type { AppName, BaseAppContextT } from "@/next/types/app"; +import { ensure } from "@/utils/ensure"; import { accountLogout } from "@ente/accounts/services/logout"; import { APPS, @@ -29,7 +30,7 @@ import { ThemeProvider } from "@mui/material/styles"; import { t } from "i18next"; import type { AppProps } from "next/app"; import { useRouter } from "next/router"; -import { createContext, useEffect, useRef, useState } from "react"; +import { createContext, useContext, useEffect, useRef, useState } from "react"; import LoadingBar, { type LoadingBarRef } from "react-top-loading-bar"; import "../../public/css/global.css"; @@ -47,6 +48,9 @@ type AppContextT = BaseAppContextT & { /** The React {@link Context} available to all pages. */ export const AppContext = createContext(undefined); +/** Utility hook to reduce amount of boilerplate in account related pages. */ +export const useAppContext = () => ensure(useContext(AppContext)); + export default function App({ Component, pageProps }: AppProps) { const appName: AppName = "auth"; diff --git a/web/apps/auth/src/pages/change-email.tsx b/web/apps/auth/src/pages/change-email.tsx index 451c5ebfe..89a765fbf 100644 --- a/web/apps/auth/src/pages/change-email.tsx +++ b/web/apps/auth/src/pages/change-email.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/change-email"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/change-password.tsx b/web/apps/auth/src/pages/change-password.tsx index ba8e1ac3d..ed82edd92 100644 --- a/web/apps/auth/src/pages/change-password.tsx +++ b/web/apps/auth/src/pages/change-password.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/change-password"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/credentials.tsx b/web/apps/auth/src/pages/credentials.tsx index 7d21b33ac..070aace4a 100644 --- a/web/apps/auth/src/pages/credentials.tsx +++ b/web/apps/auth/src/pages/credentials.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/credentials"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/generate.tsx b/web/apps/auth/src/pages/generate.tsx index 718172d49..c6804255a 100644 --- a/web/apps/auth/src/pages/generate.tsx +++ b/web/apps/auth/src/pages/generate.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/generate"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/login.tsx b/web/apps/auth/src/pages/login.tsx index b40b9f914..1a7de0497 100644 --- a/web/apps/auth/src/pages/login.tsx +++ b/web/apps/auth/src/pages/login.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/login"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/recover.tsx b/web/apps/auth/src/pages/recover.tsx index cc6d8da82..d825729e5 100644 --- a/web/apps/auth/src/pages/recover.tsx +++ b/web/apps/auth/src/pages/recover.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/recover"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/signup.tsx b/web/apps/auth/src/pages/signup.tsx index 8cc5202a8..403d3e735 100644 --- a/web/apps/auth/src/pages/signup.tsx +++ b/web/apps/auth/src/pages/signup.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/signup"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/two-factor/recover.tsx b/web/apps/auth/src/pages/two-factor/recover.tsx index aa9c6faf9..d3f40be49 100644 --- a/web/apps/auth/src/pages/two-factor/recover.tsx +++ b/web/apps/auth/src/pages/two-factor/recover.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/recover"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/two-factor/setup.tsx b/web/apps/auth/src/pages/two-factor/setup.tsx index 35a24149f..12716e2df 100644 --- a/web/apps/auth/src/pages/two-factor/setup.tsx +++ b/web/apps/auth/src/pages/two-factor/setup.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/setup"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/two-factor/verify.tsx b/web/apps/auth/src/pages/two-factor/verify.tsx index 3f4ed7e39..7c682b1b9 100644 --- a/web/apps/auth/src/pages/two-factor/verify.tsx +++ b/web/apps/auth/src/pages/two-factor/verify.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/two-factor/verify"; -import { useContext } from "react"; -import { AppContext } from "../_app"; +import { useAppContext } from "../_app"; -const Page = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/auth/src/pages/verify.tsx b/web/apps/auth/src/pages/verify.tsx index 5fb2ed10d..bb2dc8778 100644 --- a/web/apps/auth/src/pages/verify.tsx +++ b/web/apps/auth/src/pages/verify.tsx @@ -1,8 +1,6 @@ -import { ensure } from "@/utils/ensure"; import Page_ from "@ente/accounts/pages/verify"; -import { useContext } from "react"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; -const Page = () => ; +const Page = () => ; export default Page; From 7d497b5ae13f08840ec7278d41274883872a566b Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 20:40:48 +0530 Subject: [PATCH 25/28] Revert reimportability --- web/apps/photos/src/pages/index.tsx | 4 +- web/packages/accounts/components/Login.tsx | 75 +++++ web/packages/accounts/components/SignUp.tsx | 320 ++++++++++++++++++++ web/packages/accounts/pages/login.tsx | 75 +---- web/packages/accounts/pages/signup.tsx | 317 +------------------ 5 files changed, 400 insertions(+), 391 deletions(-) create mode 100644 web/packages/accounts/components/Login.tsx create mode 100644 web/packages/accounts/components/SignUp.tsx diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsx index 492785c91..907f37d3d 100644 --- a/web/apps/photos/src/pages/index.tsx +++ b/web/apps/photos/src/pages/index.tsx @@ -1,6 +1,6 @@ import log from "@/next/log"; -import Login from "@ente/accounts/components/Login"; -import SignUp from "@ente/accounts/components/SignUp"; +import { Login } from "@ente/accounts/components/Login"; +import { SignUp } from "@ente/accounts/components/SignUp"; import { APPS } from "@ente/shared/apps/constants"; import { EnteLogo } from "@ente/shared/components/EnteLogo"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; diff --git a/web/packages/accounts/components/Login.tsx b/web/packages/accounts/components/Login.tsx new file mode 100644 index 000000000..6ddbe1491 --- /dev/null +++ b/web/packages/accounts/components/Login.tsx @@ -0,0 +1,75 @@ +import log from "@/next/log"; +import { appNameToAppNameOld } from "@ente/shared/apps/constants"; +import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; +import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; +import LinkButton from "@ente/shared/components/LinkButton"; +import SingleInputForm, { + type SingleInputFormProps, +} from "@ente/shared/components/SingleInputForm"; +import { LS_KEYS, setData } from "@ente/shared/storage/localStorage"; +import { Input } from "@mui/material"; +import { t } from "i18next"; +import { useRouter } from "next/router"; +import type { AppName } from "packages/next/types/app"; +import { getSRPAttributes } from "../api/srp"; +import { sendOtt } from "../api/user"; +import { PAGES } from "../constants/pages"; + +interface LoginProps { + signUp: () => void; + appName: AppName; +} + +export function Login(props: LoginProps) { + const appNameOld = appNameToAppNameOld(props.appName); + + const router = useRouter(); + + const loginUser: SingleInputFormProps["callback"] = async ( + email, + setFieldError, + ) => { + try { + setData(LS_KEYS.USER, { email }); + const srpAttributes = await getSRPAttributes(email); + log.debug(() => ` srpAttributes: ${JSON.stringify(srpAttributes)}`); + if (!srpAttributes || srpAttributes.isEmailMFAEnabled) { + await sendOtt(appNameOld, email); + router.push(PAGES.VERIFY); + } else { + setData(LS_KEYS.SRP_ATTRIBUTES, srpAttributes); + router.push(PAGES.CREDENTIALS); + } + } catch (e) { + if (e instanceof Error) { + setFieldError(`${t("UNKNOWN_ERROR")} (reason:${e.message})`); + } else { + setFieldError( + `${t("UNKNOWN_ERROR")} (reason:${JSON.stringify(e)})`, + ); + } + } + }; + + return ( + <> + {t("LOGIN")} + + } + /> + + + + {t("NO_ACCOUNT")} + + + + ); +} diff --git a/web/packages/accounts/components/SignUp.tsx b/web/packages/accounts/components/SignUp.tsx new file mode 100644 index 000000000..6c89eb8fb --- /dev/null +++ b/web/packages/accounts/components/SignUp.tsx @@ -0,0 +1,320 @@ +import log from "@/next/log"; +import { sendOtt } from "@ente/accounts/api/user"; +import { PasswordStrengthHint } from "@ente/accounts/components/PasswordStrength"; +import { PAGES } from "@ente/accounts/constants/pages"; +import { isWeakPassword } from "@ente/accounts/utils"; +import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; +import { LS_KEYS } from "@ente/shared//storage/localStorage"; +import { appNameToAppNameOld } from "@ente/shared/apps/constants"; +import { VerticallyCentered } from "@ente/shared/components/Container"; +import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; +import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; +import ShowHidePassword from "@ente/shared/components/Form/ShowHidePassword"; +import LinkButton from "@ente/shared/components/LinkButton"; +import SubmitButton from "@ente/shared/components/SubmitButton"; +import { + generateAndSaveIntermediateKeyAttributes, + saveKeyInSessionStore, +} from "@ente/shared/crypto/helpers"; +import { setData } from "@ente/shared/storage/localStorage"; +import { + setJustSignedUp, + setLocalReferralSource, +} from "@ente/shared/storage/localStorage/helpers"; +import { SESSION_KEYS } from "@ente/shared/storage/sessionStorage"; +import InfoOutlined from "@mui/icons-material/InfoOutlined"; +import { + Box, + Checkbox, + FormControlLabel, + FormGroup, + IconButton, + InputAdornment, + Link, + TextField, + Tooltip, + Typography, +} from "@mui/material"; +import { Formik, type FormikHelpers } from "formik"; +import { t } from "i18next"; +import type { NextRouter } from "next/router"; +import type { AppName } from "packages/next/types/app"; +import React, { useState } from "react"; +import { Trans } from "react-i18next"; +import * as Yup from "yup"; + +interface FormValues { + email: string; + passphrase: string; + confirm: string; + referral: string; +} + +interface SignUpProps { + router: NextRouter; + login: () => void; + appName: AppName; +} + +export function SignUp({ router, appName, login }: SignUpProps) { + const appNameOld = appNameToAppNameOld(appName); + + const [acceptTerms, setAcceptTerms] = useState(false); + const [loading, setLoading] = useState(false); + const [showPassword, setShowPassword] = useState(false); + + const handleClickShowPassword = () => { + setShowPassword(!showPassword); + }; + + const handleMouseDownPassword = ( + event: React.MouseEvent, + ) => { + event.preventDefault(); + }; + + const registerUser = async ( + { email, passphrase, confirm, referral }: FormValues, + { setFieldError }: FormikHelpers, + ) => { + try { + if (passphrase !== confirm) { + setFieldError("confirm", t("PASSPHRASE_MATCH_ERROR")); + return; + } + setLoading(true); + try { + setData(LS_KEYS.USER, { email }); + setLocalReferralSource(referral); + await sendOtt(appNameOld, email); + } catch (e) { + const message = e instanceof Error ? e.message : ""; + setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`); + throw e; + } + try { + const { keyAttributes, masterKey, srpSetupAttributes } = + await generateKeyAndSRPAttributes(passphrase); + + setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); + setData(LS_KEYS.SRP_SETUP_ATTRIBUTES, srpSetupAttributes); + await generateAndSaveIntermediateKeyAttributes( + passphrase, + keyAttributes, + masterKey, + ); + + await saveKeyInSessionStore( + SESSION_KEYS.ENCRYPTION_KEY, + masterKey, + ); + setJustSignedUp(true); + router.push(PAGES.VERIFY); + } catch (e) { + setFieldError("confirm", t("PASSWORD_GENERATION_FAILED")); + throw e; + } + } catch (e) { + log.error("signup failed", e); + } + setLoading(false); + }; + + return ( + <> + {t("SIGN_UP")} + + initialValues={{ + email: "", + passphrase: "", + confirm: "", + referral: "", + }} + validationSchema={Yup.object().shape({ + email: Yup.string() + .email(t("EMAIL_ERROR")) + .required(t("REQUIRED")), + passphrase: Yup.string().required(t("REQUIRED")), + confirm: Yup.string().required(t("REQUIRED")), + })} + validateOnChange={false} + validateOnBlur={false} + onSubmit={registerUser} + > + {({ + values, + errors, + handleChange, + handleSubmit, + }): JSX.Element => ( +
+ + + + + ), + }} + /> + + + + + + + {t("REFERRAL_CODE_HINT")} + + + + + + + + + ), + }} + fullWidth + name="referral" + type="text" + value={values.referral} + onChange={handleChange("referral")} + error={Boolean(errors.referral)} + disabled={loading} + /> + + + + setAcceptTerms(e.target.checked) + } + color="accent" + /> + } + label={ + + + ), + b: ( + + ), + }} + /> + + } + /> + + + + + {loading && ( + + {t("KEY_GENERATION_IN_PROGRESS_MESSAGE")} + + )} + +
+ )} + + + + {t("ACCOUNT_EXISTS")} + + + ); +} diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx index 506cc81bc..57ea023ff 100644 --- a/web/packages/accounts/pages/login.tsx +++ b/web/packages/accounts/pages/login.tsx @@ -1,23 +1,11 @@ -import log from "@/next/log"; -import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; -import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; -import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; -import LinkButton from "@ente/shared/components/LinkButton"; -import SingleInputForm, { - type SingleInputFormProps, -} from "@ente/shared/components/SingleInputForm"; -import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; -import { Input } from "@mui/material"; -import { t } from "i18next"; +import { LS_KEYS, getData } from "@ente/shared/storage/localStorage"; import { useRouter } from "next/router"; -import type { AppName } from "packages/next/types/app"; import React, { useEffect, useState } from "react"; -import { getSRPAttributes } from "../api/srp"; -import { sendOtt } from "../api/user"; +import { Login } from "../components/Login"; import { PAGES } from "../constants/pages"; const Page: React.FC = ({ appContext }) => { @@ -54,62 +42,3 @@ const Page: React.FC = ({ appContext }) => { }; export default Page; - -interface LoginProps { - signUp: () => void; - appName: AppName; -} - -function Login(props: LoginProps) { - const appNameOld = appNameToAppNameOld(props.appName); - - const router = useRouter(); - - const loginUser: SingleInputFormProps["callback"] = async ( - email, - setFieldError, - ) => { - try { - setData(LS_KEYS.USER, { email }); - const srpAttributes = await getSRPAttributes(email); - log.debug(() => ` srpAttributes: ${JSON.stringify(srpAttributes)}`); - if (!srpAttributes || srpAttributes.isEmailMFAEnabled) { - await sendOtt(appNameOld, email); - router.push(PAGES.VERIFY); - } else { - setData(LS_KEYS.SRP_ATTRIBUTES, srpAttributes); - router.push(PAGES.CREDENTIALS); - } - } catch (e) { - if (e instanceof Error) { - setFieldError(`${t("UNKNOWN_ERROR")} (reason:${e.message})`); - } else { - setFieldError( - `${t("UNKNOWN_ERROR")} (reason:${JSON.stringify(e)})`, - ); - } - } - }; - - return ( - <> - {t("LOGIN")} - - } - /> - - - - {t("NO_ACCOUNT")} - - - - ); -} diff --git a/web/packages/accounts/pages/signup.tsx b/web/packages/accounts/pages/signup.tsx index 02f810250..affc0099b 100644 --- a/web/packages/accounts/pages/signup.tsx +++ b/web/packages/accounts/pages/signup.tsx @@ -1,51 +1,12 @@ -import log from "@/next/log"; -import { sendOtt } from "@ente/accounts/api/user"; -import { PasswordStrengthHint } from "@ente/accounts/components/PasswordStrength"; import { PAGES } from "@ente/accounts/constants/pages"; -import { isWeakPassword } from "@ente/accounts/utils"; -import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; import { LS_KEYS, getData } from "@ente/shared//storage/localStorage"; -import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; -import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; -import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; -import ShowHidePassword from "@ente/shared/components/Form/ShowHidePassword"; -import LinkButton from "@ente/shared/components/LinkButton"; -import SubmitButton from "@ente/shared/components/SubmitButton"; -import { - generateAndSaveIntermediateKeyAttributes, - saveKeyInSessionStore, -} from "@ente/shared/crypto/helpers"; -import { setData } from "@ente/shared/storage/localStorage"; -import { - setJustSignedUp, - setLocalReferralSource, -} from "@ente/shared/storage/localStorage/helpers"; -import { SESSION_KEYS } from "@ente/shared/storage/sessionStorage"; -import InfoOutlined from "@mui/icons-material/InfoOutlined"; -import { - Box, - Checkbox, - FormControlLabel, - FormGroup, - IconButton, - InputAdornment, - Link, - TextField, - Tooltip, - Typography, -} from "@mui/material"; -import { Formik, type FormikHelpers } from "formik"; -import { t } from "i18next"; -import type { NextRouter } from "next/router"; import { useRouter } from "next/router"; -import type { AppName } from "packages/next/types/app"; import React, { useEffect, useState } from "react"; -import { Trans } from "react-i18next"; -import * as Yup from "yup"; +import { SignUp } from "../components/SignUp"; const Page: React.FC = ({ appContext }) => { const { appName } = appContext; @@ -81,279 +42,3 @@ const Page: React.FC = ({ appContext }) => { }; export default Page; - -interface FormValues { - email: string; - passphrase: string; - confirm: string; - referral: string; -} - -interface SignUpProps { - router: NextRouter; - login: () => void; - appName: AppName; -} - -function SignUp({ router, appName, login }: SignUpProps) { - const appNameOld = appNameToAppNameOld(appName); - - const [acceptTerms, setAcceptTerms] = useState(false); - const [loading, setLoading] = useState(false); - const [showPassword, setShowPassword] = useState(false); - - const handleClickShowPassword = () => { - setShowPassword(!showPassword); - }; - - const handleMouseDownPassword = ( - event: React.MouseEvent, - ) => { - event.preventDefault(); - }; - - const registerUser = async ( - { email, passphrase, confirm, referral }: FormValues, - { setFieldError }: FormikHelpers, - ) => { - try { - if (passphrase !== confirm) { - setFieldError("confirm", t("PASSPHRASE_MATCH_ERROR")); - return; - } - setLoading(true); - try { - setData(LS_KEYS.USER, { email }); - setLocalReferralSource(referral); - await sendOtt(appNameOld, email); - } catch (e) { - const message = e instanceof Error ? e.message : ""; - setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`); - throw e; - } - try { - const { keyAttributes, masterKey, srpSetupAttributes } = - await generateKeyAndSRPAttributes(passphrase); - - setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); - setData(LS_KEYS.SRP_SETUP_ATTRIBUTES, srpSetupAttributes); - await generateAndSaveIntermediateKeyAttributes( - passphrase, - keyAttributes, - masterKey, - ); - - await saveKeyInSessionStore( - SESSION_KEYS.ENCRYPTION_KEY, - masterKey, - ); - setJustSignedUp(true); - router.push(PAGES.VERIFY); - } catch (e) { - setFieldError("confirm", t("PASSWORD_GENERATION_FAILED")); - throw e; - } - } catch (e) { - log.error("signup failed", e); - } - setLoading(false); - }; - - return ( - <> - {t("SIGN_UP")} - - initialValues={{ - email: "", - passphrase: "", - confirm: "", - referral: "", - }} - validationSchema={Yup.object().shape({ - email: Yup.string() - .email(t("EMAIL_ERROR")) - .required(t("REQUIRED")), - passphrase: Yup.string().required(t("REQUIRED")), - confirm: Yup.string().required(t("REQUIRED")), - })} - validateOnChange={false} - validateOnBlur={false} - onSubmit={registerUser} - > - {({ - values, - errors, - handleChange, - handleSubmit, - }): JSX.Element => ( -
- - - - - ), - }} - /> - - - - - - - {t("REFERRAL_CODE_HINT")} - - - - - - - - - ), - }} - fullWidth - name="referral" - type="text" - value={values.referral} - onChange={handleChange("referral")} - error={Boolean(errors.referral)} - disabled={loading} - /> - - - - setAcceptTerms(e.target.checked) - } - color="accent" - /> - } - label={ - - - ), - b: ( - - ), - }} - /> - - } - /> - - - - - {loading && ( - - {t("KEY_GENERATION_IN_PROGRESS_MESSAGE")} - - )} - -
- )} - - - - {t("ACCOUNT_EXISTS")} - - - ); -} From cbcfc243fcf5bb6e03fae24e5e96221c642c8e72 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 21:01:30 +0530 Subject: [PATCH 26/28] lf --- web/packages/accounts/components/Login.tsx | 2 +- web/packages/accounts/components/SignUp.tsx | 2 +- web/packages/accounts/pages/credentials.tsx | 2 +- web/packages/shared/apps/constants.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/packages/accounts/components/Login.tsx b/web/packages/accounts/components/Login.tsx index 6ddbe1491..297aa28ec 100644 --- a/web/packages/accounts/components/Login.tsx +++ b/web/packages/accounts/components/Login.tsx @@ -1,4 +1,5 @@ import log from "@/next/log"; +import type { AppName } from "@/next/types/app"; import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; @@ -10,7 +11,6 @@ import { LS_KEYS, setData } from "@ente/shared/storage/localStorage"; import { Input } from "@mui/material"; import { t } from "i18next"; import { useRouter } from "next/router"; -import type { AppName } from "packages/next/types/app"; import { getSRPAttributes } from "../api/srp"; import { sendOtt } from "../api/user"; import { PAGES } from "../constants/pages"; diff --git a/web/packages/accounts/components/SignUp.tsx b/web/packages/accounts/components/SignUp.tsx index 6c89eb8fb..044eaa966 100644 --- a/web/packages/accounts/components/SignUp.tsx +++ b/web/packages/accounts/components/SignUp.tsx @@ -1,4 +1,5 @@ import log from "@/next/log"; +import type { AppName } from "@/next/types/app"; import { sendOtt } from "@ente/accounts/api/user"; import { PasswordStrengthHint } from "@ente/accounts/components/PasswordStrength"; import { PAGES } from "@ente/accounts/constants/pages"; @@ -38,7 +39,6 @@ import { import { Formik, type FormikHelpers } from "formik"; import { t } from "i18next"; import type { NextRouter } from "next/router"; -import type { AppName } from "packages/next/types/app"; import React, { useState } from "react"; import { Trans } from "react-i18next"; import * as Yup from "yup"; diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx index 05d846dce..901432b45 100644 --- a/web/packages/accounts/pages/credentials.tsx +++ b/web/packages/accounts/pages/credentials.tsx @@ -295,7 +295,7 @@ const Page: React.FC = ({ appContext }) => { ); -} +}; export default Page; diff --git a/web/packages/shared/apps/constants.ts b/web/packages/shared/apps/constants.ts index f627db073..37e62c93a 100644 --- a/web/packages/shared/apps/constants.ts +++ b/web/packages/shared/apps/constants.ts @@ -1,4 +1,4 @@ -import type { AppName } from "packages/next/types/app"; +import type { AppName } from "@/next/types/app"; import { ACCOUNTS_PAGES, AUTH_PAGES, PHOTOS_PAGES } from "../constants/pages"; export enum APPS { From 8ebd50606a616ddbffe4ed960b3b961958f1f6a7 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 21:31:18 +0530 Subject: [PATCH 27/28] lf --- web/apps/photos/src/pages/index.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsx index 907f37d3d..8abad4397 100644 --- a/web/apps/photos/src/pages/index.tsx +++ b/web/apps/photos/src/pages/index.tsx @@ -1,7 +1,6 @@ import log from "@/next/log"; import { Login } from "@ente/accounts/components/Login"; import { SignUp } from "@ente/accounts/components/SignUp"; -import { APPS } from "@ente/shared/apps/constants"; import { EnteLogo } from "@ente/shared/components/EnteLogo"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages"; @@ -21,18 +20,18 @@ import { t } from "i18next"; import { useRouter } from "next/router"; import { CarouselProvider, DotGroup, Slide, Slider } from "pure-react-carousel"; import "pure-react-carousel/dist/react-carousel.es.css"; -import { useContext, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { Trans } from "react-i18next"; -import { AppContext } from "./_app"; +import { useAppContext } from "./_app"; export default function LandingPage() { + const { appName, showNavBar, setDialogMessage } = useAppContext(); const router = useRouter(); - const appContext = useContext(AppContext); const [loading, setLoading] = useState(true); const [showLogin, setShowLogin] = useState(true); useEffect(() => { - appContext.showNavBar(false); + showNavBar(false); const currentURL = new URL(window.location.href); const albumsURL = new URL(getAlbumsURL()); currentURL.pathname = router.pathname; @@ -90,7 +89,7 @@ export default function LandingPage() { await localForage.ready(); } catch (e) { log.error("usage in incognito mode tried", e); - appContext.setDialogMessage({ + setDialogMessage({ title: t("LOCAL_STORAGE_NOT_ACCESSIBLE"), nonClosable: true, @@ -134,13 +133,9 @@ export default function LandingPage() { {showLogin ? ( - + ) : ( - + )} From 05406333e46bb5ed68fcc049b2d6d0399e31b224 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sun, 26 May 2024 21:52:29 +0530 Subject: [PATCH 28/28] Split types --- .../src/pages/passkeys/flow/Recover.tsx | 24 ++++++++----------- .../photos/src/components/Sidebar/index.tsx | 2 +- web/packages/accounts/pages/change-email.tsx | 2 +- .../accounts/pages/change-password.tsx | 2 +- web/packages/accounts/pages/credentials.tsx | 2 +- web/packages/accounts/pages/generate.tsx | 4 ++-- web/packages/accounts/pages/login.tsx | 2 +- .../accounts/pages/passkeys/finish.tsx | 4 ++-- web/packages/accounts/pages/recover.tsx | 2 +- web/packages/accounts/pages/signup.tsx | 2 +- .../accounts/pages/two-factor/recover.tsx | 11 +++++++-- .../accounts/pages/two-factor/setup.tsx | 2 +- .../accounts/pages/two-factor/verify.tsx | 2 +- web/packages/accounts/pages/verify.tsx | 2 +- web/packages/accounts/types/page.ts | 16 +++++++++++++ web/packages/shared/apps/types.ts | 9 ------- .../shared/components/RecoveryKey/index.tsx | 7 +++--- 17 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 web/packages/accounts/types/page.ts delete mode 100644 web/packages/shared/apps/types.ts diff --git a/web/apps/accounts/src/pages/passkeys/flow/Recover.tsx b/web/apps/accounts/src/pages/passkeys/flow/Recover.tsx index f992e3961..30e1f63af 100644 --- a/web/apps/accounts/src/pages/passkeys/flow/Recover.tsx +++ b/web/apps/accounts/src/pages/passkeys/flow/Recover.tsx @@ -1,16 +1,12 @@ import { TwoFactorType } from "@ente/accounts/constants/twofactor"; -import RecoverPage from "@ente/accounts/pages/recover"; -import { APPS } from "@ente/shared/apps/constants"; -import { AppContext } from "pages/_app"; -import { useContext } from "react"; +import RecoverPage from "@ente/accounts/pages/two-factor/recover"; +import { useAppContext } from "../../_app"; -export default function Recover() { - const appContext = useContext(AppContext); - return ( - - ); -} +const Page = () => ( + +); + +export default Page; diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsx index c01ffe48b..5414d8fe3 100644 --- a/web/apps/photos/src/components/Sidebar/index.tsx +++ b/web/apps/photos/src/components/Sidebar/index.tsx @@ -602,7 +602,7 @@ const UtilitySection: React.FC = ({ closeSidebar }) => { label={t("PREFERENCES")} /> = ({ appContext }) => { const { appName } = appContext; diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsx index b0e6dcb70..2ecd09fd0 100644 --- a/web/packages/accounts/pages/change-password.tsx +++ b/web/packages/accounts/pages/change-password.tsx @@ -14,7 +14,6 @@ import { convertBufferToBase64, } from "@ente/accounts/utils"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; @@ -34,6 +33,7 @@ import type { KEK, KeyAttributes, User } from "@ente/shared/user/types"; import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import type { PageProps } from "../types/page"; const Page: React.FC = ({ appContext }) => { const { appName } = appContext; diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx index 901432b45..85a1b2fe7 100644 --- a/web/packages/accounts/pages/credentials.tsx +++ b/web/packages/accounts/pages/credentials.tsx @@ -2,7 +2,6 @@ import { isDevBuild } from "@/next/env"; import log from "@/next/log"; import { ensure } from "@/utils/ensure"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -51,6 +50,7 @@ import { generateSRPSetupAttributes, loginViaSRP, } from "../services/srp"; +import type { PageProps } from "../types/page"; import type { SRPAttributes } from "../types/srp"; const Page: React.FC = ({ appContext }) => { diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsx index e367813e7..3ce7293f6 100644 --- a/web/packages/accounts/pages/generate.tsx +++ b/web/packages/accounts/pages/generate.tsx @@ -8,7 +8,6 @@ import { PAGES } from "@ente/accounts/constants/pages"; import { configureSRP } from "@ente/accounts/services/srp"; import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -30,6 +29,7 @@ import type { KeyAttributes, User } from "@ente/shared/user/types"; import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import type { PageProps } from "../types/page"; const Page: React.FC = ({ appContext }) => { const { appName, logout } = appContext; @@ -105,7 +105,7 @@ const Page: React.FC = ({ appContext }) => { ) : recoverModalView ? ( { setRecoveryModalView(false); diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx index 57ea023ff..ce9c8915f 100644 --- a/web/packages/accounts/pages/login.tsx +++ b/web/packages/accounts/pages/login.tsx @@ -1,4 +1,3 @@ -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -7,6 +6,7 @@ import { useRouter } from "next/router"; import React, { useEffect, useState } from "react"; import { Login } from "../components/Login"; import { PAGES } from "../constants/pages"; +import type { PageProps } from "../types/page"; const Page: React.FC = ({ appContext }) => { const { appName, showNavBar } = appContext; diff --git a/web/packages/accounts/pages/passkeys/finish.tsx b/web/packages/accounts/pages/passkeys/finish.tsx index 3f8ae8548..b9b5b2cd4 100644 --- a/web/packages/accounts/pages/passkeys/finish.tsx +++ b/web/packages/accounts/pages/passkeys/finish.tsx @@ -4,9 +4,9 @@ import EnteSpinner from "@ente/shared/components/EnteSpinner"; import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore"; import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; import { useRouter } from "next/router"; -import { useEffect } from "react"; +import React, { useEffect } from "react"; -const Page = () => { +const Page: React.FC = () => { const router = useRouter(); const init = async () => { diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsx index a93cf53cc..1e8b99895 100644 --- a/web/packages/accounts/pages/recover.tsx +++ b/web/packages/accounts/pages/recover.tsx @@ -3,7 +3,6 @@ import { ensure } from "@/utils/ensure"; import { sendOtt } from "@ente/accounts/api/user"; import { PAGES } from "@ente/accounts/constants/pages"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; @@ -24,6 +23,7 @@ import type { KeyAttributes, User } from "@ente/shared/user/types"; import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import type { PageProps } from "../types/page"; const bip39 = require("bip39"); // mobile client library only supports english. diff --git a/web/packages/accounts/pages/signup.tsx b/web/packages/accounts/pages/signup.tsx index affc0099b..ce7e14e56 100644 --- a/web/packages/accounts/pages/signup.tsx +++ b/web/packages/accounts/pages/signup.tsx @@ -1,12 +1,12 @@ import { PAGES } from "@ente/accounts/constants/pages"; import { LS_KEYS, getData } from "@ente/shared//storage/localStorage"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; import { useRouter } from "next/router"; import React, { useEffect, useState } from "react"; import { SignUp } from "../components/SignUp"; +import type { PageProps } from "../types/page"; const Page: React.FC = ({ appContext }) => { const { appName } = appContext; diff --git a/web/packages/accounts/pages/two-factor/recover.tsx b/web/packages/accounts/pages/two-factor/recover.tsx index ffad62625..8ea9d7ea3 100644 --- a/web/packages/accounts/pages/two-factor/recover.tsx +++ b/web/packages/accounts/pages/two-factor/recover.tsx @@ -1,9 +1,10 @@ import log from "@/next/log"; +import type { BaseAppContextT } from "@/next/types/app"; import { ensure } from "@/utils/ensure"; import { recoverTwoFactor, removeTwoFactor } from "@ente/accounts/api/user"; import { PAGES } from "@ente/accounts/constants/pages"; import { TwoFactorType } from "@ente/accounts/constants/twofactor"; -import type { PageProps } from "@ente/shared/apps/types"; +import { APPS } from "@ente/shared/apps/constants"; import { VerticallyCentered } from "@ente/shared/components/Container"; import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -29,7 +30,13 @@ const bip39 = require("bip39"); // mobile client library only supports english. bip39.setDefaultWordlist("english"); -const Page: React.FC = ({ +export interface RecoverPageProps { + appContext: BaseAppContextT; + appName?: APPS; + twoFactorType?: TwoFactorType; +} + +const Page: React.FC = ({ appContext, twoFactorType = TwoFactorType.TOTP, }) => { diff --git a/web/packages/accounts/pages/two-factor/setup.tsx b/web/packages/accounts/pages/two-factor/setup.tsx index 193bfb60f..98887fcf0 100644 --- a/web/packages/accounts/pages/two-factor/setup.tsx +++ b/web/packages/accounts/pages/two-factor/setup.tsx @@ -7,7 +7,6 @@ import VerifyTwoFactor, { import { TwoFactorSetup } from "@ente/accounts/components/two-factor/setup"; import type { TwoFactorSecret } from "@ente/accounts/types/user"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import LinkButton from "@ente/shared/components/LinkButton"; import { encryptWithRecoveryKey } from "@ente/shared/crypto/helpers"; @@ -17,6 +16,7 @@ import Card from "@mui/material/Card"; import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import type { PageProps } from "../../types/page"; export enum SetupMode { QR_CODE, diff --git a/web/packages/accounts/pages/two-factor/verify.tsx b/web/packages/accounts/pages/two-factor/verify.tsx index 322b25ffc..cd2cbf4b7 100644 --- a/web/packages/accounts/pages/two-factor/verify.tsx +++ b/web/packages/accounts/pages/two-factor/verify.tsx @@ -4,7 +4,6 @@ import VerifyTwoFactor, { type VerifyTwoFactorCallback, } from "@ente/accounts/components/two-factor/VerifyForm"; import { PAGES } from "@ente/accounts/constants/pages"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; @@ -18,6 +17,7 @@ import { HttpStatusCode } from "axios"; import { t } from "i18next"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import type { PageProps } from "../../types/page"; const Page: React.FC = ({ appContext }) => { const { logout } = appContext; diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx index 025b39961..01e6e5884 100644 --- a/web/packages/accounts/pages/verify.tsx +++ b/web/packages/accounts/pages/verify.tsx @@ -1,7 +1,6 @@ import { ensure } from "@/utils/ensure"; import type { UserVerificationResponse } from "@ente/accounts/types/user"; import { appNameToAppNameOld } from "@ente/shared/apps/constants"; -import type { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; import FormPaper from "@ente/shared/components/Form/FormPaper"; @@ -31,6 +30,7 @@ import { Trans } from "react-i18next"; import { putAttributes, sendOtt, verifyOtt } from "../api/user"; import { PAGES } from "../constants/pages"; import { configureSRP } from "../services/srp"; +import type { PageProps } from "../types/page"; import type { SRPSetupAttributes } from "../types/srp"; const Page: React.FC = ({ appContext }) => { diff --git a/web/packages/accounts/types/page.ts b/web/packages/accounts/types/page.ts new file mode 100644 index 000000000..490967ae3 --- /dev/null +++ b/web/packages/accounts/types/page.ts @@ -0,0 +1,16 @@ +import type { BaseAppContextT } from "@/next/types/app"; + +/** + * The default type for pages exposed by this package. + * + * Some specific pages might extend this further (e.g. the two-factor/recover). + */ +export interface PageProps { + /** + * The common denominator AppContext. + * + * Within this package we do not have access to the context object declared + * with the app's code, so we need to take the context as a parameter. + */ + appContext: BaseAppContextT; +} diff --git a/web/packages/shared/apps/types.ts b/web/packages/shared/apps/types.ts deleted file mode 100644 index 54424f146..000000000 --- a/web/packages/shared/apps/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { BaseAppContextT } from "@/next/types/app"; -import { TwoFactorType } from "@ente/accounts/constants/twofactor"; -import { APPS } from "./constants"; - -export interface PageProps { - appContext: BaseAppContextT; - appName?: APPS; - twoFactorType?: TwoFactorType; -} diff --git a/web/packages/shared/components/RecoveryKey/index.tsx b/web/packages/shared/components/RecoveryKey/index.tsx index b9534e0a2..5bd261960 100644 --- a/web/packages/shared/components/RecoveryKey/index.tsx +++ b/web/packages/shared/components/RecoveryKey/index.tsx @@ -1,5 +1,4 @@ import { ensure } from "@/utils/ensure"; -import type { PageProps } from "@ente/shared/apps/types"; import CodeBlock from "@ente/shared/components/CodeBlock"; import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton"; import { getRecoveryKey } from "@ente/shared/crypto/helpers"; @@ -22,13 +21,13 @@ bip39.setDefaultWordlist("english"); const RECOVERY_KEY_FILE_NAME = "ente-recovery-key.txt"; interface Props { - appContext: PageProps["appContext"]; + isMobile: boolean; show: boolean; onHide: () => void; somethingWentWrong: any; } -function RecoveryKey({ somethingWentWrong, appContext, ...props }: Props) { +function RecoveryKey({ somethingWentWrong, isMobile, ...props }: Props) { const [recoveryKey, setRecoveryKey] = useState(null); useEffect(() => { @@ -54,7 +53,7 @@ function RecoveryKey({ somethingWentWrong, appContext, ...props }: Props) { return (