Skip to content

armgit / ente

Public Imported from GitHub
0

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

Split

Manav Rathif932a1652824
diff --git a/web/apps/photos/src/components/MemberSubscriptionManage.tsx b/web/apps/photos/src/components/MemberSubscriptionManage.tsx
index f1d0a38023..6d90b99652 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/user";
+import { getFamilyPlanAdmin, leaveFamily } from "@/new/photos/services/family";
import { AppContext } from "@/new/photos/types/context";
import {
FlexWrapper,
diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx b/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx
index db64b45375..9287c1cb39 100644
--- a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx
+++ b/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx
@@ -4,7 +4,7 @@ import type { UserDetails } from "@/new/photos/services/user";
import {
hasNonAdminFamilyMembers,
isPartOfFamily,
-} from "@/new/photos/services/user";
+} from "@/new/photos/services/family";
import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsx
index 515b4c7245..d79479badd 100644
--- a/web/apps/photos/src/components/Sidebar/index.tsx
+++ b/web/apps/photos/src/components/Sidebar/index.tsx
@@ -17,6 +17,7 @@ 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,
@@ -30,7 +31,6 @@ import {
} from "@/new/photos/services/plan";
import { isInternalUser } from "@/new/photos/services/settings";
import type { UserDetails } from "@/new/photos/services/user";
-import { isFamilyAdmin, isPartOfFamily } from "@/new/photos/services/user";
import { AppContext, useAppContext } from "@/new/photos/types/context";
import { initiateEmail, openURL } from "@/new/photos/utils/web";
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
index 1a42658ec2..63bf4eb61c 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
@@ -1,5 +1,9 @@
import { genericRetriableErrorDialogAttributes } from "@/base/components/utils/dialog";
import log from "@/base/log";
+import {
+ getTotalFamilyUsage,
+ isPartOfFamily,
+} from "@/new/photos/services/family";
import type {
Plan,
PlanPeriod,
@@ -19,12 +23,7 @@ import {
redirectToCustomerPortal,
redirectToPaymentsApp,
} from "@/new/photos/services/plan";
-import {
- BonusData,
- getTotalFamilyUsage,
- isPartOfFamily,
- UserDetails,
-} from "@/new/photos/services/user";
+import { BonusData, UserDetails } from "@/new/photos/services/user";
import { AppContext } from "@/new/photos/types/context";
import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";
import { openURL } from "@/new/photos/utils/web";
@@ -816,6 +815,7 @@ function StripeSubscriptionOptions({
close: { variant: "accent" },
});
} catch (e) {
+ console.log(e);
setDialogMessage({
title: t("error"),
content: t("SUBSCRIPTION_ACTIVATE_FAILED"),
@@ -855,6 +855,7 @@ function StripeSubscriptionOptions({
close: { variant: "accent" },
});
} catch (e) {
+ console.log(e);
setDialogMessage({
title: t("error"),
content: t("SUBSCRIPTION_CANCEL_FAILED"),
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index d3e20c5375..d27a8f904d 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -49,7 +49,7 @@ import {
} from "@/new/photos/services/search";
import type { SearchOption } from "@/new/photos/services/search/types";
import { initSettings } from "@/new/photos/services/settings";
-import { getLocalFamilyData } from "@/new/photos/services/user";
+import { getLocalFamilyData } from "@/new/photos/services/family";
import { useAppContext } from "@/new/photos/types/context";
import { splitByPredicate } from "@/utils/array";
import { ensure } from "@/utils/ensure";
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index f74992d7ce..913a534249 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -32,7 +32,7 @@ import {
import { groupFilesByCollectionID } from "@/new/photos/services/file";
import { getLocalFiles, sortFiles } from "@/new/photos/services/files";
import { updateMagicMetadata } from "@/new/photos/services/magic-metadata";
-import type { FamilyData } from "@/new/photos/services/user";
+import type { FamilyData } from "@/new/photos/services/family";
import { batch } from "@/utils/array";
import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
diff --git a/web/apps/photos/src/services/userService.ts b/web/apps/photos/src/services/userService.ts
index 6b001270f7..35769f00d6 100644
--- a/web/apps/photos/src/services/userService.ts
+++ b/web/apps/photos/src/services/userService.ts
@@ -2,7 +2,7 @@ import { putAttributes } from "@/accounts/api/user";
import log from "@/base/log";
import { apiURL, familyAppOrigin } from "@/base/origins";
import type { UserDetails } from "@/new/photos/services/user";
-import { getLocalFamilyData, isPartOfFamily } from "@/new/photos/services/user";
+import { getLocalFamilyData, isPartOfFamily } from "@/new/photos/services/family";
import { ApiError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 2f13c7e528..c204f53a53 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -28,6 +28,7 @@ import type {
CollectionSummary,
CollectionSummaryType,
} from "../../services/collection/ui";
+import type { FamilyData } from "../../services/family";
import {
createFileCollectionIDs,
getLatestVersionFiles,
@@ -40,7 +41,6 @@ import {
isPinnedCollection,
} from "../../services/magic-metadata";
import type { PeopleState, Person } from "../../services/ml/people";
-import type { FamilyData } from "../../services/user";
/**
* Specifies what the bar at the top of the gallery is displaying currently.
diff --git a/web/packages/new/photos/services/family.ts b/web/packages/new/photos/services/family.ts
new file mode 100644
index 0000000000..ffe79aa0eb
--- /dev/null
+++ b/web/packages/new/photos/services/family.ts
@@ -0,0 +1,78 @@
+import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
+import log from "@/base/log";
+import { apiURL } from "@/base/origins";
+import {
+ LS_KEYS,
+ getData,
+ removeData,
+} from "@ente/shared/storage/localStorage";
+import type { User } from "@ente/shared/user/types";
+
+export interface FamilyMember {
+ email: string;
+ usage: number;
+ id: string;
+ isAdmin: boolean;
+}
+
+export interface FamilyData {
+ storage: number;
+ expiry: number;
+ members: FamilyMember[];
+}
+
+export function getLocalFamilyData(): FamilyData {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
+ return getData(LS_KEYS.FAMILY_DATA);
+}
+
+// isPartOfFamily return true if the current user is part of some family plan
+export function isPartOfFamily(familyData: FamilyData): boolean {
+ return Boolean(
+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain, @typescript-eslint/no-unnecessary-condition
+ familyData && familyData.members && familyData.members.length > 0,
+ );
+}
+
+// hasNonAdminFamilyMembers return true if the admin user has members in his family
+export function hasNonAdminFamilyMembers(familyData: FamilyData): boolean {
+ return Boolean(isPartOfFamily(familyData) && familyData.members.length > 1);
+}
+
+export function isFamilyAdmin(familyData: FamilyData): boolean {
+ const familyAdmin: FamilyMember = getFamilyPlanAdmin(familyData);
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ const user: User = getData(LS_KEYS.USER);
+ return familyAdmin.email === user.email;
+}
+
+export function getFamilyPlanAdmin(familyData: FamilyData): FamilyMember {
+ if (isPartOfFamily(familyData)) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ return 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",
+ );
+ }
+}
+
+export function getTotalFamilyUsage(familyData: FamilyData): number {
+ return familyData.members.reduce(
+ (sum, currentMember) => sum + currentMember.usage,
+ 0,
+ );
+}
+
+export const leaveFamily = async () => {
+ ensureOk(
+ await fetch(await apiURL("/family/leave"), {
+ method: "DELETE",
+ headers: await authenticatedRequestHeaders(),
+ }),
+ );
+ removeData(LS_KEYS.FAMILY_DATA);
+};
diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.ts
index efc680273b..80b44bf8fc 100644
--- a/web/packages/new/photos/services/plan.ts
+++ b/web/packages/new/photos/services/plan.ts
@@ -6,7 +6,7 @@ import { apiURL, paymentsAppOrigin } from "@/base/origins";
import {
getTotalFamilyUsage,
isPartOfFamily,
-} from "@/new/photos/services/user";
+} from "@/new/photos/services/family";
import { nullToUndefined } from "@/utils/transform";
import { LS_KEYS, setData } from "@ente/shared/storage/localStorage";
import isElectron from "is-electron";
diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts
index 1dbe2cd652..6d62b83b08 100644
--- a/web/packages/new/photos/services/user.ts
+++ b/web/packages/new/photos/services/user.ts
@@ -1,13 +1,7 @@
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
-import log from "@/base/log";
import { apiURL } from "@/base/origins";
-import {
- LS_KEYS,
- getData,
- removeData,
-} from "@ente/shared/storage/localStorage";
-import type { User } from "@ente/shared/user/types";
import { z } from "zod";
+import type { FamilyData } from "./family";
import type { Subscription } from "./plan";
export interface Bonus {
@@ -32,75 +26,6 @@ export interface UserDetails {
bonusData?: BonusData;
}
-export interface FamilyMember {
- email: string;
- usage: number;
- id: string;
- isAdmin: boolean;
-}
-
-export interface FamilyData {
- storage: number;
- expiry: number;
- members: FamilyMember[];
-}
-
-export function getLocalFamilyData(): FamilyData {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
- return getData(LS_KEYS.FAMILY_DATA);
-}
-
-// isPartOfFamily return true if the current user is part of some family plan
-export function isPartOfFamily(familyData: FamilyData): boolean {
- return Boolean(
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain, @typescript-eslint/no-unnecessary-condition
- familyData && familyData.members && familyData.members.length > 0,
- );
-}
-
-// hasNonAdminFamilyMembers return true if the admin user has members in his family
-export function hasNonAdminFamilyMembers(familyData: FamilyData): boolean {
- return Boolean(isPartOfFamily(familyData) && familyData.members.length > 1);
-}
-
-export function isFamilyAdmin(familyData: FamilyData): boolean {
- const familyAdmin: FamilyMember = getFamilyPlanAdmin(familyData);
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- const user: User = getData(LS_KEYS.USER);
- return familyAdmin.email === user.email;
-}
-
-export function getFamilyPlanAdmin(familyData: FamilyData): FamilyMember {
- if (isPartOfFamily(familyData)) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return 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",
- );
- }
-}
-
-export function getTotalFamilyUsage(familyData: FamilyData): number {
- return familyData.members.reduce(
- (sum, currentMember) => sum + currentMember.usage,
- 0,
- );
-}
-
-export const leaveFamily = async () => {
- ensureOk(
- await fetch(await apiURL("/family/leave"), {
- method: "DELETE",
- headers: await authenticatedRequestHeaders(),
- }),
- );
- removeData(LS_KEYS.FAMILY_DATA);
-};
-
/**
* Fetch the two-factor status (whether or not it is enabled) from remote.
*/