Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move checkpoint

Manav Rathi9737405c3ac9
diff --git a/web/apps/photos/src/components/MemberSubscriptionManage.tsx b/web/apps/photos/src/components/MemberSubscriptionManage.tsx
index 8dfd5e900c..f1d0a38023 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 } from "@/new/photos/services/user";
+import { getFamilyPlanAdmin, leaveFamily } from "@/new/photos/services/user";
import { AppContext } from "@/new/photos/types/context";
import {
FlexWrapper,
@@ -9,7 +9,6 @@ import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleW
import { Box, Button, Dialog, DialogContent, Typography } from "@mui/material";
import { t } from "i18next";
import { useContext } from "react";
-import billingService from "services/plan";
export function MemberSubscriptionManage({ open, userDetails, onClose }) {
const { setDialogMessage } = useContext(AppContext);
@@ -17,7 +16,7 @@ export function MemberSubscriptionManage({ open, userDetails, onClose }) {
async function onLeaveFamilyClick() {
try {
- await billingService.leaveFamily();
+ await leaveFamily();
} catch (e) {
setDialogMessage({
title: t("error"),
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx
index 4e0c2d69fe..7a30eb8ef4 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload/Uploader.tsx
@@ -7,6 +7,7 @@ import { CollectionMappingChoiceDialog } from "@/new/photos/components/Collectio
import type { CollectionSelectorAttributes } from "@/new/photos/components/CollectionSelector";
import { downloadAppDialogAttributes } from "@/new/photos/components/utils/download";
import { exportMetadataDirectoryName } from "@/new/photos/services/export";
+import { redirectToCustomerPortal } from "@/new/photos/services/plan";
import type {
FileAndPath,
UploadItem,
@@ -24,7 +25,6 @@ import isElectron from "is-electron";
import { GalleryContext } from "pages/gallery";
import { useContext, useEffect, useRef, useState } from "react";
import { getLatestCollections } from "services/collectionService";
-import { redirectToCustomerPortal } from "services/plan";
import {
getPublicCollectionUID,
getPublicCollectionUploaderName,
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 1a2c4abd37..d3e20c5375 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -39,7 +39,10 @@ import {
getLocalTrashedFiles,
sortFiles,
} from "@/new/photos/services/files";
-import { verifySubscription } from "@/new/photos/services/plan";
+import {
+ redirectToCustomerPortal,
+ verifySubscription,
+} from "@/new/photos/services/plan";
import {
filterSearchableFiles,
setSearchCollectionsAndFiles,
@@ -107,6 +110,7 @@ import { t } from "i18next";
import { useRouter, type NextRouter } from "next/router";
import { createContext, useCallback, useEffect, useRef, useState } from "react";
import { useDropzone } from "react-dropzone";
+import { Trans } from "react-i18next";
import {
constructEmailList,
constructUserIDToEmailMap,
@@ -116,7 +120,6 @@ import {
getAllLocalCollections,
} from "services/collectionService";
import { syncFiles } from "services/fileService";
-import { redirectToCustomerPortal } from "services/plan";
import { preFileInfoSync, sync } from "services/sync";
import { syncTrash } from "services/trashService";
import uploadManager from "services/upload/uploadManager";
@@ -134,7 +137,6 @@ import {
handleCollectionOps,
} from "utils/collection";
import { FILE_OPS_TYPE, getSelectedFiles, handleFileOps } from "utils/file";
-import { getSubscriptionPurchaseSuccessMessage } from "utils/ui";
const defaultGalleryContext: GalleryContextType = {
showPlanSelectorModal: () => null,
@@ -1243,9 +1245,16 @@ export async function checkSubscriptionPurchase(
if (status == "success" && typeof sessionID == "string") {
try {
const subscription = await verifySubscription(sessionID);
- setDialogMessage(
- getSubscriptionPurchaseSuccessMessage(subscription),
- );
+ setDialogMessage({
+ title: t("SUBSCRIPTION_PURCHASE_SUCCESS_TITLE"),
+ close: { variant: "accent" },
+ content: (
+ <Trans
+ i18nKey="SUBSCRIPTION_PURCHASE_SUCCESS"
+ values={{ date: subscription?.expiryTime }}
+ />
+ ),
+ });
} catch (e) {
setDialogMessage({
title: t("error"),
diff --git a/web/apps/photos/src/utils/ui/index.tsx b/web/apps/photos/src/utils/ui/index.tsx
index ce8f690b3e..a49d1c6a7b 100644
--- a/web/apps/photos/src/utils/ui/index.tsx
+++ b/web/apps/photos/src/utils/ui/index.tsx
@@ -2,7 +2,6 @@ import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";
import InfoOutlined from "@mui/icons-material/InfoRounded";
import { t } from "i18next";
import { Trans } from "react-i18next";
-import { Subscription } from "services/plan";
export const getTrashFilesMessage = (
deleteFileHelper,
@@ -47,16 +46,3 @@ export const getExportDirectoryDoesNotExistMessage =
content: <Trans i18nKey={"EXPORT_DIRECTORY_DOES_NOT_EXIST_MESSAGE"} />,
close: {},
});
-
-export const getSubscriptionPurchaseSuccessMessage = (
- subscription: Subscription,
-): DialogBoxAttributes => ({
- title: t("SUBSCRIPTION_PURCHASE_SUCCESS_TITLE"),
- close: { variant: "accent" },
- content: (
- <Trans
- i18nKey="SUBSCRIPTION_PURCHASE_SUCCESS"
- values={{ date: subscription?.expiryTime }}
- />
- ),
-});
diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.ts
index 423c9fa304..cd26d028dc 100644
--- a/web/packages/new/photos/services/plan.ts
+++ b/web/packages/new/photos/services/plan.ts
@@ -1,18 +1,14 @@
+// TODO:
+/* 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, paymentsAppOrigin } from "@/base/origins";
import {
getTotalFamilyUsage,
isPartOfFamily,
} from "@/new/photos/services/user";
import { nullToUndefined } from "@/utils/transform";
-import HTTPService from "@ente/shared/network/HTTPService";
-import {
- LS_KEYS,
- removeData,
- setData,
-} from "@ente/shared/storage/localStorage";
-import { getToken } from "@ente/shared/storage/localStorage/helpers";
+import { LS_KEYS, setData } from "@ente/shared/storage/localStorage";
import isElectron from "is-electron";
import { z } from "zod";
import type { BonusData, UserDetails } from "./user";
@@ -72,30 +68,6 @@ const PlansData = z.object({
export type PlansData = z.infer<typeof PlansData>;
-class billingService {
- public async leaveFamily() {
- if (!getToken()) {
- return;
- }
- try {
- await HTTPService.delete(
- await apiURL("/family/leave"),
- null,
- null,
- {
- "X-Auth-Token": getToken(),
- },
- );
- removeData(LS_KEYS.FAMILY_DATA);
- } catch (e) {
- log.error("/family/leave failed", e);
- throw e;
- }
- }
-}
-
-export default new billingService();
-
/**
* Fetch the list of plans from remote.
*/
diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts
index 6f43ba0bfc..1dbe2cd652 100644
--- a/web/packages/new/photos/services/user.ts
+++ b/web/packages/new/photos/services/user.ts
@@ -1,7 +1,11 @@
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
import log from "@/base/log";
import { apiURL } from "@/base/origins";
-import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
+import {
+ LS_KEYS,
+ getData,
+ removeData,
+} from "@ente/shared/storage/localStorage";
import type { User } from "@ente/shared/user/types";
import { z } from "zod";
import type { Subscription } from "./plan";
@@ -87,6 +91,16 @@ export function getTotalFamilyUsage(familyData: FamilyData): number {
);
}
+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.
*/