Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web][photos] Update password authentication dialog

Aswin Asok502e3046f7a5
diff --git a/desktop/changes/authenticate-user-dialog.md b/desktop/changes/authenticate-user-dialog.md
new file mode 100644
index 0000000000..89b7cac260
--- /dev/null
+++ b/desktop/changes/authenticate-user-dialog.md
@@ -0,0 +1 @@
+- Updated the password authentication dialog to match the new album dialog.
diff --git a/web/apps/photos/src/components/AuthenticateUser.tsx b/web/apps/photos/src/components/AuthenticateUser.tsx
index 90d98e27d8..a6c6173880 100644
--- a/web/apps/photos/src/components/AuthenticateUser.tsx
+++ b/web/apps/photos/src/components/AuthenticateUser.tsx
@@ -1,5 +1,19 @@
+import CloseIcon from "@mui/icons-material/Close";
+import {
+ ButtonBase,
+ Dialog,
+ DialogTitle,
+ IconButton,
+ Input,
+ InputBase,
+ Stack,
+ Typography,
+} from "@mui/material";
import { useAuthPageConfig } from "ente-accounts/components/auth/AuthPageProvider";
-import { VerifyMasterPasswordForm } from "ente-accounts/components/VerifyMasterPasswordForm";
+import {
+ VerifyMasterPasswordForm,
+ type VerifyMasterPasswordPresentationProps,
+} from "ente-accounts/components/VerifyMasterPasswordForm";
import { checkSessionValidity } from "ente-accounts/services/session";
import {
ensureLocalUser,
@@ -7,15 +21,25 @@ import {
type KeyAttributes,
type LocalUser,
} from "ente-accounts/services/user";
+import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";
+import { LoadingButton } from "ente-base/components/mui/LoadingButton";
+import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";
import {
- TitledMiniDialog,
- type MiniDialogAttributes,
-} from "ente-base/components/MiniDialog";
+ v2CancelButtonSx,
+ v2CloseButtonSx,
+ v2HeaderRowSx,
+ v2HelperSx,
+ v2InputSx,
+ v2LabelSx,
+ v2PaperSx,
+ v2SubmitButtonSx,
+ v2TitleSx,
+} from "ente-base/components/SingleInput.styles";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import { useBaseContext } from "ente-base/context";
import log from "ente-base/log";
import { t } from "i18next";
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useId, useState } from "react";
type AuthenticateUserProps = ModalVisibilityProps & {
onAuthenticate: () => void;
@@ -26,14 +50,28 @@ export const AuthenticateUser: React.FC<AuthenticateUserProps> = ({
onClose,
...rest
}) => (
- <TitledMiniDialog
+ <Dialog
open={open}
onClose={onClose}
- sx={{ position: "absolute" }}
- title={t("password")}
+ maxWidth={false}
+ slotProps={{ paper: { sx: v2PaperSx } }}
>
- <AuthenticateUserDialogContents {...{ open, onClose }} {...rest} />
- </TitledMiniDialog>
+ <Stack sx={{ p: "20px", gap: "20px" }}>
+ <Stack direction="row" sx={v2HeaderRowSx}>
+ <DialogTitle sx={{ ...v2TitleSx, "&&": { p: 0 } }}>
+ {t("password")}
+ </DialogTitle>
+ <IconButton
+ aria-label={t("close")}
+ onClick={onClose}
+ sx={v2CloseButtonSx}
+ >
+ <CloseIcon sx={{ fontSize: 18 }} />
+ </IconButton>
+ </Stack>
+ <AuthenticateUserDialogContents {...{ open, onClose }} {...rest} />
+ </Stack>
+ </Dialog>
);
const AuthenticateUserDialogContents: React.FC<AuthenticateUserProps> = ({
@@ -74,10 +112,18 @@ const AuthenticateUserDialogContents: React.FC<AuthenticateUserProps> = ({
if (open) void validateSession();
}, [open, validateSession]);
+ const presentation = useCallback(
+ (props: VerifyMasterPasswordPresentationProps) => (
+ <AuthenticateUserForm {...props} onCancel={onClose} />
+ ),
+ [onClose],
+ );
+
if (!user || !keyAttributes) return <></>;
return (
<VerifyMasterPasswordForm
+ presentation={presentation}
decryptBox={decryptBox}
userEmail={user.email}
keyAttributes={keyAttributes}
@@ -98,3 +144,83 @@ const passwordChangedElsewhereDialogAttributes = (
continue: { text: t("login"), action: onLogin },
cancel: false,
});
+
+const AuthenticateUserForm: React.FC<
+ VerifyMasterPasswordPresentationProps & { onCancel: () => void }
+> = ({
+ userEmail,
+ password,
+ passwordError,
+ isSubmitting,
+ submitButtonTitle,
+ onPasswordChange,
+ onSubmit,
+ onCancel,
+}) => {
+ const inputID = useId();
+ const helperID = useId();
+ const [showPassword, setShowPassword] = useState(false);
+ return (
+ <Stack component="form" onSubmit={onSubmit} sx={{ gap: "20px" }}>
+ <Input
+ sx={{ display: "none" }}
+ name="email"
+ autoComplete="username"
+ type="email"
+ value={userEmail}
+ />
+ <Stack sx={{ gap: "8px" }}>
+ <Typography component="label" htmlFor={inputID} sx={v2LabelSx}>
+ {t("password")}
+ </Typography>
+ <InputBase
+ id={inputID}
+ name="password"
+ value={password}
+ onChange={onPasswordChange}
+ type={showPassword ? "text" : "password"}
+ autoComplete="current-password"
+ autoFocus
+ disabled={isSubmitting}
+ error={!!passwordError}
+ sx={v2InputSx}
+ inputProps={{
+ "aria-describedby": passwordError
+ ? helperID
+ : undefined,
+ "aria-invalid": !!passwordError,
+ }}
+ endAdornment={
+ <ShowHidePasswordInputAdornment
+ showPassword={showPassword}
+ onToggle={() => setShowPassword((show) => !show)}
+ />
+ }
+ />
+ <Typography
+ id={helperID}
+ aria-live="polite"
+ sx={v2HelperSx(!!passwordError)}
+ >
+ {passwordError ?? ""}
+ </Typography>
+ </Stack>
+ <Stack direction="row" sx={{ gap: "12px" }}>
+ <ButtonBase
+ onClick={onCancel}
+ disabled={isSubmitting}
+ sx={v2CancelButtonSx}
+ >
+ {t("cancel")}
+ </ButtonBase>
+ <LoadingButton
+ type="submit"
+ loading={isSubmitting}
+ sx={{ ...v2SubmitButtonSx, p: 0 }}
+ >
+ {submitButtonTitle}
+ </LoadingButton>
+ </Stack>
+ </Stack>
+ );
+};
diff --git a/web/packages/base/components/SingleInput.styles.ts b/web/packages/base/components/SingleInput.styles.ts
new file mode 100644
index 0000000000..f0fd6b1f08
--- /dev/null
+++ b/web/packages/base/components/SingleInput.styles.ts
@@ -0,0 +1,119 @@
+import type { SxProps, Theme } from "@mui/material";
+
+const surfaceStroke = "#e0e0e0";
+const surfaceStrokeDark = "rgba(255 255 255 / 0.12)";
+
+export const v2PaperSx: SxProps<Theme> = (theme) => ({
+ width: "min(444px, calc(100svw - 32px))",
+ maxWidth: "444px",
+ boxSizing: "content-box",
+ m: 2,
+ borderRadius: "20px",
+ border: `1px solid ${surfaceStroke}`,
+ backgroundColor: "#f4f4f4",
+ backgroundImage: "none",
+ boxShadow: "none",
+ color: "text.base",
+ ...theme.applyStyles("dark", {
+ borderColor: surfaceStrokeDark,
+ backgroundColor: "#1b1b1b",
+ }),
+});
+export const v2HeaderRowSx = {
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: "12px",
+};
+export const v2TitleSx = { fontSize: 24, lineHeight: "32px", fontWeight: 600 };
+export const v2CloseButtonSx = (theme: Theme) => ({
+ width: 38,
+ height: 38,
+ p: 0,
+ flexShrink: 0,
+ color: "text.base",
+ backgroundColor: "background.paper",
+ "&:hover": { backgroundColor: "fill.faintHover" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+});
+
+const greenAccent = "#08c225";
+const greenAccentHover = "#07ad21";
+const errorColor = "#fa1336";
+
+export const v2LabelSx = {
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ color: "text.muted",
+};
+export const v2InputSx: SxProps<Theme> = (theme) => ({
+ height: 52,
+ boxSizing: "content-box",
+ display: "flex",
+ alignItems: "center",
+ borderRadius: "16px",
+ border: "1px solid transparent",
+ backgroundColor: "background.paper",
+ px: "16px",
+ fontSize: 14,
+ fontWeight: 500,
+ color: "text.base",
+ "&.Mui-focused": { borderColor: "rgba(0 0 0 / 0.08)" },
+ "& input": { padding: 0, height: "auto" },
+ "& input::placeholder": { color: "text.muted", opacity: 1 },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "#282828",
+ "&.Mui-focused": { borderColor: "rgba(255 255 255 / 0.18)" },
+ }),
+ "&.Mui-error": { borderColor: errorColor },
+});
+export const v2HelperSx = (isError: boolean) => (theme: Theme) => ({
+ fontSize: 12,
+ lineHeight: "16px",
+ fontWeight: 500,
+ color: isError ? errorColor : "rgba(0 0 0 / 0.45)",
+ ...(isError
+ ? {}
+ : theme.applyStyles("dark", { color: "rgba(255 255 255 / 0.45)" })),
+});
+const v2BaseActionSx = {
+ flex: 1,
+ height: 52,
+ borderRadius: "20px",
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ fontFamily: "inherit",
+ "&.Mui-disabled": { opacity: 0.7 },
+};
+export const v2CancelButtonSx = (theme: Theme) => ({
+ ...v2BaseActionSx,
+ color: "text.base",
+ backgroundColor: "#eaeaea",
+ "&:hover": { backgroundColor: "#dedede" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ "&:hover": { backgroundColor: "rgba(255 255 255 / 0.18)" },
+ }),
+});
+export const v2SubmitButtonSx = {
+ ...v2BaseActionSx,
+ color: "#fff",
+ backgroundColor: greenAccent,
+ "&:hover": { backgroundColor: greenAccentHover },
+ "&.Mui-disabled": {
+ color: "#fff",
+ backgroundColor: greenAccent,
+ opacity: 0.7,
+ },
+};
+
+export const peopleActionFocusSx = {
+ "&.Mui-focusVisible": {
+ outline: "1px solid",
+ outlineColor: "stroke.base",
+ outlineOffset: "2px",
+ },
+};
diff --git a/web/packages/base/components/SingleInputDialog.tsx b/web/packages/base/components/SingleInputDialog.tsx
index 7e64e0400f..713fbac962 100644
--- a/web/packages/base/components/SingleInputDialog.tsx
+++ b/web/packages/base/components/SingleInputDialog.tsx
@@ -12,6 +12,12 @@ import {
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import { t } from "i18next";
import React, { useCallback, useId } from "react";
+import {
+ v2CloseButtonSx,
+ v2HeaderRowSx,
+ v2PaperSx,
+ v2TitleSx,
+} from "./SingleInput.styles";
import { SingleInputForm, type SingleInputFormProps } from "./SingleInputForm";
type SingleInputDialogProps = ModalVisibilityProps &
@@ -96,41 +102,3 @@ export const SingleInputDialog: React.FC<SingleInputDialogProps> = ({
</Dialog>
);
};
-
-const surfaceStroke = "#e0e0e0";
-const surfaceStrokeDark = "rgba(255 255 255 / 0.12)";
-
-const v2PaperSx: SxProps<Theme> = (theme) => ({
- width: "min(444px, calc(100svw - 32px))",
- maxWidth: "444px",
- boxSizing: "content-box",
- m: 2,
- borderRadius: "20px",
- border: `1px solid ${surfaceStroke}`,
- backgroundColor: "#f4f4f4",
- backgroundImage: "none",
- boxShadow: "none",
- color: "text.base",
- ...theme.applyStyles("dark", {
- borderColor: surfaceStrokeDark,
- backgroundColor: "#1b1b1b",
- }),
-});
-const v2HeaderRowSx = {
- alignItems: "center",
- justifyContent: "space-between",
- gap: "12px",
-};
-const v2TitleSx = { fontSize: 24, lineHeight: "32px", fontWeight: 600 };
-const v2CloseButtonSx = (theme: Theme) => ({
- width: 38,
- height: 38,
- p: 0,
- flexShrink: 0,
- color: "text.base",
- backgroundColor: "background.paper",
- "&:hover": { backgroundColor: "fill.faintHover" },
- ...theme.applyStyles("dark", {
- backgroundColor: "rgba(255 255 255 / 0.12)",
- }),
-});
diff --git a/web/packages/base/components/SingleInputForm.tsx b/web/packages/base/components/SingleInputForm.tsx
index f8d752e40d..65c1365caf 100644
--- a/web/packages/base/components/SingleInputForm.tsx
+++ b/web/packages/base/components/SingleInputForm.tsx
@@ -6,9 +6,7 @@ import {
TextField,
Typography,
type ButtonProps,
- type SxProps,
type TextFieldProps,
- type Theme,
} from "@mui/material";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
@@ -16,6 +14,14 @@ import log from "ente-base/log";
import { useFormik } from "formik";
import { t } from "i18next";
import React, { useCallback, useId, useState } from "react";
+import {
+ peopleActionFocusSx,
+ v2CancelButtonSx,
+ v2HelperSx,
+ v2InputSx,
+ v2LabelSx,
+ v2SubmitButtonSx,
+} from "./SingleInput.styles";
import { ShowHidePasswordInputAdornment } from "./mui/PasswordInputAdornment";
export type SingleInputFormProps = Pick<
@@ -214,83 +220,3 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
</form>
);
};
-
-const greenAccent = "#08c225";
-const greenAccentHover = "#07ad21";
-const errorColor = "#fa1336";
-
-const v2LabelSx = {
- fontSize: 14,
- lineHeight: "20px",
- fontWeight: 500,
- color: "text.muted",
-};
-const v2InputSx: SxProps<Theme> = (theme) => ({
- height: 52,
- boxSizing: "content-box",
- display: "flex",
- alignItems: "center",
- borderRadius: "16px",
- border: "1px solid transparent",
- backgroundColor: "background.paper",
- px: "16px",
- fontSize: 14,
- fontWeight: 500,
- color: "text.base",
- "&.Mui-focused": { borderColor: "rgba(0 0 0 / 0.08)" },
- "& input": { padding: 0, height: "auto" },
- "& input::placeholder": { color: "text.muted", opacity: 1 },
- ...theme.applyStyles("dark", {
- backgroundColor: "#282828",
- "&.Mui-focused": { borderColor: "rgba(255 255 255 / 0.18)" },
- }),
- "&.Mui-error": { borderColor: errorColor },
-});
-const v2HelperSx = (isError: boolean) => (theme: Theme) => ({
- fontSize: 12,
- lineHeight: "16px",
- fontWeight: 500,
- color: isError ? errorColor : "rgba(0 0 0 / 0.45)",
- ...(isError
- ? {}
- : theme.applyStyles("dark", { color: "rgba(255 255 255 / 0.45)" })),
-});
-const v2BaseActionSx = {
- flex: 1,
- height: 52,
- borderRadius: "20px",
- fontSize: 14,
- lineHeight: "20px",
- fontWeight: 500,
- fontFamily: "inherit",
- "&.Mui-disabled": { opacity: 0.7 },
-};
-const v2CancelButtonSx = (theme: Theme) => ({
- ...v2BaseActionSx,
- color: "text.base",
- backgroundColor: "#eaeaea",
- "&:hover": { backgroundColor: "#dedede" },
- ...theme.applyStyles("dark", {
- backgroundColor: "rgba(255 255 255 / 0.12)",
- "&:hover": { backgroundColor: "rgba(255 255 255 / 0.18)" },
- }),
-});
-const v2SubmitButtonSx = {
- ...v2BaseActionSx,
- color: "#fff",
- backgroundColor: greenAccent,
- "&:hover": { backgroundColor: greenAccentHover },
- "&.Mui-disabled": {
- color: "#fff",
- backgroundColor: greenAccent,
- opacity: 0.7,
- },
-};
-
-const peopleActionFocusSx = {
- "&.Mui-focusVisible": {
- outline: "1px solid",
- outlineColor: "stroke.base",
- outlineOffset: "2px",
- },
-};