π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update(locker):pending-dialogs-updated
Aswin Asok17c12d9b5b48
diff --git a/web/apps/locker/src/components/LockerAuthenticateUser.tsx b/web/apps/locker/src/components/LockerAuthenticateUser.tsxindex deac2ee2ab..39fe15e398 100644--- a/web/apps/locker/src/components/LockerAuthenticateUser.tsx+++ b/web/apps/locker/src/components/LockerAuthenticateUser.tsx@@ -1,4 +1,18 @@-import { VerifyMasterPasswordForm } from "ente-accounts/components/VerifyMasterPasswordForm";+import CloseIcon from "@mui/icons-material/Close";+import VisibilityIcon from "@mui/icons-material/Visibility";+import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";+import {+ Dialog,+ DialogContent,+ DialogTitle,+ IconButton,+ InputAdornment,+ Stack,+} from "@mui/material";+import {+ VerifyMasterPasswordForm,+ type VerifyMasterPasswordPresentationProps,+} from "ente-accounts/components/VerifyMasterPasswordForm";import { checkSessionValidity } from "ente-accounts/services/session";import {ensureLocalUser,@@ -6,16 +20,25 @@ import {type KeyAttributes,type LocalUser,} from "ente-accounts/services/user";-import {- TitledMiniDialog,- type MiniDialogAttributes,-} from "ente-base/components/MiniDialog";+import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";+import { LoadingButton } from "ente-base/components/mui/LoadingButton";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 React, { useCallback, useEffect, useState } from "react";+import { FormField } from "./createItemDialog/ItemFormFields";+import {+ lockerSheetContainerSx,+ lockerSheetPaperSx,+} from "./locker-dialog-styles";+import {+ lockerColorSx,+ lockerTextBodyBoldSx,+ lockerTextH2Sx,+} from "./locker-tokens";+type LockerAuthenticateUserProps = ModalVisibilityProps & {onAuthenticate: () => void;};@@ -25,11 +48,55 @@ export const LockerAuthenticateUser: React.FC<LockerAuthenticateUserProps> = ({onClose,onAuthenticate,}) => (- <TitledMiniDialog open={open} onClose={onClose} title={t("password")}>- <LockerAuthenticateUserDialogContents- {...{ open, onClose, onAuthenticate }}- />- </TitledMiniDialog>+ <Dialog+ open={open}+ onClose={onClose}+ fullWidth+ maxWidth="xs"+ aria-labelledby="locker-authenticate-title"+ slotProps={{+ paper: { sx: lockerSheetPaperSx },+ container: { sx: lockerSheetContainerSx },+ }}+ >+ <DialogTitle+ id="locker-authenticate-title"+ sx={{+ ...lockerTextH2Sx,+ "&&&": { p: 0 },+ display: "flex",+ alignItems: "center",+ justifyContent: "space-between",+ mb: 2.5,+ }}+ >+ {t("password")}+ <IconButton+ aria-label={t("close")}+ onClick={onClose}+ sx={(theme) => ({+ width: 36,+ height: 36,+ p: 0,+ borderRadius: "50%",+ ...lockerColorSx(theme, {+ backgroundColor: "fillLight",+ color: "iconColor",+ }),+ "&:hover": lockerColorSx(theme, {+ backgroundColor: "fillDark",+ }),+ })}+ >+ <CloseIcon sx={{ fontSize: 18 }} />+ </IconButton>+ </DialogTitle>+ <DialogContent sx={{ "&&&": { p: 0 } }}>+ <LockerAuthenticateUserDialogContents+ {...{ open, onClose, onAuthenticate }}+ />+ </DialogContent>+ </Dialog>);const LockerAuthenticateUserDialogContents: React.FC<@@ -72,6 +139,7 @@ const LockerAuthenticateUserDialogContents: React.FC<return (<VerifyMasterPasswordForm+ presentation={LockerPasswordForm}userEmail={user.email}keyAttributes={keyAttributes}submitButtonTitle={t("authenticate")}@@ -91,3 +159,96 @@ const passwordChangedElsewhereDialogAttributes = (continue: { text: t("login"), action: onLogin },cancel: false,});++const LockerPasswordForm: React.FC<VerifyMasterPasswordPresentationProps> = ({+ userEmail,+ password,+ passwordError,+ isSubmitting,+ submitButtonTitle,+ onPasswordChange,+ onSubmit,+}) => {+ const [showPassword, setShowPassword] = useState(false);+ return (+ <Stack component="form" onSubmit={onSubmit} sx={{ gap: 3 }}>+ <input+ name="email"+ type="email"+ autoComplete="username"+ value={userEmail}+ readOnly+ hidden+ />+ <FormField+ name="password"+ label={t("password")}+ type={showPassword ? "text" : "password"}+ autoComplete="current-password"+ autoFocus+ value={password}+ onChange={onPasswordChange}+ disabled={isSubmitting}+ error={!!passwordError}+ helperText={passwordError}+ slotProps={{+ input: {+ endAdornment: (+ <InputAdornment position="end">+ <IconButton+ aria-label={t("show_or_hide_password")}+ aria-pressed={showPassword}+ onClick={() =>+ setShowPassword((show) => !show)+ }+ onMouseDown={(event) =>+ event.preventDefault()+ }+ edge="end"+ sx={(theme) => ({+ color: "inherit",+ "&&": {+ backgroundColor: "transparent",+ },+ "&&:hover": lockerColorSx(theme, {+ backgroundColor: "fillDark",+ }),+ })}+ >+ {showPassword ? (+ <VisibilityOffIcon+ sx={{ fontSize: 20 }}+ />+ ) : (+ <VisibilityIcon sx={{ fontSize: 20 }} />+ )}+ </IconButton>+ </InputAdornment>+ ),+ },+ }}+ />+ <LoadingButton+ fullWidth+ type="submit"+ color="primary"+ loading={isSubmitting}+ sx={(theme) => ({+ ...lockerTextBodyBoldSx,+ minHeight: 52,+ borderRadius: "20px",+ textTransform: "none",+ ...lockerColorSx(theme, {+ backgroundColor: "primary",+ color: "specialWhite",+ }),+ "&:hover": lockerColorSx(theme, {+ backgroundColor: "primaryDark",+ }),+ })}+ >+ {submitButtonTitle}+ </LoadingButton>+ </Stack>+ );+};diff --git a/web/apps/locker/src/components/LockerSessionsDrawer.tsx b/web/apps/locker/src/components/LockerSessionsDrawer.tsxindex 721eb245ac..95ee313194 100644--- a/web/apps/locker/src/components/LockerSessionsDrawer.tsx+++ b/web/apps/locker/src/components/LockerSessionsDrawer.tsx@@ -22,6 +22,7 @@ import log from "ente-base/log";import { savedAuthToken } from "ente-base/token";import { t } from "i18next";import React, { useCallback, useEffect, useState } from "react";+import { LockerConfirmDialog } from "./LockerConfirmDialog";import {LockerTitledNestedSidebarDrawer,type LockerNestedSidebarDrawerVisibilityProps,@@ -35,6 +36,7 @@ import {textLightSx,titlebarActionButtonSx,} from "./locker-sidebar-styles";+import { lockerColorSx } from "./locker-tokens";const mobileUserAgentRegex = /iphone|ipad|android|mobile/i;@@ -103,6 +105,10 @@ const SessionsContents: React.FC<SessionsContentsProps> = ({const [currentToken, setCurrentToken] = useState<string | undefined>();const [isLoading, setIsLoading] = useState(true);const [error, setError] = useState<string | undefined>();+ const [sessionToTerminate, setSessionToTerminate] = useState<Session>();+ const [terminationOpen, setTerminationOpen] = useState(false);+ const [isTerminating, setIsTerminating] = useState(false);+ const [terminationError, setTerminationError] = useState<string>();const fetchSessions = useCallback(async () => {setIsLoading(true);@@ -136,52 +142,33 @@ const SessionsContents: React.FC<SessionsContentsProps> = ({void fetchSessions();}, [fetchSessions, refreshTrigger]);- const handleTerminateSession = useCallback(- (session: Session) => {- const isCurrentDevice = isCurrentSession(session, currentToken);-- showMiniDialog({- title: t("terminate_session"),- message: isCurrentDevice ? (- t("terminate_session_confirm_message_self")- ) : (- <Box sx={{ whiteSpace: "pre-line" }}>- {`${t("terminate_session_confirm_message")}:\n\n${session.prettyUA}\n${session.ip}`}- </Box>- ),- continue: {- text: t("terminate"),- color: "critical",- action: async () => {- if (isCurrentDevice) {- logout();- return;- }-- try {- await terminateSession(session.token);- await fetchSessions();- } catch (e) {- log.error("Failed to terminate session", e);- if (isHTTP401Error(e)) {- setTimeout(() => {- showMiniDialog(- sessionExpiredDialogAttributes(logout),- );- }, 0);- } else {- showMiniDialog({- title: t("error"),- message: t("terminate_session_failed"),- });- }- }- },- },- });- },- [currentToken, fetchSessions, logout, showMiniDialog],- );+ const handleTerminateSession = async () => {+ if (!terminationOpen || !sessionToTerminate || isTerminating) return;+ setIsTerminating(true);+ setTerminationError(undefined);+ try {+ if (isCurrentSession(sessionToTerminate, currentToken)) {+ logout();+ setTerminationOpen(false);+ return;+ }+ await terminateSession(sessionToTerminate.token);+ setTerminationOpen(false);+ await fetchSessions();+ } catch (e) {+ log.error("Failed to terminate session", e);+ if (isHTTP401Error(e)) {+ setTerminationOpen(false);+ setTimeout(() => {+ showMiniDialog(sessionExpiredDialogAttributes(logout));+ }, 0);+ } else {+ setTerminationError(t("terminate_session_failed"));+ }+ } finally {+ setIsTerminating(false);+ }+ };if (isLoading) {return (@@ -234,9 +221,55 @@ const SessionsContents: React.FC<SessionsContentsProps> = ({key={session.token}session={session}isCurrentDevice={isCurrentSession(session, currentToken)}- onTerminate={() => handleTerminateSession(session)}+ onTerminate={() => {+ setTerminationError(undefined);+ setSessionToTerminate(session);+ setTerminationOpen(true);+ }}/>))}+ <LockerConfirmDialog+ open={terminationOpen}+ illustration="/images/warning-red.png"+ title={t("terminate_session")}+ body={+ sessionToTerminate &&+ isCurrentSession(sessionToTerminate, currentToken) ? (+ t("terminate_session_confirm_message_self")+ ) : (+ <>+ {t("terminate_session_confirm_message")}+ <Box+ component="span"+ sx={(theme) => ({+ display: "block",+ mt: 2,+ p: 1.5,+ borderRadius: "12px",+ overflowWrap: "anywhere",+ ...lockerColorSx(theme, {+ backgroundColor: "fillDark",+ color: "textLight",+ }),+ })}+ >+ {sessionToTerminate?.prettyUA}+ <Box+ component="span"+ sx={{ display: "block", mt: 0.5 }}+ >+ {sessionToTerminate?.ip}+ </Box>+ </Box>+ </>+ )+ }+ confirmLabel={t("terminate")}+ loading={isTerminating}+ error={terminationError}+ onClose={() => setTerminationOpen(false)}+ onConfirm={handleTerminateSession}+ /></Stack>);};diff --git a/web/apps/locker/src/components/LockerSupportDrawer.tsx b/web/apps/locker/src/components/LockerSupportDrawer.tsxindex 3e91efe19a..aa7a103a25 100644--- a/web/apps/locker/src/components/LockerSupportDrawer.tsx+++ b/web/apps/locker/src/components/LockerSupportDrawer.tsx@@ -11,14 +11,15 @@ import {} from "@hugeicons/core-free-icons";import ChevronRightIcon from "@mui/icons-material/ChevronRight";import { Box } from "@mui/material";-import { useBaseContext } from "ente-base/context";import log from "ente-base/log";import { savedLogs } from "ente-base/log-web";import { saveStringAsFile } from "ente-base/utils/web";import { initiateEmail, openURL } from "ente-new/photos/utils/web";import { t } from "i18next";-import React from "react";+import React, { useState } from "react";import { Trans } from "react-i18next";+import { lockerColorSx } from "./locker-tokens";+import { LockerConfirmDialog } from "./LockerConfirmDialog";import {LockerSidebarCardButton,LockerSidebarLink,@@ -41,7 +42,9 @@ const helpTopics = [export const LockerSupportDrawer: React.FC<LockerNestedSidebarDrawerVisibilityProps> = ({ open, onClose, onRootClose }) => {- const { showMiniDialog } = useBaseContext();+ const [logsOpen, setLogsOpen] = useState(false);+ const [isViewingLogs, setIsViewingLogs] = useState(false);+ const [logsError, setLogsError] = useState<string>();const handleRootClose = () => {onClose();onRootClose();@@ -63,12 +66,20 @@ export const LockerSupportDrawer: React.FC<}};- const confirmViewLogs = () =>- showMiniDialog({- title: t("view_logs"),- message: <Trans i18nKey="view_logs_message" />,- continue: { text: t("view_logs"), action: viewLogs },- });+ const handleViewLogs = async () => {+ if (isViewingLogs) return;+ setIsViewingLogs(true);+ setLogsError(undefined);+ try {+ await viewLogs();+ setLogsOpen(false);+ } catch (error) {+ log.error("Failed to view Locker logs", error);+ setLogsError(t("generic_error"));+ } finally {+ setIsViewingLogs(false);+ }+ };return (<LockerTitledNestedSidebarDrawer@@ -97,7 +108,12 @@ export const LockerSupportDrawer: React.FC<endIcon={<ChevronRightIcon />}onClick={handleReportIssue}/>- <LockerSidebarLink onClick={confirmViewLogs}>+ <LockerSidebarLink+ onClick={() => {+ setLogsError(undefined);+ setLogsOpen(true);+ }}+ >{t("export_logs")}</LockerSidebarLink><Box sx={{ mt: 2 }}>@@ -122,6 +138,43 @@ export const LockerSupportDrawer: React.FC<>{t("view_all_help_topics")}</LockerSidebarLink>+ <LockerConfirmDialog+ open={logsOpen}+ illustration="/images/warning-grey.png"+ title={t("view_logs")}+ body={+ <Box+ component="span"+ sx={(theme) => ({+ display: "block",+ textAlign: "center",+ lineHeight: "22px",+ ...lockerColorSx(theme, { color: "textBase" }),+ "& > span": { display: "block" },+ "& > span + span": {+ mt: 2,+ p: 1.5,+ borderRadius: "12px",+ ...lockerColorSx(theme, {+ backgroundColor: "fillDark",+ color: "textLight",+ }),+ },+ })}+ >+ <Trans+ i18nKey="view_logs_message"+ components={{ p: <span /> }}+ />+ </Box>+ }+ confirmLabel={t("view_logs")}+ tone="primary"+ loading={isViewingLogs}+ error={logsError}+ onClose={() => setLogsOpen(false)}+ onConfirm={handleViewLogs}+ /></LockerTitledNestedSidebarDrawer>);};diff --git a/web/apps/locker/src/components/LockerTwoFactorDrawer.tsx b/web/apps/locker/src/components/LockerTwoFactorDrawer.tsxindex 4cd929a499..5bb0c0084d 100644--- a/web/apps/locker/src/components/LockerTwoFactorDrawer.tsx+++ b/web/apps/locker/src/components/LockerTwoFactorDrawer.tsx@@ -1,24 +1,34 @@+import ChevronRightIcon from "@mui/icons-material/ChevronRight";import LockIcon from "@mui/icons-material/Lock";-import { CircularProgress, Stack, Typography } from "@mui/material";+import {+ Box,+ Button,+ CircularProgress,+ FormControlLabel,+ Stack,+ Switch,+ Typography,+} from "@mui/material";import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";import { updateSavedLocalUser } from "ente-accounts/services/accounts-db";import {disableTwoFactor,getTwoFactorStatus,} from "ente-accounts/services/user";-import {- RowButton,- RowButtonGroup,- RowButtonGroupHint,- RowSwitch,-} from "ente-base/components/RowButton";-import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";import { useBaseContext } from "ente-base/context";import { isHTTP401Error } from "ente-base/http";import log from "ente-base/log";import { t } from "i18next";import { useRouter } from "next/router";import React, { useCallback, useEffect, useState } from "react";+import {+ lockerColorSx,+ lockerTextBodyBoldSx,+ lockerTextBodySx,+ lockerTextMiniSx,+} from "./locker-tokens";+import { LockerConfirmDialog } from "./LockerConfirmDialog";+import { LockerSidebarCardButton } from "./LockerSidebarCardButton";import {LockerTitledNestedSidebarDrawer,type LockerNestedSidebarDrawerVisibilityProps,@@ -72,6 +82,10 @@ const TwoFactorContents: React.FC<TwoFactorContentsProps> = ({>();const [isLoading, setIsLoading] = useState(false);const [error, setError] = useState<string | undefined>();+ const [confirmation, setConfirmation] = useState<+ "disable" | "reconfigure"+ >();+ const [isDisabling, setIsDisabling] = useState(false);const handleError = useCallback((e: unknown, message: string) => {@@ -106,49 +120,34 @@ const TwoFactorContents: React.FC<TwoFactorContentsProps> = ({}, [handleError]);useEffect(() => {- if (!open) return;+ if (!open) {+ setConfirmation(undefined);+ return;+ }setIsTwoFactorEnabled(undefined);void refreshStatus();}, [open, refreshStatus]);- const confirmDisable = () =>- showMiniDialog({- title: t("disable_two_factor"),- message: t("disable_two_factor_message"),- continue: {- text: t("disable"),- color: "critical",- action: async () => {- setError(undefined);- try {- await disableTwoFactor();- onRootClose();- } catch (e) {- log.error("Failed to disable two-factor", e);- if (isHTTP401Error(e)) {- setTimeout(() => {- showMiniDialog(- sessionExpiredDialogAttributes(logout),- );- }, 0);- return;- }- throw e;- }- },- },- });-- const confirmReconfigure = () =>- showMiniDialog({- title: t("update_two_factor"),- message: t("update_two_factor_message"),- continue: {- text: t("update"),- color: "primary",- action: onConfigure,- },- });+ const handleConfirm = async () => {+ if (!confirmation || isDisabling) return;+ if (confirmation === "reconfigure") {+ setConfirmation(undefined);+ onConfigure();+ return;+ }+ setIsDisabling(true);+ setError(undefined);+ try {+ await disableTwoFactor();+ setConfirmation(undefined);+ onRootClose();+ } catch (e) {+ handleError(e, "Failed to disable two-factor");+ if (isHTTP401Error(e)) setConfirmation(undefined);+ } finally {+ setIsDisabling(false);+ }+ };if (isLoading && isTwoFactorEnabled === undefined) {return (@@ -178,13 +177,49 @@ const TwoFactorContents: React.FC<TwoFactorContentsProps> = ({);}- return isTwoFactorEnabled ? (- <ManageTwoFactor- onDisable={confirmDisable}- onReconfigure={confirmReconfigure}- />- ) : (- <SetupTwoFactor onConfigure={onConfigure} />+ return (+ <>+ {isTwoFactorEnabled ? (+ <ManageTwoFactor+ onDisable={() => {+ setError(undefined);+ setConfirmation("disable");+ }}+ onReconfigure={() => {+ setError(undefined);+ setConfirmation("reconfigure");+ }}+ />+ ) : (+ <SetupTwoFactor onConfigure={onConfigure} />+ )}+ <LockerConfirmDialog+ open={!!confirmation}+ illustration={+ confirmation === "disable"+ ? "/images/warning-red.png"+ : "/images/warning-grey.png"+ }+ title={t(+ confirmation === "disable"+ ? "disable_two_factor"+ : "update_two_factor",+ )}+ body={t(+ confirmation === "disable"+ ? "disable_two_factor_message"+ : "update_two_factor_message",+ )}+ confirmLabel={t(+ confirmation === "disable" ? "disable" : "update",+ )}+ tone={confirmation === "disable" ? "critical" : "primary"}+ loading={isDisabling}+ error={error}+ onClose={() => setConfirmation(undefined)}+ onConfirm={handleConfirm}+ />+ </>);};@@ -193,20 +228,52 @@ interface SetupTwoFactorProps {}const SetupTwoFactor: React.FC<SetupTwoFactorProps> = ({ onConfigure }) => (- <Stack sx={{ px: "16px", py: "20px", alignItems: "center" }}>- <LockIcon sx={{ fontSize: "40px", color: "text.muted" }} />+ <Stack sx={{ py: 2, alignItems: "center", gap: 3 }}>+ <Box+ sx={(theme) => ({+ width: 80,+ height: 80,+ borderRadius: "20px",+ display: "grid",+ placeItems: "center",+ ...lockerColorSx(theme, {+ backgroundColor: "fillLight",+ color: "textLight",+ }),+ })}+ >+ <LockIcon sx={{ fontSize: 32 }} />+ </Box><Typography- sx={{- color: "text.muted",+ sx={(theme) => ({+ ...lockerTextBodySx,textAlign: "center",- marginBlock: "32px 36px",- }}+ ...lockerColorSx(theme, { color: "textLight" }),+ })}>{t("two_factor_info")}</Typography>- <FocusVisibleButton color="accent" fullWidth onClick={onConfigure}>+ <Button+ variant="contained"+ color="primary"+ fullWidth+ onClick={onConfigure}+ sx={(theme) => ({+ ...lockerTextBodyBoldSx,+ minHeight: 52,+ borderRadius: "20px",+ textTransform: "none",+ ...lockerColorSx(theme, {+ backgroundColor: "primary",+ color: "specialWhite",+ }),+ "&:hover": lockerColorSx(theme, {+ backgroundColor: "primaryDark",+ }),+ })}+ >{t("enable_two_factor")}- </FocusVisibleButton>+ </Button></Stack>);@@ -219,22 +286,38 @@ const ManageTwoFactor: React.FC<ManageTwoFactorProps> = ({onDisable,onReconfigure,}) => (- <Stack sx={{ px: "16px", py: "20px", gap: "24px" }}>- <RowButtonGroup>- <RowSwitch- label={t("enabled")}- checked={true}- onClick={onDisable}- />- </RowButtonGroup>-- <Stack>- <RowButtonGroup>- <RowButton label={t("reconfigure")} onClick={onReconfigure} />- </RowButtonGroup>- <RowButtonGroupHint>- {t("reconfigure_two_factor_hint")}- </RowButtonGroupHint>- </Stack>+ <Stack sx={{ gap: 1 }}>+ <FormControlLabel+ label={t("enabled")}+ labelPlacement="start"+ control={<Switch checked onChange={onDisable} color="primary" />}+ sx={(theme) => ({+ m: 0,+ px: 1.5,+ minHeight: 54,+ borderRadius: "20px",+ justifyContent: "space-between",+ ...lockerColorSx(theme, {+ backgroundColor: "fillLight",+ color: "textBase",+ }),+ "& .MuiFormControlLabel-label": lockerTextBodySx,+ })}+ />+ <LockerSidebarCardButton+ label={t("reconfigure")}+ onClick={onReconfigure}+ endIcon={<ChevronRightIcon />}+ />+ <Typography+ sx={(theme) => ({+ ...lockerTextMiniSx,+ px: 1.5,+ mt: 0.5,+ ...lockerColorSx(theme, { color: "textLight" }),+ })}+ >+ {t("reconfigure_two_factor_hint")}+ </Typography></Stack>);