Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

update(photos):2fa-choice-screen-updated

Aswin Asok4108c685c1c0
diff --git a/web/apps/photos/src/components/auth/SecondFactorChoiceDialog.tsx b/web/apps/photos/src/components/auth/SecondFactorChoiceDialog.tsx
new file mode 100644
index 0000000000..2905c031f7
--- /dev/null
+++ b/web/apps/photos/src/components/auth/SecondFactorChoiceDialog.tsx
@@ -0,0 +1,64 @@
+import { styled } from "@mui/material";
+import type { SecondFactorChoicePresentationProps } from "ente-accounts/components/SecondFactorChoice";
+import { pt } from "ente-base/i18n";
+import { t } from "i18next";
+import type React from "react";
+import {
+ AuthDialog,
+ AuthDialogHeader,
+ AuthDialogText,
+ AuthDialogTitle,
+} from "./AuthDialog";
+import { Button } from "./Button";
+import { authDialogContentLayout } from "./styles";
+
+export function SecondFactorChoiceDialog({
+ open,
+ onDialogClose,
+ onSelect,
+}: SecondFactorChoicePresentationProps): React.JSX.Element {
+ return (
+ <AuthDialog
+ open={open}
+ onClose={onDialogClose}
+ ariaLabelledby="second-factor-choice-title"
+ >
+ <ContentRoot>
+ <AuthDialogHeader>
+ <AuthDialogTitle id="second-factor-choice-title">
+ {t("two_factor")}
+ </AuthDialogTitle>
+ <AuthDialogText>
+ {pt(
+ "Confirm it’s you with the second factor you set up.",
+ )}
+ </AuthDialogText>
+ </AuthDialogHeader>
+ <ButtonStack>
+ <Button
+ variant="primary"
+ fullWidth
+ onClick={() => onSelect("totp")}
+ >
+ {t("totp_login")}
+ </Button>
+ <Button
+ variant="secondary"
+ fullWidth
+ onClick={() => onSelect("passkey")}
+ >
+ {t("passkey_login")}
+ </Button>
+ </ButtonStack>
+ </ContentRoot>
+ </AuthDialog>
+ );
+}
+
+const ContentRoot = styled("div")(authDialogContentLayout);
+
+const ButtonStack = styled("div")({
+ display: "flex",
+ flexDirection: "column",
+ gap: "12px",
+});
diff --git a/web/apps/photos/src/pages/credentials.tsx b/web/apps/photos/src/pages/credentials.tsx
index b256709f69..fa62f80632 100644
--- a/web/apps/photos/src/pages/credentials.tsx
+++ b/web/apps/photos/src/pages/credentials.tsx
@@ -3,6 +3,7 @@ import {
PasswordForm,
} from "@/components/auth/CredentialsForm";
import { PasskeyVerificationForm } from "@/components/auth/PasskeyVerificationForm";
+import { SecondFactorChoiceDialog } from "@/components/auth/SecondFactorChoiceDialog";
import { PhotosAuthShell } from "@/components/PhotosAuthShell";
import { featureFlags } from "@/featureFlags";
import type { VerifyingPasskeyPresentationProps } from "ente-accounts/components/LoginComponents";
@@ -41,6 +42,7 @@ function CredentialsPage(): React.JSX.Element {
presentation={CredentialsPresentation}
passwordPresentation={PasswordForm}
passkeyPresentation={PasskeyPresentation}
+ secondFactorChoicePresentation={SecondFactorChoiceDialog}
/>
);
}
diff --git a/web/apps/photos/src/pages/verify.tsx b/web/apps/photos/src/pages/verify.tsx
index 70494e2c0e..91181e1f9f 100644
--- a/web/apps/photos/src/pages/verify.tsx
+++ b/web/apps/photos/src/pages/verify.tsx
@@ -1,4 +1,5 @@
import { PasskeyVerificationForm } from "@/components/auth/PasskeyVerificationForm";
+import { SecondFactorChoiceDialog } from "@/components/auth/SecondFactorChoiceDialog";
import { VerifyEmailForm } from "@/components/auth/VerifyEmailForm";
import { PhotosAuthShell } from "@/components/PhotosAuthShell";
import { featureFlags } from "@/featureFlags";
@@ -37,6 +38,7 @@ function VerifyPage(): React.JSX.Element {
<AccountsVerifyPage
presentation={VerifyEmailPresentation}
passkeyPresentation={PasskeyPresentation}
+ secondFactorChoicePresentation={SecondFactorChoiceDialog}
/>
);
}
diff --git a/web/packages/accounts/components/SecondFactorChoice.tsx b/web/packages/accounts/components/SecondFactorChoice.tsx
index 63445b77f4..95bdbdcd62 100644
--- a/web/packages/accounts/components/SecondFactorChoice.tsx
+++ b/web/packages/accounts/components/SecondFactorChoice.tsx
@@ -1,51 +1,80 @@
-import { Dialog, DialogContent, DialogTitle, Stack } from "@mui/material";
+import {
+ Dialog,
+ DialogContent,
+ DialogTitle,
+ Stack,
+ type ModalProps,
+} from "@mui/material";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import { t } from "i18next";
-import React from "react";
+import React, { type ComponentType } from "react";
export type SecondFactorType = "totp" | "passkey";
+export interface SecondFactorChoicePresentationProps {
+ open: boolean;
+ onDialogClose: ModalProps["onClose"];
+ onSelect: (factor: SecondFactorType) => void;
+}
+
type SecondFactorChoiceProps = ModalVisibilityProps & {
onSelect: (factor: SecondFactorType) => void;
+ presentation?: ComponentType<SecondFactorChoicePresentationProps>;
};
export const SecondFactorChoice: React.FC<SecondFactorChoiceProps> = ({
open,
onClose,
onSelect,
-}) => (
- <Dialog
- open={open}
- onClose={(_, reason) => {
- if (reason != "backdropClick") onClose();
- }}
- fullWidth
- slotProps={{ paper: { sx: { maxWidth: "360px", padding: "12px" } } }}
- >
- <DialogTitle>{t("two_factor")}</DialogTitle>
- <DialogContent>
- <Stack sx={{ gap: "12px" }}>
- <FocusVisibleButton
- color="accent"
- onClick={() => {
- onClose();
- onSelect("totp");
- }}
- >
- {t("totp_login")}
- </FocusVisibleButton>
-
- <FocusVisibleButton
- color="accent"
- onClick={() => {
- onClose();
- onSelect("passkey");
- }}
- >
- {t("passkey_login")}
- </FocusVisibleButton>
- </Stack>
- </DialogContent>
- </Dialog>
-);
+ presentation: Presentation,
+}) => {
+ const handleDialogClose: ModalProps["onClose"] = (_, reason) => {
+ if (reason != "backdropClick") onClose();
+ };
+
+ const handleSelect = (factor: SecondFactorType) => {
+ onClose();
+ onSelect(factor);
+ };
+
+ if (Presentation) {
+ return (
+ <Presentation
+ open={open}
+ onDialogClose={handleDialogClose}
+ onSelect={handleSelect}
+ />
+ );
+ }
+
+ return (
+ <Dialog
+ open={open}
+ onClose={handleDialogClose}
+ fullWidth
+ slotProps={{
+ paper: { sx: { maxWidth: "360px", padding: "12px" } },
+ }}
+ >
+ <DialogTitle>{t("two_factor")}</DialogTitle>
+ <DialogContent>
+ <Stack sx={{ gap: "12px" }}>
+ <FocusVisibleButton
+ color="accent"
+ onClick={() => handleSelect("totp")}
+ >
+ {t("totp_login")}
+ </FocusVisibleButton>
+
+ <FocusVisibleButton
+ color="accent"
+ onClick={() => handleSelect("passkey")}
+ >
+ {t("passkey_login")}
+ </FocusVisibleButton>
+ </Stack>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index ba8bb3c601..a39b6bd2b8 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -5,7 +5,10 @@ import {
VerifyingPasskey,
type VerifyingPasskeyPresentationProps,
} from "ente-accounts/components/LoginComponents";
-import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";
+import {
+ SecondFactorChoice,
+ type SecondFactorChoicePresentationProps,
+} from "ente-accounts/components/SecondFactorChoice";
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";
import {
@@ -84,12 +87,14 @@ export interface CredentialsPageProps {
presentation?: ComponentType<CredentialsPresentationProps>;
passwordPresentation?: ComponentType<VerifyMasterPasswordPresentationProps>;
passkeyPresentation?: ComponentType<VerifyingPasskeyPresentationProps>;
+ secondFactorChoicePresentation?: ComponentType<SecondFactorChoicePresentationProps>;
}
const Page: React.FC<CredentialsPageProps> = ({
presentation: Presentation,
passwordPresentation,
passkeyPresentation,
+ secondFactorChoicePresentation,
}) => {
const { logout, showMiniDialog } = useBaseContext();
@@ -409,7 +414,10 @@ const Page: React.FC<CredentialsPageProps> = ({
</AccountsPageFooterWithHost>
</AccountsPageContents>
)}
- <SecondFactorChoice {...secondFactorChoiceProps} />
+ <SecondFactorChoice
+ {...secondFactorChoiceProps}
+ presentation={secondFactorChoicePresentation}
+ />
</>
);
};
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index 408b5ef628..6cdefdc7e5 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -8,7 +8,10 @@ import {
VerifyingPasskey,
type VerifyingPasskeyPresentationProps,
} from "ente-accounts/components/LoginComponents";
-import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";
+import {
+ SecondFactorChoice,
+ type SecondFactorChoicePresentationProps,
+} from "ente-accounts/components/SecondFactorChoice";
import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";
import {
replaceSavedLocalUser,
@@ -68,11 +71,13 @@ export interface VerifyEmailPresentationProps {
export interface VerifyPageProps {
presentation?: ComponentType<VerifyEmailPresentationProps>;
passkeyPresentation?: ComponentType<VerifyingPasskeyPresentationProps>;
+ secondFactorChoicePresentation?: ComponentType<SecondFactorChoicePresentationProps>;
}
const Page: React.FC<VerifyPageProps> = ({
presentation: Presentation,
passkeyPresentation,
+ secondFactorChoicePresentation,
}) => {
const { logout, showMiniDialog } = useBaseContext();
@@ -219,7 +224,10 @@ const Page: React.FC<VerifyPageProps> = ({
onResend={resendEmail}
onChangeEmail={logout}
/>
- <SecondFactorChoice {...secondFactorChoiceProps} />
+ <SecondFactorChoice
+ {...secondFactorChoiceProps}
+ presentation={secondFactorChoicePresentation}
+ />
</>
);
}
@@ -265,7 +273,10 @@ const Page: React.FC<VerifyPageProps> = ({
<LinkButton onClick={logout}>{t("change_email")}</LinkButton>
</AccountsPageFooter>
- <SecondFactorChoice {...secondFactorChoiceProps} />
+ <SecondFactorChoice
+ {...secondFactorChoiceProps}
+ presentation={secondFactorChoicePresentation}
+ />
</AccountsPageContents>
);
};