π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Added buttons for disable2fa, close family and disable passkeys
atyabbind716f18c2e1b
diff --git a/infra/staff/src/App.css b/infra/staff/src/App.cssindex a057e13087..0b9a58a038 100644--- a/infra/staff/src/App.css+++ b/infra/staff/src/App.css@@ -1,47 +1,78 @@-body,-html {- margin: 0;- padding: 0;- height: 100%;- font-family: Arial, sans-serif;-}--.sidebar {- width: 200px;- height: 100%;+.sidebar button {+ margin-right: 10px;+ padding: 10px 20px;+ font-size: 16px;+ cursor: pointer;background-color: #009879;color: white;- padding-top: 20px;- position: fixed;- top: 0;- left: 0;+ border: none;+ border-radius: 5px;}-.sidebar ul {- list-style-type: none;- padding: 0;+.content-wrapper {+ display: flex;+ align-items: flex-start; /* Ensure items start at the top */+ margin-left: 70px; /* Adjusts margin to move content towards the right */}-.sidebar ul li {- padding: 10px;- text-align: center;- cursor: pointer;+/* Adjust .fetch-button-container margin to ensure proper spacing */+.fetch-button-container {+ margin-right: 20px; /* Adjust as needed */}-.sidebar ul li:hover {- background-color: lightgreen;- color: black;+.fetch-button-container button {+ padding: 10px 20px;+ font-size: 16px;+ cursor: pointer;+ background-color: #009879;+ color: white;+ border: none;+ border-radius: 5px;+ margin-top: 20px;+}+.fetch-button-container button:hover {+ background-color: #007c6c;}-.main-content {- margin-left: 200px;+.sidebar button:hover {+ background-color: #007c6c;+}+.sidebar {padding: 20px;- flex-grow: 1;+ flex: 0 0 auto; /* Prevent sidebar from growing and affecting other elements */}-.input-form,-.fetch-button,-table,-.footer {+.button-container {+ display: flex;+ gap: 10px;+}++button {+ padding: 10px 20px;+ font-size: 16px;+}++.error-message {margin-top: 20px;+ color: red;+}+.message {+ position: fixed;+ bottom: 10px;+ left: 50%;+ transform: translateX(-50%);+ padding: 10px;+ border-radius: 5px;+ background-color: #f0f0f0;+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);+}++.message.error {+ background-color: #f44336;+ color: white;+}++.message.success {+ background-color: #4caf50;+ color: white;}diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsxindex 845f1226ec..ec0ea42906 100644--- a/infra/staff/src/App.tsx+++ b/infra/staff/src/App.tsx@@ -1,26 +1,18 @@import React, { useEffect, useState } from "react";-<<<<<<< HEAD+import "./App.css";import { Sidebar } from "./components/Sidebar";-import S from "./utils/strings";--export const App: React.FC = () => {- const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {- e.preventDefault();- fetchData();- };- const [serverUrl /*, setServerUrl */] = useState(- import.meta.env.VITE_ENTE_ENDPOINT || "",- );--=======import { apiOrigin } from "./services/support";import S from "./utils/strings";+type User = Record<+ string,+ string | number | boolean | null | undefined | Record<string, unknown>+>;+type UserData = Record<string, User>;export const App: React.FC = () => {->>>>>>> main- const [token, setToken] = useState("");- const [email, setEmail] = useState("");- const [userData, setUserData] = useState<any>(null);+ const [token, setToken] = useState<string>("");+ const [email, setEmail] = useState<string>("");+ const [userData, setUserData] = useState<UserData | null>(null);const [error, setError] = useState<string | null>(null);useEffect(() => {@@ -40,14 +32,17 @@ export const App: React.FC = () => {const fetchData = async () => {try {- const url = `${apiOrigin}/admin/user?email=${email}&token=${token}`;+ const encodedEmail = encodeURIComponent(email);+ const encodedToken = encodeURIComponent(token);+ const url = `${apiOrigin}/admin/user?email=${encodedEmail}&token=${encodedToken}`;+ console.log(`Fetching data from URL: ${url}`);const response = await fetch(url);if (!response.ok) {throw new Error("Network response was not ok");}- const userData = await response.json();- console.log("API Response:", userData);- setUserData(userData);+ const userDataResponse = (await response.json()) as UserData;+ console.log("API Response:", userDataResponse);+ setUserData(userDataResponse);setError(null);} catch (error) {console.error("Error fetching data:", error);@@ -55,10 +50,12 @@ export const App: React.FC = () => {}};- const renderAttributes = (data: any) => {+ const renderAttributes = (+ data: Record<string, unknown> | User | null,+ ): React.ReactNode => {if (!data) return null;- let nullAttributes: string[] = [];+ const nullAttributes: string[] = [];const rows = Object.entries(data).map(([key, value]) => {console.log("Processing key:", key, "value:", value);@@ -82,7 +79,9 @@ export const App: React.FC = () => {{key.toUpperCase()}</td></tr>- {renderAttributes(value)}+ {renderAttributes(+ value as Record<string, unknown> | User,+ )}</React.Fragment>);} else {@@ -102,17 +101,26 @@ export const App: React.FC = () => {displayValue = `${(value / 1024 ** 3).toFixed(2)} GB`;} else if (typeof value === "string") {try {- const parsedValue = JSON.parse(value);+ const parsedValue = JSON.parse(+ value,+ ) as React.ReactNode;displayValue = parsedValue;} catch (error) {displayValue = value;}+ } else if (typeof value === "object" && value !== null) {+ displayValue = JSON.stringify(value, null, 2); // Pretty print JSON} else if (value === null) {displayValue = "null";- } else if (typeof value !== "undefined") {+ } else if (+ typeof value === "boolean" ||+ typeof value === "number"+ ) {displayValue = value.toString();- } else {+ } else if (typeof value === "undefined") {displayValue = "undefined";+ } else {+ displayValue = value as string; // Fallback for any other types}return (@@ -144,99 +152,95 @@ export const App: React.FC = () => {};return (- <>- <Sidebar />- <div className="container center-table">- <h1>{S.hello}</h1>-- <form className="input-form" onSubmit={handleFormSubmit}>- <div className="input-group">- <label>- Token:- <input- type="text"- value={token}- onChange={(e) => setToken(e.target.value)}- style={{- padding: "10px",- margin: "10px",- width: "100%",- }}- />- </label>- </div>- <div className="input-group">- <label>- Email id:- <input- type="text"- value={email}- onChange={(e) => setEmail(e.target.value)}- style={{- padding: "10px",- margin: "10px",- width: "100%",- }}- />- </label>- </div>- </form>- <div className="fetch-button">+ <div className="container center-table">+ <h1>{S.hello}</h1>+ <form className="input-form">+ <div className="input-group">+ <label>+ Token:+ <input+ type="text"+ value={token}+ onChange={(e) => setToken(e.target.value)}+ style={{+ padding: "10px",+ margin: "10px",+ width: "100%",+ }}+ />+ </label>+ </div>+ <div className="input-group">+ <label>+ Email id:+ <input+ type="text"+ value={email}+ onChange={(e) => setEmail(e.target.value)}+ style={{+ padding: "10px",+ margin: "10px",+ width: "100%",+ }}+ />+ </label>+ </div>+ </form>+ <div className="content-wrapper">+ <Sidebar email={email} token={token} />+ <div className="fetch-button-container"><button- onClick={fetchData}- style={{- padding: "10px 20px",- fontSize: "16px",- cursor: "pointer",- backgroundColor: "#009879",- color: "white",- border: "none",- borderRadius: "5px",+ onClick={() => {+ fetchData().catch((error: unknown) =>+ console.error("Fetch data error:", error),+ );}}>FETCH</button></div>- <br />- {error && <p style={{ color: "red" }}>{`Error: ${error}`}</p>}- {userData && (- <table- style={{- width: "100%",- borderCollapse: "collapse",- margin: "20px 0",- fontSize: "1em",- minWidth: "400px",- boxShadow: "0 0 20px rgba(0, 0, 0, 0.15)",- }}- >- <tbody>- {Object.keys(userData).map((category) => (- <React.Fragment key={category}>- <tr>- <td- colSpan={2}- style={{- fontWeight: "bold",- backgroundColor: "#f1f1f1",- padding: "10px",- }}- >- {category.toUpperCase()}- </td>- </tr>- {renderAttributes(userData[category])}- </React.Fragment>- ))}- </tbody>- </table>- )}- <footer className="footer">- <p>- <a href="https://help.ente.io">help.ente.io</a>- </p>- </footer></div>- </>+ <br />+ {error && <p style={{ color: "red" }}>{`Error: ${error}`}</p>}+ {userData && (+ <table+ style={{+ width: "100%",+ borderCollapse: "collapse",+ margin: "20px 0",+ fontSize: "1em",+ minWidth: "400px",+ boxShadow: "0 0 20px rgba(0, 0, 0, 0.15)",+ }}+ >+ <tbody>+ {Object.keys(userData).map((category) => (+ <React.Fragment key={category}>+ <tr>+ <td+ colSpan={2}+ style={{+ fontWeight: "bold",+ backgroundColor: "#f1f1f1",+ padding: "10px",+ }}+ >+ {category.toUpperCase()}+ </td>+ </tr>+ {renderAttributes(userData[category] ?? null)}+ </React.Fragment>+ ))}+ </tbody>+ </table>+ )}+ <footer className="footer">+ <p>+ <a href="https://help.ente.io">help.ente.io</a>+ </p>+ </footer>+ </div>);};++export default App;diff --git a/infra/staff/src/components/Sidebar.tsx b/infra/staff/src/components/Sidebar.tsxindex 87011784e4..897fca076b 100644--- a/infra/staff/src/components/Sidebar.tsx+++ b/infra/staff/src/components/Sidebar.tsx@@ -1,21 +1,176 @@-import React from "react";+import React, { useState } from "react";import "../App.css";+import { apiOrigin } from "../services/support";+interface SidebarProps {- onOptionSelect: (option: string) => void;+ token: string;+ email: string;+}++interface UserData {+ user: {+ ID: string;+ };}-export const Sidebar: React.FC<SidebarProps> = ({ onOptionSelect }) => {+export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {+ const [, /*userId*/ setUserId] = useState<string | null>(null);+ const [error, setError] = useState<string | null>(null);+ const [message, setMessage] = useState<string | null>(null);+ interface ApiResponse {+ // Define properties according to your API response structure+ // For example:+ data: {+ // Define properties based on your API response+ // For example:+ userId: string;+ };+ }++ const fetchData = async (): Promise<string | null> => {+ if (!email || !token) {+ setError("Email or token is missing.");+ return null;+ }++ try {+ const url = `${apiOrigin}/admin/user?email=${encodeURIComponent(email)}&token=${encodeURIComponent(token)}`;+ const response = await fetch(url);+ if (!response.ok) {+ throw new Error("Network response was not ok");+ }+ const userDataResponse = (await response.json()) as UserData;+ const fetchedUserId = userDataResponse.user.ID;+ if (!fetchedUserId) {+ throw new Error("User ID not found in response");+ }+ setUserId(fetchedUserId);+ setError(null);+ return fetchedUserId;+ } catch (error) {+ console.error("Error fetching data:", error);+ setError(+ error instanceof Error && typeof error.message === "string"+ ? error.message+ : "An unexpected error occurred",+ );++ setTimeout(() => {+ setError(null);+ }, 1000);+ return null;+ }+ };++ const performAction = async (userId: string, action: string) => {+ try {+ const actionUrls: Record<string, string> = {+ Disable2FA: "/admin/user/disable-2fa",+ Passkeys: "/admin/user/disable-passkeys",+ Closefamily: "/admin/user/close-family",+ };++ const url = `${apiOrigin}${actionUrls[action]}?id=${encodeURIComponent(userId)}&token=${encodeURIComponent(token)}`;+ const response = await fetch(url, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ userId }),+ });++ if (!response.ok) {+ throw new Error(+ `Network response was not ok: ${response.status}`,+ );+ }++ const result = (await response.json()) as ApiResponse;+ console.log("API Response:", result);++ // Set success message+ setMessage(`${action} completed successfully`);+ setError(null); // Clear any previous errors++ // Clear success message after 3 seconds+ setTimeout(() => {+ setMessage(null);+ }, 1000);+ } catch (error) {+ console.error(`Error ${action}:`, error);+ setError(+ error instanceof Error && typeof error.message === "string"+ ? error.message+ : "An unexpected error occurred",+ );+ // Clear error message after 3 seconds+ setTimeout(() => {+ setError(null);+ }, 1000);+ setMessage(null); // Clear message on error+ }+ };++ const handleActionClick = async (action: string) => {+ try {+ const fetchedUserId = await fetchData();+ if (!fetchedUserId) {+ throw new Error("Incorrect email id or token");+ }++ // Perform action+ await performAction(fetchedUserId, action);+ } catch (error) {+ console.error(`Error performing ${action}:`, error);+ setError(+ error instanceof Error && typeof error.message === "string"+ ? error.message+ : "An unexpected error occurred",+ );+ // Clear error message after 3 seconds+ setTimeout(() => {+ setError(null);+ }, 1000);+ setMessage(null); // Clear message on error+ }+ };+return (<div className="sidebar">- <ul>- <li onClick={() => onOptionSelect("Disable2FA")}>Disable2FA</li>- <li onClick={() => onOptionSelect("Closefamily")}>- Closefamily- </li>- <li onClick={() => onOptionSelect("Passkeys")}>- DisablePasskeys- </li>- </ul>+ <div className="button-container">+ <button+ onClick={() => {+ handleActionClick("Disable2FA").catch((e: unknown) =>+ console.error(e),+ );+ }}+ >+ Disable 2FA+ </button>+ <button+ onClick={() => {+ handleActionClick("Closefamily").catch((e: unknown) =>+ console.error(e),+ );+ }}+ >+ Close Family+ </button>+ <button+ onClick={() => {+ handleActionClick("Passkeys").catch((e: unknown) =>+ console.error(e),+ );+ }}+ >+ Disable Passkeys+ </button>+ </div>+ {(error ?? message) && (+ <div className={`message ${error ? "error" : "success"}`}>+ {error ? `Error: ${error}` : `Success: ${message}`}+ </div>+ )}</div>);};++export default Sidebar;