π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refactor: consolidate and separate interfaces
mngshm9f70aab9b558
diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsxindex 2a754f3bd0..a1bf14d6c8 100644--- a/infra/staff/src/App.tsx+++ b/infra/staff/src/App.tsx@@ -10,10 +10,10 @@ import "./App.css";import FamilyTableComponent from "./components/FamilyComponentTable";import StorageBonusTableComponent from "./components/StorageBonusTableComponent";import TokensTableComponent from "./components/TokenTableComponent";-import type { UserData } from "./components/UserComponent";import UserComponent from "./components/UserComponent";import duckieimage from "./components/duckie.png";import { apiOrigin } from "./services/support";+import type { UserData, UserResponse } from "./types";export let email = "";export let token = "";@@ -29,38 +29,6 @@ export const setToken = (newToken: string) => {export const getEmail = () => email;export const getToken = () => token;-interface User {- ID: string;- email: string;- creationTime: number;-}--interface Subscription {- productID: string;- paymentProvider: string;- expiryTime: number;- storage: number;-}--interface Security {- isEmailMFAEnabled: boolean;- isTwoFactorEnabled: boolean;- passkeys: string;- passkeyCount: number;- canDisableEmailMFA: boolean;-}--interface UserResponse {- user: User;- subscription: Subscription;- authCodes?: number;- details?: {- usage?: number;- storageBonus?: number;- profileData: Security;- };-}-const App: React.FC = () => {const [localEmail, setLocalEmail] = useState<string>("");const [localToken, setLocalToken] = useState<string>("");@@ -139,7 +107,7 @@ const App: React.FC = () => {console.log("API Response:", userDataResponse);const extractedUserData: UserData = {- User: {+ user: {"User ID": userDataResponse.user.ID || "None",Email: userDataResponse.user.email || "None","Creation time":@@ -147,7 +115,7 @@ const App: React.FC = () => {userDataResponse.user.creationTime / 1000,).toLocaleString() || "None",},- Storage: {+ storage: {Total: userDataResponse.subscription.storage? userDataResponse.subscription.storage >= 1024 ** 3? `${(userDataResponse.subscription.storage / 1024 ** 3).toFixed(2)} GB`@@ -166,7 +134,7 @@ const App: React.FC = () => {: `${(userDataResponse.details.storageBonus / 1024 ** 2).toFixed(2)} MB`: "None",},- Subscription: {+ subscription: {"Product ID":userDataResponse.subscription.productID || "None",Provider:@@ -176,7 +144,7 @@ const App: React.FC = () => {userDataResponse.subscription.expiryTime / 1000,).toLocaleString() || "None",},- Security: {+ security: {"Email MFA": userDataResponse.details?.profileData.isEmailMFAEnabled? "Enabled"diff --git a/infra/staff/src/components/ChangeEmail.tsx b/infra/staff/src/components/ChangeEmail.tsxindex 26407af50e..d3824babc4 100644--- a/infra/staff/src/components/ChangeEmail.tsx+++ b/infra/staff/src/components/ChangeEmail.tsx@@ -10,10 +10,10 @@ import {import React, { useEffect, useState } from "react";import { getEmail, getToken } from "../App";import { apiOrigin } from "../services/support";-interface ErrorResponse {- message: string;-}+import type { ErrorResponse } from "../types";+// The below interfaces will only be used in this file+// hence not including them into a sub-merged types fileinterface ChangeEmailProps {open: boolean;onClose: () => void;diff --git a/infra/staff/src/components/CloseFamily.tsx b/infra/staff/src/components/CloseFamily.tsxindex 145c11b505..5ab71bd474 100644--- a/infra/staff/src/components/CloseFamily.tsx+++ b/infra/staff/src/components/CloseFamily.tsx@@ -10,14 +10,7 @@ import {import React, { useState } from "react";import { getEmail, getToken } from "../App"; // Import getEmail and getToken functionsimport { apiOrigin } from "../services/support";--interface UserData {- subscription?: {- userID: string;- // Add other properties as per your API response structure- };- // Add other properties as per your API response structure-}+import type { UserData } from "../types";interface CloseFamilyProps {open: boolean;diff --git a/infra/staff/src/components/Disable2FA.tsx b/infra/staff/src/components/Disable2FA.tsxindex 29a3a6cd5a..62166aef24 100644--- a/infra/staff/src/components/Disable2FA.tsx+++ b/infra/staff/src/components/Disable2FA.tsx@@ -10,14 +10,7 @@ import {import React, { useState } from "react";import { getEmail, getToken } from "../App"; // Import getEmail and getToken functionsimport { apiOrigin } from "../services/support";--interface UserData {- subscription?: {- userID: string;- // Add other properties as per your API response structure- };- // Add other properties as per your API response structure-}+import type { UserData } from "../types";interface Disable2FAProps {open: boolean;diff --git a/infra/staff/src/components/DisablePasskeys.tsx b/infra/staff/src/components/DisablePasskeys.tsxindex 824b2f2f87..a2757a371d 100644--- a/infra/staff/src/components/DisablePasskeys.tsx+++ b/infra/staff/src/components/DisablePasskeys.tsx@@ -10,20 +10,7 @@ import {import React, { useState } from "react";import { getEmail, getToken } from "../App"; // Import getEmail and getToken functionsimport { apiOrigin } from "../services/support";--interface UserData {- subscription?: {- userID: string;- // Add other properties as per your API response structure- };- // Add other properties as per your API response structure-}--interface DisablePasskeysProps {- open: boolean;- handleClose: () => void;- handleDisablePasskeys: () => void; // Callback to handle disabling passkeys-}+import type { DisablePasskeysProps, UserData } from "../types";const DisablePasskeys: React.FC<DisablePasskeysProps> = ({open,diff --git a/infra/staff/src/components/FamilyComponentTable.tsx b/infra/staff/src/components/FamilyComponentTable.tsxindex 2171b3aeda..94512f8355 100644--- a/infra/staff/src/components/FamilyComponentTable.tsx+++ b/infra/staff/src/components/FamilyComponentTable.tsx@@ -13,23 +13,10 @@ import * as React from "react";import { useEffect, useState } from "react";import { getEmail, getToken } from "../App";import { apiOrigin } from "../services/support";+import type { FamilyMember, UserData } from "../types";+import { formatUsageToGB } from "../utils/strings";import CloseFamily from "./CloseFamily";-interface FamilyMember {- id: string;- email: string;- status: string;- usage: number;-}--interface UserData {- details: {- familyData: {- members: FamilyMember[];- };- };-}-const FamilyTableComponent: React.FC = () => {const [familyMembers, setFamilyMembers] = useState<FamilyMember[]>([]);const [closeFamilyOpen, setCloseFamilyOpen] = useState(false);@@ -54,7 +41,7 @@ const FamilyTableComponent: React.FC = () => {}const userData = (await response.json()) as UserData; // Typecast to UserData interfaceconst members: FamilyMember[] =- userData.details.familyData.members;+ userData.details?.familyData?.members || [];setFamilyMembers(members);} catch (error) {console.error("Error fetching family data:", error);@@ -69,11 +56,6 @@ const FamilyTableComponent: React.FC = () => {);}, []);- const formatUsageToGB = (usage: number): string => {- const usageInGB = (usage / (1024 * 1024 * 1024)).toFixed(2);- return `${usageInGB} GB`;- };-const handleOpenCloseFamily = () => {setCloseFamilyOpen(true);};diff --git a/infra/staff/src/components/ToggleEmailMFA.tsx b/infra/staff/src/components/ToggleEmailMFA.tsxindex 0e0a469a73..82e3f28015 100644--- a/infra/staff/src/components/ToggleEmailMFA.tsx+++ b/infra/staff/src/components/ToggleEmailMFA.tsx@@ -10,14 +10,7 @@ import {import React, { useState } from "react";import { getEmail, getToken } from "../App"; // Import getEmail and getToken functionsimport { apiOrigin } from "../services/support";--interface UserData {- subscription?: {- userID: string;- // Add other properties as per your API response structure- };- // Add other properties as per your API response structure-}+import type { UserData } from "../types";interface ToggleEmailMFAProps {open: boolean;diff --git a/infra/staff/src/components/UpdateSubscription.tsx b/infra/staff/src/components/UpdateSubscription.tsxindex b1bf7dfea1..1b1806b59a 100644--- a/infra/staff/src/components/UpdateSubscription.tsx+++ b/infra/staff/src/components/UpdateSubscription.tsx@@ -62,8 +62,8 @@ const UpdateSubscription: React.FC<UpdateSubscriptionProps> = ({expiryTime: "",userId: "",attributes: {- "customerID": "",- "stripeAccountCountry": ""+ customerID: "",+ stripeAccountCountry: "",},});@@ -108,9 +108,13 @@ const UpdateSubscription: React.FC<UpdateSubscriptionProps> = ({expiryTime: expiryTime,userId: userDataResponse.subscription.userID || "",attributes: {- customerID: userDataResponse.subscription.attributes.customerID || "",- stripeAccountCountry: userDataResponse.subscription.attributes.stripeAccountCountry || ""- }+ customerID:+ userDataResponse.subscription.attributes+ .customerID || "",+ stripeAccountCountry:+ userDataResponse.subscription.attributes+ .stripeAccountCountry || "",+ },});} catch (error) {console.error("Error fetching data:", error);@@ -174,8 +178,9 @@ const UpdateSubscription: React.FC<UpdateSubscriptionProps> = ({transactionId: values.transactionId,attributes: {customerID: values.attributes.customerID,- stripeAccountCountry: values.attributes.stripeAccountCountry- }+ stripeAccountCountry:+ values.attributes.stripeAccountCountry,+ },};try {diff --git a/infra/staff/src/components/UserComponent.tsx b/infra/staff/src/components/UserComponent.tsxindex bc93101960..d10d1800f4 100644--- a/infra/staff/src/components/UserComponent.tsx+++ b/infra/staff/src/components/UserComponent.tsx@@ -19,17 +19,7 @@ import Disable2FA from "./Disable2FA";import DisablePasskeys from "./DisablePasskeys";import ToggleEmailMFA from "./ToggleEmailMFA";import UpdateSubscription from "./UpdateSubscription";--export interface UserData {- User: Record<string, string>;- Storage: Record<string, string>;- Subscription: Record<string, string>;- Security: Record<string, string>;-}--interface UserComponentProps {- userData: UserData | null;-}+import type { UserComponentProps } from "../types";const UserComponent: React.FC<UserComponentProps> = ({ userData }) => {const [deleteAccountOpen, setDeleteAccountOpen] = React.useState(false);@@ -44,10 +34,10 @@ const UserComponent: React.FC<UserComponentProps> = ({ userData }) => {const [disablePasskeysOpen, setDisablePasskeysOpen] = React.useState(false);React.useEffect(() => {- setTwoFactorEnabled(userData?.Security["Two factor 2FA"] === "Enabled");- setEmail2FAEnabled(userData?.Security["Email MFA"] === "Enabled");+ setTwoFactorEnabled(userData?.security["Two factor 2FA"] === "Enabled");+ setEmail2FAEnabled(userData?.security["Email MFA"] === "Enabled");setCanDisableEmailMFA(- userData?.Security["Can Disable EmailMFA"] === "Yes",+ userData?.security["Can Disable EmailMFA"] === "Yes",);}, [userData]);diff --git a/infra/staff/src/types/index.ts b/infra/staff/src/types/index.tsnew file mode 100644index 0000000000..274f08540b--- /dev/null+++ b/infra/staff/src/types/index.ts@@ -0,0 +1,70 @@+// Type related Users++export interface User {+ ID: string;+ email: string;+ creationTime: number;+}++export interface UserResponse {+ user: User;+ subscription: Subscription;+ authCodes?: number;+ details?: {+ usage?: number;+ storageBonus?: number;+ profileData: Security;+ };+}++export interface UserData {+ user: Record<string, string>;+ storage: Record<string, string>;+ subscription?: Record<string, string>;+ security: Record<string, string>;+ details?: {+ familyData: {+ members: FamilyMember[];+ };+ };+}++export interface UserComponentProps {+ userData: UserData | null;+}++// Error Response Interface+export interface ErrorResponse {+ message: string;+}++// Types related to Subscriptions+export interface Subscription {+ productID: string;+ paymentProvider: string;+ expiryTime: number;+ storage: number;+}++export interface Security {+ isEmailMFAEnabled: boolean;+ isTwoFactorEnabled: boolean;+ passkeys: string;+ passkeyCount: number;+ canDisableEmailMFA: boolean;+}++// Types related Family+export interface FamilyMember {+ id: string;+ email: string;+ status: string;+ usage: number;+}++// Types related to passkeys+export interface DisablePasskeysProps {+ open: boolean;+ handleClose: () => void;+ handleDisablePasskeys: () => void; // Callback to handle disabling passkeys+}diff --git a/infra/staff/src/utils/index.ts b/infra/staff/src/utils/index.tsnew file mode 100644index 0000000000..46a4bc3fcf--- /dev/null+++ b/infra/staff/src/utils/index.ts@@ -0,0 +1,5 @@+// Common utilities+export function formatUsageToGB(usage: number): string {+ const usageInGB = (usage / (1024 * 1024 * 1024)).toFixed(2);+ return `${usageInGB} GB`;+}diff --git a/infra/staff/src/utils/strings.ts b/infra/staff/src/utils/strings.tsdeleted file mode 100644index 39b22fcd76..0000000000--- a/infra/staff/src/utils/strings.ts+++ /dev/null@@ -1,13 +0,0 @@-/**- * User facing strings in the app.- *- * By keeping them separate, we make our lives easier if/when we need to- * localize the corresponding pages. Right now, these are just the values in the- * default language, English.- */-const S = {- hello: "Hello Ente!",- error_generic: "Oops, something went wrong.",-};--export default S;