From 9ce0b43bfeb6eb90e88451b01e29cd4fb9f81311 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 20 Feb 2025 18:05:19 +0530 Subject: [PATCH] del 1 --- ...leteAccountModal.tsx => DeleteAccount.tsx} | 21 ++++++++++++------- web/apps/photos/src/components/Sidebar.tsx | 2 +- web/apps/photos/src/pages/gallery.tsx | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) rename web/apps/photos/src/components/{DeleteAccountModal.tsx => DeleteAccount.tsx} (95%) diff --git a/web/apps/photos/src/components/DeleteAccountModal.tsx b/web/apps/photos/src/components/DeleteAccount.tsx similarity index 95% rename from web/apps/photos/src/components/DeleteAccountModal.tsx rename to web/apps/photos/src/components/DeleteAccount.tsx index 8e195fe649..3fadc1354c 100644 --- a/web/apps/photos/src/components/DeleteAccountModal.tsx +++ b/web/apps/photos/src/components/DeleteAccount.tsx @@ -24,8 +24,7 @@ import { } from "@mui/material"; import { Formik, type FormikHelpers } from "formik"; import { t } from "i18next"; -import { GalleryContext } from "pages/gallery"; -import React, { useContext, useRef, useState } from "react"; +import React, { useRef, useState } from "react"; import { Trans } from "react-i18next"; import { deleteAccount, getAccountDeleteChallenge } from "services/userService"; import * as Yup from "yup"; @@ -35,13 +34,23 @@ interface FormValues { feedback: string; } -const DeleteAccountModal: React.FC = ({ +type DeleteAccountProps = ModalVisibilityProps & { + /** + * Called when the user should be authenticated again. + * + * Account deletion only proceeds if the promise returned by this function + * is fulfilled. + */ + onAuthenticateUser: () => Promise; +}; + +export const DeleteAccount: React.FC = ({ open, onClose, + onAuthenticateUser, }) => { const { logout, showMiniDialog } = useBaseContext(); const { onGenericError } = usePhotosAppContext(); - const { authenticateUser } = useContext(GalleryContext); const [loading, setLoading] = useState(false); const deleteAccountChallenge = useRef(undefined); @@ -76,7 +85,7 @@ const DeleteAccountModal: React.FC = ({ deleteAccountChallenge.current = deleteChallengeResponse.encryptedChallenge; if (deleteChallengeResponse.allowDelete) { - authenticateUser(confirmAccountDeletion); + onAuthenticateUser().then(confirmAccountDeletion); } else { askToMailForDeletion(); } @@ -213,8 +222,6 @@ const DeleteAccountModal: React.FC = ({ ); }; -export default DeleteAccountModal; - /** * All of these must have a corresponding localized string nested under the * "delete_reason" key. diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx index c85b7df42e..b5fddbc168 100644 --- a/web/apps/photos/src/components/Sidebar.tsx +++ b/web/apps/photos/src/components/Sidebar.tsx @@ -109,7 +109,7 @@ import { useColorScheme, } from "@mui/material"; import Typography from "@mui/material/Typography"; -import DeleteAccountModal from "components/DeleteAccountModal"; +import DeleteAccountModal from "components/DeleteAccount"; import { WatchFolder } from "components/WatchFolder"; import { t } from "i18next"; import { useRouter } from "next/router"; diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 1d0b1966e3..04fd8e198c 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -216,6 +216,7 @@ const Page: React.FC = () => { onAuthenticateCallback.current = callback; setAuthenticateUserModalView(true); }; + const closeAuthenticateUserModal = () => setAuthenticateUserModalView(false);