Skip to content

armgit / ente

Public Imported from GitHub
0

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

Inline

Manav Rathi258d1768fd9b
diff --git a/web/apps/photos/src/components/TwoFactor/Modal/Manage.tsx b/web/apps/photos/src/components/TwoFactor/Modal/Manage.tsx
deleted file mode 100644
index 241164653f..0000000000
--- a/web/apps/photos/src/components/TwoFactor/Modal/Manage.tsx
+++ /dev/null
@@ -1,112 +0,0 @@
-import { t } from "i18next";
-import { useContext } from "react";
-
-import { disableTwoFactor } from "@/accounts/api/user";
-import { AppContext } from "@/new/photos/types/context";
-import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
-import { LS_KEYS, getData, setLSUser } from "@ente/shared/storage/localStorage";
-import { Button, Grid } from "@mui/material";
-import router from "next/router";
-
-interface Iprops {
- closeDialog: () => void;
-}
-
-export default function TwoFactorModalManageSection(props: Iprops) {
- const { closeDialog } = props;
- const { setDialogMessage } = useContext(AppContext);
-
- const warnTwoFactorDisable = async () => {
- setDialogMessage({
- title: t("DISABLE_TWO_FACTOR"),
-
- content: t("DISABLE_TWO_FACTOR_MESSAGE"),
- close: { text: t("cancel") },
- proceed: {
- variant: "critical",
- text: t("disable"),
- action: twoFactorDisable,
- },
- });
- };
-
- const twoFactorDisable = async () => {
- try {
- await disableTwoFactor();
- await setLSUser({
- ...getData(LS_KEYS.USER),
- isTwoFactorEnabled: false,
- });
- closeDialog();
- } catch (e) {
- setDialogMessage({
- title: t("TWO_FACTOR_DISABLE_FAILED"),
- close: {},
- });
- }
- };
-
- const warnTwoFactorReconfigure = async () => {
- setDialogMessage({
- title: t("UPDATE_TWO_FACTOR"),
-
- content: t("UPDATE_TWO_FACTOR_MESSAGE"),
- close: { text: t("cancel") },
- proceed: {
- variant: "accent",
- text: t("UPDATE"),
- action: reconfigureTwoFactor,
- },
- });
- };
-
- const reconfigureTwoFactor = async () => {
- closeDialog();
- router.push(PAGES.TWO_FACTOR_SETUP);
- };
-
- return (
- <>
- <Grid
- mb={1.5}
- rowSpacing={1}
- container
- alignItems="center"
- justifyContent="center"
- >
- <Grid item sm={9} xs={12}>
- {t("UPDATE_TWO_FACTOR_LABEL")}
- </Grid>
- <Grid item sm={3} xs={12}>
- <Button
- color={"accent"}
- onClick={warnTwoFactorReconfigure}
- size="large"
- >
- {t("reconfigure")}
- </Button>
- </Grid>
- </Grid>
- <Grid
- rowSpacing={1}
- container
- alignItems="center"
- justifyContent="center"
- >
- <Grid item sm={9} xs={12}>
- {t("DISABLE_TWO_FACTOR_LABEL")}{" "}
- </Grid>
-
- <Grid item sm={3} xs={12}>
- <Button
- color="critical"
- onClick={warnTwoFactorDisable}
- size="large"
- >
- {t("disable")}
- </Button>
- </Grid>
- </Grid>
- </>
- );
-}
diff --git a/web/apps/photos/src/components/TwoFactor/Modal/Setup.tsx b/web/apps/photos/src/components/TwoFactor/Modal/Setup.tsx
deleted file mode 100644
index dbe724b469..0000000000
--- a/web/apps/photos/src/components/TwoFactor/Modal/Setup.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
-import LockIcon from "@mui/icons-material/Lock";
-import { t } from "i18next";
-import { useRouter } from "next/router";
-
-import { VerticallyCentered } from "@ente/shared/components/Container";
-import { Button, Typography } from "@mui/material";
-
-interface Iprops {
- closeDialog: () => void;
-}
-
-export default function TwoFactorModalSetupSection({ closeDialog }: Iprops) {
- const router = useRouter();
- const redirectToTwoFactorSetup = () => {
- closeDialog();
- router.push(PAGES.TWO_FACTOR_SETUP);
- };
-
- return (
- <VerticallyCentered sx={{ mb: 2 }}>
- <LockIcon sx={{ fontSize: (theme) => theme.spacing(5), mb: 2 }} />
- <Typography mb={4}>{t("TWO_FACTOR_INFO")}</Typography>
- <Button
- variant="contained"
- color="accent"
- size="large"
- onClick={redirectToTwoFactorSetup}
- >
- {t("ENABLE_TWO_FACTOR")}
- </Button>
- </VerticallyCentered>
- );
-}
diff --git a/web/apps/photos/src/components/TwoFactor/Modal/index.tsx b/web/apps/photos/src/components/TwoFactor/Modal/index.tsx
index da65c7e73b..69afd8fcbc 100644
--- a/web/apps/photos/src/components/TwoFactor/Modal/index.tsx
+++ b/web/apps/photos/src/components/TwoFactor/Modal/index.tsx
@@ -1,12 +1,23 @@
+import { disableTwoFactor } from "@/accounts/api/user";
import type { ModalVisibilityProps } from "@/base/components/utils/modal";
+import { AppContext } from "@/new/photos/types/context";
+import { VerticallyCentered } from "@ente/shared/components/Container";
import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";
+import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
import { LS_KEYS, getData, setLSUser } from "@ente/shared/storage/localStorage";
-import { Dialog, DialogContent, styled } from "@mui/material";
+import LockIcon from "@mui/icons-material/Lock";
+import {
+ Button,
+ Dialog,
+ DialogContent,
+ Grid,
+ Typography,
+ styled,
+} from "@mui/material";
import { t } from "i18next";
-import { useEffect, useState } from "react";
+import router, { useRouter } from "next/router";
+import { useContext, useEffect, useState } from "react";
import { getTwoFactorStatus } from "services/userService";
-import TwoFactorModalManageSection from "./Manage";
-import TwoFactorModalSetupSection from "./Setup";
const TwoFactorDialog = styled(Dialog)(({ theme }) => ({
"& .MuiDialogContent-root": {
@@ -66,4 +77,137 @@ function TwoFactorModal(props: Props) {
</TwoFactorDialog>
);
}
+
export default TwoFactorModal;
+
+interface TwoFactorModalSetupSectionProps {
+ closeDialog: () => void;
+}
+
+function TwoFactorModalSetupSection({
+ closeDialog,
+}: TwoFactorModalSetupSectionProps) {
+ const router = useRouter();
+ const redirectToTwoFactorSetup = () => {
+ closeDialog();
+ router.push(PAGES.TWO_FACTOR_SETUP);
+ };
+
+ return (
+ <VerticallyCentered sx={{ mb: 2 }}>
+ <LockIcon sx={{ fontSize: (theme) => theme.spacing(5), mb: 2 }} />
+ <Typography mb={4}>{t("TWO_FACTOR_INFO")}</Typography>
+ <Button
+ variant="contained"
+ color="accent"
+ size="large"
+ onClick={redirectToTwoFactorSetup}
+ >
+ {t("ENABLE_TWO_FACTOR")}
+ </Button>
+ </VerticallyCentered>
+ );
+}
+
+interface TwoFactorModalManageSectionProps {
+ closeDialog: () => void;
+}
+
+function TwoFactorModalManageSection(props: TwoFactorModalManageSectionProps) {
+ const { closeDialog } = props;
+ const { setDialogMessage } = useContext(AppContext);
+
+ const warnTwoFactorDisable = async () => {
+ setDialogMessage({
+ title: t("DISABLE_TWO_FACTOR"),
+
+ content: t("DISABLE_TWO_FACTOR_MESSAGE"),
+ close: { text: t("cancel") },
+ proceed: {
+ variant: "critical",
+ text: t("disable"),
+ action: twoFactorDisable,
+ },
+ });
+ };
+
+ const twoFactorDisable = async () => {
+ try {
+ await disableTwoFactor();
+ await setLSUser({
+ ...getData(LS_KEYS.USER),
+ isTwoFactorEnabled: false,
+ });
+ closeDialog();
+ } catch (e) {
+ setDialogMessage({
+ title: t("TWO_FACTOR_DISABLE_FAILED"),
+ close: {},
+ });
+ }
+ };
+
+ const warnTwoFactorReconfigure = async () => {
+ setDialogMessage({
+ title: t("UPDATE_TWO_FACTOR"),
+
+ content: t("UPDATE_TWO_FACTOR_MESSAGE"),
+ close: { text: t("cancel") },
+ proceed: {
+ variant: "accent",
+ text: t("UPDATE"),
+ action: reconfigureTwoFactor,
+ },
+ });
+ };
+
+ const reconfigureTwoFactor = async () => {
+ closeDialog();
+ router.push(PAGES.TWO_FACTOR_SETUP);
+ };
+
+ return (
+ <>
+ <Grid
+ mb={1.5}
+ rowSpacing={1}
+ container
+ alignItems="center"
+ justifyContent="center"
+ >
+ <Grid item sm={9} xs={12}>
+ {t("UPDATE_TWO_FACTOR_LABEL")}
+ </Grid>
+ <Grid item sm={3} xs={12}>
+ <Button
+ color={"accent"}
+ onClick={warnTwoFactorReconfigure}
+ size="large"
+ >
+ {t("reconfigure")}
+ </Button>
+ </Grid>
+ </Grid>
+ <Grid
+ rowSpacing={1}
+ container
+ alignItems="center"
+ justifyContent="center"
+ >
+ <Grid item sm={9} xs={12}>
+ {t("DISABLE_TWO_FACTOR_LABEL")}{" "}
+ </Grid>
+
+ <Grid item sm={3} xs={12}>
+ <Button
+ color="critical"
+ onClick={warnTwoFactorDisable}
+ size="large"
+ >
+ {t("disable")}
+ </Button>
+ </Grid>
+ </Grid>
+ </>
+ );
+}