Skip to content

armgit / ente

Public Imported from GitHub
0

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

wip checkpoint

Manav Rathiec1b294425ac
diff --git a/web/apps/photos/src/components/MemberSubscriptionManage.tsx b/web/apps/photos/src/components/MemberSubscriptionManage.tsx
index 7a903dac36..ce28f892c2 100644
--- a/web/apps/photos/src/components/MemberSubscriptionManage.tsx
+++ b/web/apps/photos/src/components/MemberSubscriptionManage.tsx
@@ -1,5 +1,5 @@
import { useIsSmallWidth } from "@/base/hooks";
-import { getFamilyPlanAdmin, leaveFamily } from "@/new/photos/services/plan";
+import { familyAdminEmail, leaveFamily } from "@/new/photos/services/plan";
import { AppContext } from "@/new/photos/types/context";
import {
FlexWrapper,
@@ -58,7 +58,7 @@ export function MemberSubscriptionManage({ open, userDetails, onClose }) {
{t("subscription_info_family")}
</Typography>
<Typography>
- {getFamilyPlanAdmin(userDetails)?.email}
+ {familyAdminEmail(userDetails) ?? ""}
</Typography>
</Box>
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsx
index a5165267cd..1f725c3969 100644
--- a/web/apps/photos/src/components/Sidebar/index.tsx
+++ b/web/apps/photos/src/components/Sidebar/index.tsx
@@ -18,10 +18,11 @@ import {
TRASH_SECTION,
} from "@/new/photos/services/collection";
import type { CollectionSummaries } from "@/new/photos/services/collection/ui";
-import { isFamilyAdmin, isPartOfFamily } from "@/new/photos/services/family";
import {
hasAddOnBonus,
hasExceededStorageQuota,
+ isFamilyAdmin,
+ isPartOfFamily,
isSubscriptionActive,
isSubscriptionActiveFree,
isSubscriptionActivePaid,
@@ -220,10 +221,7 @@ const SubscriptionStatus: React.FC<SubscriptionStatusProps> = ({
if (!userDetails) {
return false;
}
- if (
- isPartOfFamily(userDetails.familyData) &&
- !isFamilyAdmin(userDetails.familyData)
- ) {
+ if (isPartOfFamily(userDetails) && !isFamilyAdmin(userDetails)) {
return false;
}
if (
diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.ts
index d65ab2ef48..c3c7793024 100644
--- a/web/packages/new/photos/services/plan.ts
+++ b/web/packages/new/photos/services/plan.ts
@@ -2,11 +2,9 @@
/* eslint-disable @typescript-eslint/prefer-optional-chain */
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
-import log from "@/base/log";
import { apiURL, familyAppOrigin, paymentsAppOrigin } from "@/base/origins";
import { nullToUndefined } from "@/utils/transform";
-import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
-import type { User } from "@ente/shared/user/types";
+import { LS_KEYS, setData } from "@ente/shared/storage/localStorage";
import isElectron from "is-electron";
import { z } from "zod";
import type { BonusData, UserDetails } from "./user";
@@ -312,26 +310,19 @@ export const isPartOfFamily = (userDetails: UserDetails) =>
export const isPartOfFamilyWithOtherMembers = (userDetails: UserDetails) =>
(userDetails.familyData?.members.length ?? 0) > 1;
-export function isFamilyAdmin(userDetails: UserDetails): boolean {
- const familyAdmin: FamilyMember = getFamilyPlanAdmin(userDetails);
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- const user: User = getData(LS_KEYS.USER);
- return familyAdmin.email === user.email;
-}
+/**
+ * Return true if the user (represented by the given {@link userDetails}) is the
+ * admin for the family plan.
+ */
+export const isFamilyAdmin = (userDetails: UserDetails) =>
+ userDetails.email == familyAdminEmail(userDetails);
-export function getFamilyPlanAdmin(userDetails: UserDetails): FamilyMember {
- if (isPartOfFamily(userDetails)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
- return userDetails.familyData?.members.find((x) => x.isAdmin)!;
- } else {
- log.error(
- "invalid getFamilyPlanAdmin call - verify user is part of family plan before calling this method",
- );
- throw new Error(
- "invalid getFamilyPlanAdmin call - verify user is part of family plan before calling this method",
- );
- }
-}
+/**
+ * Return the email of the admin for the family plan, if any, that the user
+ * (represented by the given {@link userDetails}) is a part of.
+ */
+export const familyAdminEmail = (userDetails: UserDetails) =>
+ userDetails.familyData?.members.find((x) => x.isAdmin)?.email;
/**
* Return the combined usage of all the family members.