Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor(sidebar):extract-account-component

Aswin Asok4a31367c52af
diff --git a/web/apps/photos/src/components/sidebar/Sidebar.tsx b/web/apps/photos/src/components/sidebar/Sidebar.tsx
index f7cca226fa..9e6ee8c1ae 100644
--- a/web/apps/photos/src/components/sidebar/Sidebar.tsx
+++ b/web/apps/photos/src/components/sidebar/Sidebar.tsx
@@ -1,9 +1,5 @@
import { downloadAppDialogAttributes } from "@/components/utils/download";
import exportService from "@/services/export";
-import {
- generatePasskeyRecovery,
- recoveryKeyMnemonic,
-} from "@/services/recovery-key";
import { performSidebarAction as performSidebarRegistryAction } from "@/services/search/sidebar-search-registry";
import {
Delete02Icon,
@@ -19,8 +15,6 @@ import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
import NorthEastIcon from "@mui/icons-material/NorthEast";
import {
Box,
- Dialog,
- DialogContent,
Divider,
IconButton,
Link,
@@ -32,9 +26,6 @@ import {
useColorScheme,
} from "@mui/material";
import Typography from "@mui/material/Typography";
-import { RecoveryKey } from "ente-accounts/components/RecoveryKey";
-import { openAccountsManagePasskeysPage } from "ente-accounts/services/passkey";
-import { getActiveSessions } from "ente-accounts/services/sessions";
import { isDesktop } from "ente-base/app";
import { EnteLogo, EnteLogoBox } from "ente-base/components/EnteLogo";
import { LinkButton } from "ente-base/components/LinkButton";
@@ -47,15 +38,12 @@ import {
RowSwitch,
} from "ente-base/components/RowButton";
import { SpacedRow } from "ente-base/components/containers";
-import { DialogCloseIconButton } from "ente-base/components/mui/DialogCloseIconButton";
-import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import {
SidebarDrawer,
TitledNestedSidebarDrawer,
type NestedSidebarDrawerVisibilityProps,
} from "ente-base/components/mui/SidebarDrawer";
-import { useIsSmallWidth } from "ente-base/components/utils/hooks";
import {
useModalVisibility,
type ModalVisibilityProps,
@@ -77,18 +65,13 @@ import {
isHLSGenerationSupported,
toggleHLSGeneration,
} from "ente-gallery/services/video";
-import { formattedStorageByteSize } from "ente-gallery/utils/units";
import {
useAppLockSnapshot,
useHLSGenerationStatusSnapshot,
useSettingsSnapshot,
useUserDetailsSnapshot,
} from "ente-new/photos/components/utils/use-snapshot";
-import {
- reauthenticateWithAppLock,
- suppressAppLockRefreshFromSessionForTrustedReload,
- suppressAutoLockOnBlurForTrustedPrompt,
-} from "ente-new/photos/services/app-lock";
+import { suppressAppLockRefreshFromSessionForTrustedReload } from "ente-new/photos/services/app-lock";
import {
PseudoCollectionID,
type CollectionSummaries,
@@ -101,25 +84,19 @@ import {
updateCustomDomain,
updateMapEnabled,
} from "ente-new/photos/services/settings";
-import { get2FAStatus } from "ente-new/photos/services/user";
import {
- familyAdminEmail,
- familyMemberStorageLimit,
hasExceededStorageQuota,
isFamilyAdmin,
isPartOfFamily,
- isPartOfFamilyWithOtherMembers,
isSubscriptionActive,
isSubscriptionActivePaid,
isSubscriptionCancelled,
isSubscriptionFree,
isSubscriptionPastDue,
isSubscriptionStripe,
- leaveFamily,
pullUserDetails,
redirectToCustomerPortal,
userDetailsAddOnBonuses,
- userDetailsSnapshot,
type UserDetails,
} from "ente-new/photos/services/user-details";
import { usePhotosAppContext } from "ente-new/photos/types/context";
@@ -140,10 +117,10 @@ import { Trans } from "react-i18next";
import { DropdownInput } from "./DropdownInput";
import { ReferralSettings } from "./ReferralSettings";
import { WatchFolder } from "./WatchFolder";
-import { DeleteAccount } from "./account/DeleteAccount";
-import { SessionsSettings } from "./account/SessionsSettings";
import { SubscriptionCard } from "./account/SubscriptionCard";
-import { TwoFactorSettings } from "./account/TwoFactorSettings";
+import { Account, type AccountAction } from "./accounts/Account";
+import { ManageMemberSubscription } from "./accounts/ManageMemberSubscription";
+import { openManageSubscription } from "./accounts/subscription";
import { AppLockSettings } from "./preferences/AppLockSettings";
import { MLSettings } from "./preferences/MLSettings";
@@ -161,19 +138,6 @@ type SidebarProps = ModalVisibilityProps & {
onAuthenticateUser: () => Promise<boolean>;
};
-type AccountAction = Extract<
- SidebarActionID,
- | "account.subscription"
- | "account.recoveryKey"
- | "account.twoFactor"
- | "account.twoFactor.reconfigure"
- | "account.passkeys"
- | "account.changePassword"
- | "account.changeEmail"
- | "account.deleteAccount"
- | "account.sessions"
->;
-
type PreferencesAction = Extract<
SidebarActionID,
| "preferences.language"
@@ -399,35 +363,6 @@ interface SectionProps {
onCloseSidebar: SidebarProps["onClose"];
}
-const openManageSubscription = ({
- userDetails,
- showManageMemberSubscription,
- onShowPlanSelector,
-}: {
- userDetails: UserDetails | undefined;
- showManageMemberSubscription: () => void;
- onShowPlanSelector: () => void;
-}) => {
- if (
- userDetails &&
- isPartOfFamily(userDetails) &&
- !isFamilyAdmin(userDetails)
- ) {
- showManageMemberSubscription();
- } else if (
- userDetails &&
- isSubscriptionStripe(userDetails.subscription) &&
- isSubscriptionPastDue(userDetails.subscription)
- ) {
- // TODO: This makes an API request, so the UI should indicate the await.
- //
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
- redirectToCustomerPortal();
- } else {
- onShowPlanSelector();
- }
-};
-
const HeaderSection: React.FC<SectionProps> = ({ onCloseSidebar }) => (
<SpacedRow sx={{ mt: "6px", pl: "12px" }}>
<EnteLogoBox>
@@ -601,69 +536,6 @@ const SubscriptionStatus: React.FC<SubscriptionStatusProps> = ({
);
};
-type ManageMemberSubscriptionProps = ModalVisibilityProps & {
- userDetails: UserDetails;
-};
-
-const ManageMemberSubscription: React.FC<ManageMemberSubscriptionProps> = ({
- open,
- onClose,
- userDetails,
-}) => {
- const { showMiniDialog } = useBaseContext();
- const fullScreen = useIsSmallWidth();
-
- const confirmLeaveFamily = () =>
- showMiniDialog({
- title: t("leave_family_plan"),
- message: t("leave_family_plan_confirm"),
- continue: {
- text: t("leave"),
- color: "critical",
- action: leaveFamily,
- },
- });
-
- return (
- <Dialog {...{ open, onClose, fullScreen }} maxWidth="xs" fullWidth>
- <SpacedRow sx={{ p: "20px 8px 12px 16px" }}>
- <Stack>
- <Typography variant="h3">{t("subscription")}</Typography>
- <Typography sx={{ color: "text.muted" }}>
- {t("family_plan")}
- </Typography>
- </Stack>
- <DialogCloseIconButton {...{ onClose }} />
- </SpacedRow>
- <DialogContent>
- <Stack sx={{ alignItems: "center", mx: 2 }}>
- <Box sx={{ mb: 4 }}>
- <Typography sx={{ color: "text.muted" }}>
- {t("subscription_info_family")}
- </Typography>
- <Typography>
- {familyAdminEmail(userDetails) ?? ""}
- </Typography>
- </Box>
- <img
- height={256}
- src="/images/family-plan/1x.png"
- srcSet="/images/family-plan/2x.png 2x, /images/family-plan/3x.png 3x"
- />
- <FocusVisibleButton
- fullWidth
- variant="outlined"
- color="critical"
- onClick={confirmLeaveFamily}
- >
- {t("leave_family_plan")}
- </FocusVisibleButton>
- </Stack>
- </DialogContent>
- </Dialog>
- );
-};
-
type ShortcutSectionProps = SectionProps &
Pick<
SidebarProps,
@@ -939,331 +811,6 @@ const InfoSection: React.FC = () => {
);
};
-type AccountProps = NestedSidebarDrawerVisibilityProps &
- Pick<SidebarProps, "onAuthenticateUser" | "onShowPlanSelector"> & {
- pendingAction?: AccountAction;
- onActionHandled?: (action?: AccountAction) => void;
- };
-
-const Account: React.FC<AccountProps> = ({
- open,
- onClose,
- onRootClose,
- onAuthenticateUser,
- onShowPlanSelector,
- pendingAction,
- onActionHandled,
-}) => {
- const { showMiniDialog } = useBaseContext();
- const userDetails = useUserDetailsSnapshot();
- const [twoFactorEnabled, setTwoFactorEnabled] = useState<boolean>();
- const [sessionCount, setSessionCount] = useState<number>();
-
- const accountLabel = (label: string, subtext?: string) => (
- <Stack
- sx={{
- gap: 0.5,
- minWidth: 0,
- alignItems: "flex-start",
- textAlign: "left",
- }}
- >
- <Typography sx={{ fontWeight: "medium" }}>{label}</Typography>
- {subtext && (
- <Typography
- variant="small"
- sx={{
- color: "text.muted",
- fontWeight: 400,
- overflowWrap: "anywhere",
- }}
- >
- {subtext}
- </Typography>
- )}
- </Stack>
- );
- let planSubtext: string | undefined;
- if (userDetails) {
- let storage =
- userDetails.subscription.storage + userDetails.storageBonus;
-
- if (isPartOfFamilyWithOtherMembers(userDetails)) {
- const memberLimit = familyMemberStorageLimit(userDetails);
- const familyStorage =
- (userDetails.familyData?.storage ?? 0) +
- userDetails.storageBonus;
- storage = memberLimit ?? familyStorage;
- }
-
- const period = userDetails.subscription.period;
- const canShowBillingPeriod =
- !isSubscriptionFree(userDetails.subscription) &&
- (!isPartOfFamily(userDetails) || isFamilyAdmin(userDetails));
- const billingLabel =
- canShowBillingPeriod && period
- ? t(period == "year" ? "yearly" : "monthly")
- : undefined;
-
- planSubtext = [formattedStorageByteSize(storage), billingLabel]
- .filter(Boolean)
- .join(" Β· ");
- }
-
- const router = useRouter();
-
- const {
- show: showManageMemberSubscription,
- props: manageMemberSubscriptionVisibilityProps,
- } = useModalVisibility();
- const { show: showRecoveryKey, props: recoveryKeyVisibilityProps } =
- useModalVisibility();
- const { show: showTwoFactor, props: twoFactorVisibilityProps } =
- useModalVisibility();
- const { show: showSessions, props: sessionsVisibilityProps } =
- useModalVisibility();
- const { show: showDeleteAccount, props: deleteAccountVisibilityProps } =
- useModalVisibility();
-
- useEffect(() => {
- if (
- !open ||
- twoFactorVisibilityProps.open ||
- sessionsVisibilityProps.open
- )
- return;
- let cancelled = false;
- void Promise.all([
- get2FAStatus().catch(() => undefined),
- getActiveSessions().catch(() => undefined),
- ]).then(([twoFactor, sessions]) => {
- if (cancelled) return;
- setTwoFactorEnabled(twoFactor);
- setSessionCount(sessions?.length);
- });
- return () => {
- cancelled = true;
- };
- }, [open, twoFactorVisibilityProps.open, sessionsVisibilityProps.open]);
-
- const isNonAdminFamilyMember = useMemo(
- () =>
- userDetails &&
- isPartOfFamily(userDetails) &&
- !isFamilyAdmin(userDetails),
- [userDetails],
- );
-
- const handleRootClose = () => {
- onClose();
- onRootClose();
- };
-
- const handleChangePassword = useCallback(async () => {
- if (!(await onAuthenticateUser())) return;
- void router.push("/change-password");
- }, [onAuthenticateUser, router]);
- const handleChangeEmail = useCallback(() => {
- void router.push("/change-email");
- }, [router]);
-
- const handleManageSubscription = useCallback(() => {
- void (async () => {
- if (!userDetails) {
- await pullUserDetails();
- }
-
- const resolvedUserDetails = userDetails ?? userDetailsSnapshot();
- if (!resolvedUserDetails) return;
-
- openManageSubscription({
- userDetails: resolvedUserDetails,
- showManageMemberSubscription,
- onShowPlanSelector,
- });
- })();
- }, [onShowPlanSelector, showManageMemberSubscription, userDetails]);
-
- const handleRecoveryKey = useCallback(async () => {
- if (isDesktop) {
- const reauthResult = await reauthenticateWithAppLock();
- if (reauthResult === "cancelled") return;
- if (reauthResult === "fallback" && !(await onAuthenticateUser()))
- return;
- } else {
- if (!(await onAuthenticateUser())) return;
- }
- showRecoveryKey();
- }, [onAuthenticateUser, showRecoveryKey]);
-
- const handlePasskeys = useCallback(async () => {
- onRootClose();
- if (isDesktop) {
- suppressAutoLockOnBlurForTrustedPrompt();
- }
- await openAccountsManagePasskeysPage(generatePasskeyRecovery);
- }, [onRootClose]);
-
- const handleActiveSessions = useCallback(async () => {
- if (isDesktop) {
- const reauthResult = await reauthenticateWithAppLock();
- if (reauthResult === "cancelled") return;
- if (reauthResult === "fallback" && !(await onAuthenticateUser()))
- return;
- } else {
- if (!(await onAuthenticateUser())) return;
- }
- showSessions();
- }, [onAuthenticateUser, showSessions]);
-
- const handleDeleteAccount = useCallback(() => {
- showDeleteAccount();
- }, [showDeleteAccount]);
-
- useEffect(() => {
- if (!open || !pendingAction) return;
- switch (pendingAction) {
- case "account.subscription":
- handleManageSubscription();
- break;
- case "account.recoveryKey":
- void handleRecoveryKey();
- break;
- case "account.twoFactor.reconfigure":
- case "account.twoFactor":
- showTwoFactor();
- break;
- case "account.passkeys":
- void handlePasskeys();
- break;
- case "account.changePassword":
- void handleChangePassword();
- break;
- case "account.changeEmail":
- handleChangeEmail();
- break;
- case "account.deleteAccount":
- handleDeleteAccount();
- break;
- case "account.sessions":
- void handleActiveSessions();
- break;
- }
- onActionHandled?.();
- }, [
- handleManageSubscription,
- handleActiveSessions,
- handleChangeEmail,
- handleChangePassword,
- handleDeleteAccount,
- handleRecoveryKey,
- handlePasskeys,
- open,
- onActionHandled,
- pendingAction,
- showTwoFactor,
- ]);
-
- return (
- <TitledNestedSidebarDrawer
- {...{ open, onClose }}
- onRootClose={handleRootClose}
- title={t("account")}
- >
- <Stack sx={{ px: 2, py: 1, gap: 3 }}>
- <RowButtonGroup>
- <RowButton
- label={accountLabel(t("manage_plan"), planSubtext)}
- onClick={handleManageSubscription}
- />
- </RowButtonGroup>
- <RowButtonGroup>
- <RowButton
- label={t("recovery_key")}
- onClick={() => void handleRecoveryKey()}
- />
- </RowButtonGroup>
- <RowButtonGroup>
- <RowButton
- label={accountLabel(
- t("two_factor"),
- twoFactorEnabled === undefined
- ? undefined
- : t(
- twoFactorEnabled
- ? "account_two_factor_on"
- : "account_two_factor_off",
- ),
- )}
- onClick={showTwoFactor}
- />
- <RowButtonDivider />
- <RowButton
- label={accountLabel(t("passkeys"))}
- onClick={handlePasskeys}
- />
- <RowButtonDivider />
- <RowButton
- label={accountLabel(
- t("active_sessions"),
- sessionCount === undefined
- ? undefined
- : t("account_sessions", {
- count: sessionCount,
- }),
- )}
- onClick={handleActiveSessions}
- />
- </RowButtonGroup>
- <RowButtonGroup>
- <RowButton
- label={t("change_password")}
- onClick={handleChangePassword}
- />
- <RowButtonDivider />
- <RowButton
- label={accountLabel(
- t("change_email"),
- userDetails?.email,
- )}
- onClick={handleChangeEmail}
- />
- </RowButtonGroup>
- <RowButtonGroup>
- <RowButton
- color="critical"
- label={t("delete_account")}
- onClick={handleDeleteAccount}
- />
- </RowButtonGroup>
- </Stack>
- <RecoveryKey
- {...recoveryKeyVisibilityProps}
- getRecoveryKeyMnemonic={recoveryKeyMnemonic}
- {...{ showMiniDialog }}
- />
- {isNonAdminFamilyMember && userDetails && (
- <ManageMemberSubscription
- {...manageMemberSubscriptionVisibilityProps}
- {...{ userDetails }}
- />
- )}
- <TwoFactorSettings
- {...twoFactorVisibilityProps}
- onRootClose={onRootClose}
- />
- <SessionsSettings
- {...sessionsVisibilityProps}
- onRootClose={onRootClose}
- />
- <DeleteAccount
- {...deleteAccountVisibilityProps}
- {...{ onAuthenticateUser }}
- />
- </TitledNestedSidebarDrawer>
- );
-};
-
const DesktopAppLockSettings: React.FC<
Pick<SidebarProps, "onAuthenticateUser"> &
Pick<NestedSidebarDrawerVisibilityProps, "onRootClose">
diff --git a/web/apps/photos/src/components/sidebar/accounts/Account.tsx b/web/apps/photos/src/components/sidebar/accounts/Account.tsx
new file mode 100644
index 0000000000..264903066a
--- /dev/null
+++ b/web/apps/photos/src/components/sidebar/accounts/Account.tsx
@@ -0,0 +1,385 @@
+import {
+ generatePasskeyRecovery,
+ recoveryKeyMnemonic,
+} from "@/services/recovery-key";
+import { Stack } from "@mui/material";
+import Typography from "@mui/material/Typography";
+import { RecoveryKey } from "ente-accounts/components/RecoveryKey";
+import { openAccountsManagePasskeysPage } from "ente-accounts/services/passkey";
+import { getActiveSessions } from "ente-accounts/services/sessions";
+import { isDesktop } from "ente-base/app";
+import {
+ RowButton,
+ RowButtonDivider,
+ RowButtonGroup,
+} from "ente-base/components/RowButton";
+import {
+ TitledNestedSidebarDrawer,
+ type NestedSidebarDrawerVisibilityProps,
+} from "ente-base/components/mui/SidebarDrawer";
+import { useModalVisibility } from "ente-base/components/utils/modal";
+import { useBaseContext } from "ente-base/context";
+import { formattedStorageByteSize } from "ente-gallery/utils/units";
+import { useUserDetailsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
+import {
+ reauthenticateWithAppLock,
+ suppressAutoLockOnBlurForTrustedPrompt,
+} from "ente-new/photos/services/app-lock";
+import type { SidebarActionID } from "ente-new/photos/services/search/types";
+import { get2FAStatus } from "ente-new/photos/services/user";
+import {
+ familyMemberStorageLimit,
+ isFamilyAdmin,
+ isPartOfFamily,
+ isPartOfFamilyWithOtherMembers,
+ isSubscriptionFree,
+ pullUserDetails,
+ userDetailsSnapshot,
+} from "ente-new/photos/services/user-details";
+import { t } from "i18next";
+import { useRouter } from "next/router";
+import React, { useCallback, useEffect, useMemo, useState } from "react";
+import { DeleteAccount } from "../account/DeleteAccount";
+import { SessionsSettings } from "../account/SessionsSettings";
+import { TwoFactorSettings } from "../account/TwoFactorSettings";
+import { ManageMemberSubscription } from "./ManageMemberSubscription";
+import { openManageSubscription } from "./subscription";
+
+export type AccountAction = Extract<
+ SidebarActionID,
+ | "account.subscription"
+ | "account.recoveryKey"
+ | "account.twoFactor"
+ | "account.twoFactor.reconfigure"
+ | "account.passkeys"
+ | "account.changePassword"
+ | "account.changeEmail"
+ | "account.deleteAccount"
+ | "account.sessions"
+>;
+
+type AccountProps = NestedSidebarDrawerVisibilityProps & {
+ onAuthenticateUser: () => Promise<boolean>;
+ onShowPlanSelector: () => void;
+ pendingAction?: AccountAction;
+ onActionHandled?: (action?: AccountAction) => void;
+};
+
+export const Account: React.FC<AccountProps> = ({
+ open,
+ onClose,
+ onRootClose,
+ onAuthenticateUser,
+ onShowPlanSelector,
+ pendingAction,
+ onActionHandled,
+}) => {
+ const { showMiniDialog } = useBaseContext();
+ const userDetails = useUserDetailsSnapshot();
+ const [twoFactorEnabled, setTwoFactorEnabled] = useState<boolean>();
+ const [sessionCount, setSessionCount] = useState<number>();
+
+ const accountLabel = (label: string, subtext?: string) => (
+ <Stack
+ sx={{
+ gap: 0.5,
+ minWidth: 0,
+ alignItems: "flex-start",
+ textAlign: "left",
+ }}
+ >
+ <Typography sx={{ fontWeight: "medium" }}>{label}</Typography>
+ {subtext && (
+ <Typography
+ variant="small"
+ sx={{
+ color: "text.muted",
+ fontWeight: 400,
+ overflowWrap: "anywhere",
+ }}
+ >
+ {subtext}
+ </Typography>
+ )}
+ </Stack>
+ );
+ let planSubtext: string | undefined;
+ if (userDetails) {
+ let storage =
+ userDetails.subscription.storage + userDetails.storageBonus;
+
+ if (isPartOfFamilyWithOtherMembers(userDetails)) {
+ const memberLimit = familyMemberStorageLimit(userDetails);
+ const familyStorage =
+ (userDetails.familyData?.storage ?? 0) +
+ userDetails.storageBonus;
+ storage = memberLimit ?? familyStorage;
+ }
+
+ const period = userDetails.subscription.period;
+ const canShowBillingPeriod =
+ !isSubscriptionFree(userDetails.subscription) &&
+ (!isPartOfFamily(userDetails) || isFamilyAdmin(userDetails));
+ const billingLabel =
+ canShowBillingPeriod && period
+ ? t(period == "year" ? "yearly" : "monthly")
+ : undefined;
+
+ planSubtext = [formattedStorageByteSize(storage), billingLabel]
+ .filter(Boolean)
+ .join(" Β· ");
+ }
+
+ const router = useRouter();
+
+ const {
+ show: showManageMemberSubscription,
+ props: manageMemberSubscriptionVisibilityProps,
+ } = useModalVisibility();
+ const { show: showRecoveryKey, props: recoveryKeyVisibilityProps } =
+ useModalVisibility();
+ const { show: showTwoFactor, props: twoFactorVisibilityProps } =
+ useModalVisibility();
+ const { show: showSessions, props: sessionsVisibilityProps } =
+ useModalVisibility();
+ const { show: showDeleteAccount, props: deleteAccountVisibilityProps } =
+ useModalVisibility();
+
+ useEffect(() => {
+ if (
+ !open ||
+ twoFactorVisibilityProps.open ||
+ sessionsVisibilityProps.open
+ )
+ return;
+ let cancelled = false;
+ void Promise.all([
+ get2FAStatus().catch(() => undefined),
+ getActiveSessions().catch(() => undefined),
+ ]).then(([twoFactor, sessions]) => {
+ if (cancelled) return;
+ setTwoFactorEnabled(twoFactor);
+ setSessionCount(sessions?.length);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [open, twoFactorVisibilityProps.open, sessionsVisibilityProps.open]);
+
+ const isNonAdminFamilyMember = useMemo(
+ () =>
+ userDetails &&
+ isPartOfFamily(userDetails) &&
+ !isFamilyAdmin(userDetails),
+ [userDetails],
+ );
+
+ const handleRootClose = () => {
+ onClose();
+ onRootClose();
+ };
+
+ const handleChangePassword = useCallback(async () => {
+ if (!(await onAuthenticateUser())) return;
+ void router.push("/change-password");
+ }, [onAuthenticateUser, router]);
+ const handleChangeEmail = useCallback(() => {
+ void router.push("/change-email");
+ }, [router]);
+
+ const handleManageSubscription = useCallback(() => {
+ void (async () => {
+ if (!userDetails) {
+ await pullUserDetails();
+ }
+
+ const resolvedUserDetails = userDetails ?? userDetailsSnapshot();
+ if (!resolvedUserDetails) return;
+
+ openManageSubscription({
+ userDetails: resolvedUserDetails,
+ showManageMemberSubscription,
+ onShowPlanSelector,
+ });
+ })();
+ }, [onShowPlanSelector, showManageMemberSubscription, userDetails]);
+
+ const handleRecoveryKey = useCallback(async () => {
+ if (isDesktop) {
+ const reauthResult = await reauthenticateWithAppLock();
+ if (reauthResult === "cancelled") return;
+ if (reauthResult === "fallback" && !(await onAuthenticateUser()))
+ return;
+ } else {
+ if (!(await onAuthenticateUser())) return;
+ }
+ showRecoveryKey();
+ }, [onAuthenticateUser, showRecoveryKey]);
+
+ const handlePasskeys = useCallback(async () => {
+ onRootClose();
+ if (isDesktop) {
+ suppressAutoLockOnBlurForTrustedPrompt();
+ }
+ await openAccountsManagePasskeysPage(generatePasskeyRecovery);
+ }, [onRootClose]);
+
+ const handleActiveSessions = useCallback(async () => {
+ if (isDesktop) {
+ const reauthResult = await reauthenticateWithAppLock();
+ if (reauthResult === "cancelled") return;
+ if (reauthResult === "fallback" && !(await onAuthenticateUser()))
+ return;
+ } else {
+ if (!(await onAuthenticateUser())) return;
+ }
+ showSessions();
+ }, [onAuthenticateUser, showSessions]);
+
+ const handleDeleteAccount = useCallback(() => {
+ showDeleteAccount();
+ }, [showDeleteAccount]);
+
+ useEffect(() => {
+ if (!open || !pendingAction) return;
+ switch (pendingAction) {
+ case "account.subscription":
+ handleManageSubscription();
+ break;
+ case "account.recoveryKey":
+ void handleRecoveryKey();
+ break;
+ case "account.twoFactor.reconfigure":
+ case "account.twoFactor":
+ showTwoFactor();
+ break;
+ case "account.passkeys":
+ void handlePasskeys();
+ break;
+ case "account.changePassword":
+ void handleChangePassword();
+ break;
+ case "account.changeEmail":
+ handleChangeEmail();
+ break;
+ case "account.deleteAccount":
+ handleDeleteAccount();
+ break;
+ case "account.sessions":
+ void handleActiveSessions();
+ break;
+ }
+ onActionHandled?.();
+ }, [
+ handleManageSubscription,
+ handleActiveSessions,
+ handleChangeEmail,
+ handleChangePassword,
+ handleDeleteAccount,
+ handleRecoveryKey,
+ handlePasskeys,
+ open,
+ onActionHandled,
+ pendingAction,
+ showTwoFactor,
+ ]);
+
+ return (
+ <TitledNestedSidebarDrawer
+ {...{ open, onClose }}
+ onRootClose={handleRootClose}
+ title={t("account")}
+ >
+ <Stack sx={{ px: 2, py: 1, gap: 3 }}>
+ <RowButtonGroup>
+ <RowButton
+ label={accountLabel(t("manage_plan"), planSubtext)}
+ onClick={handleManageSubscription}
+ />
+ </RowButtonGroup>
+ <RowButtonGroup>
+ <RowButton
+ label={t("recovery_key")}
+ onClick={() => void handleRecoveryKey()}
+ />
+ </RowButtonGroup>
+ <RowButtonGroup>
+ <RowButton
+ label={accountLabel(
+ t("two_factor"),
+ twoFactorEnabled === undefined
+ ? undefined
+ : t(
+ twoFactorEnabled
+ ? "account_two_factor_on"
+ : "account_two_factor_off",
+ ),
+ )}
+ onClick={showTwoFactor}
+ />
+ <RowButtonDivider />
+ <RowButton
+ label={accountLabel(t("passkeys"))}
+ onClick={handlePasskeys}
+ />
+ <RowButtonDivider />
+ <RowButton
+ label={accountLabel(
+ t("active_sessions"),
+ sessionCount === undefined
+ ? undefined
+ : t("account_sessions", {
+ count: sessionCount,
+ }),
+ )}
+ onClick={handleActiveSessions}
+ />
+ </RowButtonGroup>
+ <RowButtonGroup>
+ <RowButton
+ label={t("change_password")}
+ onClick={handleChangePassword}
+ />
+ <RowButtonDivider />
+ <RowButton
+ label={accountLabel(
+ t("change_email"),
+ userDetails?.email,
+ )}
+ onClick={handleChangeEmail}
+ />
+ </RowButtonGroup>
+ <RowButtonGroup>
+ <RowButton
+ color="critical"
+ label={t("delete_account")}
+ onClick={handleDeleteAccount}
+ />
+ </RowButtonGroup>
+ </Stack>
+ <RecoveryKey
+ {...recoveryKeyVisibilityProps}
+ getRecoveryKeyMnemonic={recoveryKeyMnemonic}
+ {...{ showMiniDialog }}
+ />
+ {isNonAdminFamilyMember && userDetails && (
+ <ManageMemberSubscription
+ {...manageMemberSubscriptionVisibilityProps}
+ {...{ userDetails }}
+ />
+ )}
+ <TwoFactorSettings
+ {...twoFactorVisibilityProps}
+ onRootClose={onRootClose}
+ />
+ <SessionsSettings
+ {...sessionsVisibilityProps}
+ onRootClose={onRootClose}
+ />
+ <DeleteAccount
+ {...deleteAccountVisibilityProps}
+ {...{ onAuthenticateUser }}
+ />
+ </TitledNestedSidebarDrawer>
+ );
+};
diff --git a/web/apps/photos/src/components/sidebar/accounts/ManageMemberSubscription.tsx b/web/apps/photos/src/components/sidebar/accounts/ManageMemberSubscription.tsx
new file mode 100644
index 0000000000..b810833257
--- /dev/null
+++ b/web/apps/photos/src/components/sidebar/accounts/ManageMemberSubscription.tsx
@@ -0,0 +1,76 @@
+import { Box, Dialog, DialogContent, Stack } from "@mui/material";
+import Typography from "@mui/material/Typography";
+import { SpacedRow } from "ente-base/components/containers";
+import { DialogCloseIconButton } from "ente-base/components/mui/DialogCloseIconButton";
+import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
+import { useIsSmallWidth } from "ente-base/components/utils/hooks";
+import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
+import { useBaseContext } from "ente-base/context";
+import {
+ familyAdminEmail,
+ leaveFamily,
+ type UserDetails,
+} from "ente-new/photos/services/user-details";
+import { t } from "i18next";
+import React from "react";
+
+type ManageMemberSubscriptionProps = ModalVisibilityProps & {
+ userDetails: UserDetails;
+};
+
+export const ManageMemberSubscription: React.FC<
+ ManageMemberSubscriptionProps
+> = ({ open, onClose, userDetails }) => {
+ const { showMiniDialog } = useBaseContext();
+ const fullScreen = useIsSmallWidth();
+
+ const confirmLeaveFamily = () =>
+ showMiniDialog({
+ title: t("leave_family_plan"),
+ message: t("leave_family_plan_confirm"),
+ continue: {
+ text: t("leave"),
+ color: "critical",
+ action: leaveFamily,
+ },
+ });
+
+ return (
+ <Dialog {...{ open, onClose, fullScreen }} maxWidth="xs" fullWidth>
+ <SpacedRow sx={{ p: "20px 8px 12px 16px" }}>
+ <Stack>
+ <Typography variant="h3">{t("subscription")}</Typography>
+ <Typography sx={{ color: "text.muted" }}>
+ {t("family_plan")}
+ </Typography>
+ </Stack>
+ <DialogCloseIconButton {...{ onClose }} />
+ </SpacedRow>
+ <DialogContent>
+ <Stack sx={{ alignItems: "center", mx: 2 }}>
+ <Box sx={{ mb: 4 }}>
+ <Typography sx={{ color: "text.muted" }}>
+ {t("subscription_info_family")}
+ </Typography>
+ <Typography>
+ {familyAdminEmail(userDetails) ?? ""}
+ </Typography>
+ </Box>
+ <img
+ height={256}
+ src="/images/family-plan/1x.png"
+ srcSet="/images/family-plan/2x.png 2x, /images/family-plan/3x.png 3x"
+ />
+ <FocusVisibleButton
+ fullWidth
+ variant="outlined"
+ color="critical"
+ onClick={confirmLeaveFamily}
+ >
+ {t("leave_family_plan")}
+ </FocusVisibleButton>
+ </Stack>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/web/apps/photos/src/components/sidebar/accounts/subscription.ts b/web/apps/photos/src/components/sidebar/accounts/subscription.ts
new file mode 100644
index 0000000000..9bf8b7606f
--- /dev/null
+++ b/web/apps/photos/src/components/sidebar/accounts/subscription.ts
@@ -0,0 +1,37 @@
+import {
+ isFamilyAdmin,
+ isPartOfFamily,
+ isSubscriptionPastDue,
+ isSubscriptionStripe,
+ redirectToCustomerPortal,
+ type UserDetails,
+} from "ente-new/photos/services/user-details";
+
+export const openManageSubscription = ({
+ userDetails,
+ showManageMemberSubscription,
+ onShowPlanSelector,
+}: {
+ userDetails: UserDetails | undefined;
+ showManageMemberSubscription: () => void;
+ onShowPlanSelector: () => void;
+}) => {
+ if (
+ userDetails &&
+ isPartOfFamily(userDetails) &&
+ !isFamilyAdmin(userDetails)
+ ) {
+ showManageMemberSubscription();
+ } else if (
+ userDetails &&
+ isSubscriptionStripe(userDetails.subscription) &&
+ isSubscriptionPastDue(userDetails.subscription)
+ ) {
+ // TODO: This makes an API request, so the UI should indicate the await.
+ //
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
+ redirectToCustomerPortal();
+ } else {
+ onShowPlanSelector();
+ }
+};