π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Added options for delete account and update subscription
atyabbin567dfb7e6b9f
diff --git a/infra/staff/package.json b/infra/staff/package.jsonindex d81c891868..6939e38937 100644--- a/infra/staff/package.json+++ b/infra/staff/package.json@@ -11,12 +11,15 @@"preview": "vite preview"},"dependencies": {+ "date-fns": "^3.6.0","react": "^18",+ "react-datepicker": "^7.1.0","react-dom": "^18","react-toastify": "^10.0.5","zod": "^3"},"devDependencies": {+ "@rollup/plugin-node-resolve": "^15.2.3","@types/react": "^18","@types/react-dom": "^18","@typescript-eslint/eslint-plugin": "^7",@@ -29,7 +32,7 @@"prettier": "^3","prettier-plugin-organize-imports": "^3.2","prettier-plugin-packagejson": "^2.5",- "typescript": "^5.4.5",+ "typescript": "^5","vite": "^5.2"},"packageManager": "[email protected]"diff --git a/infra/staff/src/App.css b/infra/staff/src/App.cssindex 4e7c66ce7a..8e702df72d 100644--- a/infra/staff/src/App.css+++ b/infra/staff/src/App.css@@ -19,6 +19,21 @@border-radius: 5px;margin-top: 20px;}+#submitbtn{++ padding: 10px 20px;+ font-size: 16px;+ cursor: pointer;+ background-color: #009879;+ color: white;+ border: none;+ border-radius: 5px;+ margin-top: 20px;+}++#submitbtn:hover {+ background-color: #007c6c;+}.fetch-button-container button:hover {background-color: #007c6c;@@ -122,3 +137,321 @@ button {.dropdown-menu button:hover {background-color: #f0f0f0;}+.modal {+ position: fixed;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+ background-color: #ffffff;+ padding: 20px;+ border: 1px solid #ccc;+ border-radius: 5px;+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);+ z-index: 1000;+ max-width: 80%;+ max-height: 80%;+ overflow: auto;+}++.modal-header {+ display: flex;+ justify-content: space-between;+ align-items: center;+ padding-bottom: 10px;+ border-bottom: 1px solid #ccc;+}++.modal-header .close-btn {+ cursor: pointer;+ color: #777;+ font-size: 20px;+}++.modal-content {+ margin-top: 10px;+}++/* Styles for draggable modal */+.modal.draggable {+ cursor: move;+}++.modal.draggable .modal-header {+ cursor: move;+}+.popup {+ position: fixed;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+ background-color: lightgreen;+ padding: 20px;+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);+ z-index: 1000;+}++.popup-content {+ display: flex;+ flex-direction: column;+}++.popup-content div {+ margin-bottom: 10px;+}+:root {+ --popup-bg-color-light: #fff;+ --popup-bg-color-dark: #2c2c2c;+ --popup-border-color-light: #ccc;+ --popup-border-color-dark: #444;+ --popup-text-color-light: #000;+ --popup-text-color-dark: #fff;+ --popup-shadow-light: rgba(0, 0, 0, 0.1);+ --popup-shadow-dark: rgba(255, 255, 255, 0.1);+}++.update-subscription-popup {+ position: fixed;+ top: 50%;+ left: 50%;+ width: 400px;+ transform: translate(-50%, -50%);+ background-color: var(--popup-bg-color-light);+ border: 1px solid var(--popup-border-color-light);+ padding: 20px;+ z-index: 1000;+ box-shadow: 0px 0px 10px var(--popup-shadow-light);+}++.popup-content {+ display: flex;+ flex-direction: column;+}++.close-button {+ align-self: flex-end;+ background: none;+ border: none;+ font-size: 1.5rem;+ cursor: pointer;+ color: var(--popup-text-color-light);+}++.popup-content h2 {+ margin-top: 0;+}++.popup-content form label {+ display: block;+ margin-bottom: 10px;+}++.popup-content form input,+.popup-content form select {+ width: 100%;+ padding: 8px;+ margin-top: 5px;+ background-color: var(--popup-bg-color-light);+ color: var(--popup-text-color-light);+ border: 1px solid var(--popup-border-color-light);+}++.popup-content form button {+ padding: 10px 15px;+ margin-top: 10px;+ cursor: pointer;+ background-color: var(--popup-bg-color-light);+ color: var(--popup-text-color-light);+ border: 1px solid var(--popup-border-color-light);+}++.custom-select {+ position: relative;+ width: 100%;+}++.custom-select select {+ width: 100%;+ padding: 8px;+ cursor: pointer;+ background-color: var(--popup-bg-color-light);+ color: var(--popup-text-color-light);+ border: 1px solid var(--popup-border-color-light);+ appearance: none;+}++.custom-select::after {+ content: "\25BC";+ position: absolute;+ top: 50%;+ right: 10px;+ transform: translateY(-50%);+ pointer-events: none;+}++.message {+ margin-top: 10px;+ padding: 10px;+ border-radius: 5px;+}++.message.error {+ background-color: #f8d7da;+ color: #721c24;+}++.message.success {+ background-color: #d4edda;+ color: #155724;+}++@media (prefers-color-scheme: dark) {+ .update-subscription-popup {+ background-color: var(--popup-bg-color-dark);+ border-color: var(--popup-border-color-dark);+ color: var(--popup-text-color-dark);+ box-shadow: 0px 0px 10px var(--popup-shadow-dark);+ }++ .close-button {+ color: var(--popup-text-color-dark);+ }++ .popup-content form input,+ .popup-content form select {+ background-color: var(--popup-bg-color-dark);+ color: var(--popup-text-color-dark);+ border: 1px solid var(--popup-border-color-dark);+ }++ .popup-content form button {+ background-color: var(--popup-bg-color-dark);+ color: var(--popup-text-color-dark);+ border: 1px solid var(--popup-border-color-dark);+ }+}+:root {+ --popup-bg-color-light: #fff;+ --popup-bg-color-dark: #2c2c2c;+ --popup-border-color-light: #ccc;+ --popup-border-color-dark: #444;+ --popup-text-color-light: #000;+ --popup-text-color-dark: #fff;+ --popup-shadow-light: rgba(0, 0, 0, 0.1);+ --popup-shadow-dark: rgba(255, 255, 255, 0.1);+}++.update-subscription-popup {+ position: fixed;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+ background-color: var(--popup-bg-color-light);+ border: 1px solid var(--popup-border-color-light);+ padding: 20px;+ z-index: 1000;+ box-shadow: 0px 0px 10px var(--popup-shadow-light);+}++.popup-content {+ display: flex;+ flex-direction: column;+}++.close-button {+ align-self: flex-end;+ background: none;+ border: none;+ font-size: 1.5rem;+ cursor: pointer;+ color: var(--popup-text-color-light);+}++.popup-content h2 {+ margin-top: 0;+}++.form-group {+ margin-bottom: 20px;+}++.form-group label {+ display: block;+ margin-bottom: 5px;+}++.form-group input,+.form-group select {+ width: 100%;+ padding: 8px;+ background-color: var(--popup-bg-color-light);+ color: var(--popup-text-color-light);+ border: 1px solid var(--popup-border-color-light);+ border-radius: 5px;+ margin-top: 5px;+}++.custom-select {+ position: relative;+ width: 100%;+}++.custom-select select {+ width: 100%;+ padding: 8px;+ cursor: pointer;+ background-color: var(--popup-bg-color-light);+ color: var(--popup-text-color-light);+ border: 1px solid var(--popup-border-color-light);+ appearance: none;+}++.custom-select::after {+ content: "\25BC";+ position: absolute;+ top: 50%;+ right: 10px;+ transform: translateY(-50%);+ pointer-events: none;+}++.message {+ margin-top: 10px;+ padding: 10px;+ border-radius: 5px;+}++.message.error {+ background-color: #f8d7da;+ color: #721c24;+}++.message.success {+ background-color: #d4edda;+ color: #155724;+}++@media (prefers-color-scheme: dark) {+ .update-subscription-popup {+ background-color: var(--popup-bg-color-dark);+ border-color: var(--popup-border-color-dark);+ color: var(--popup-text-color-dark);+ box-shadow: 0px 0px 10px var(--popup-shadow-dark);+ }++ .close-button {+ color: var(--popup-text-color-dark);+ }++ .form-group input,+ .form-group select {+ background-color: var(--popup-bg-color-dark);+ color: var(--popup-text-color-dark);+ border: 1px solid var(--popup-border-color-dark);+ }++ .form-group button {+ background-color: var(--popup-bg-color-dark);+ color: var(--popup-text-color-dark);+ border: 1px solid var(--popup-border-color-dark);+ }+}diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsxindex e27c24ccbf..bad145673b 100644--- a/infra/staff/src/App.tsx+++ b/infra/staff/src/App.tsx@@ -15,7 +15,7 @@ export const App: React.FC = () => {const [email, setEmail] = useState<string>("");const [userData, setUserData] = useState<UserData | null>(null);const [error, setError] = useState<string | null>(null);- const [isDataFetched, setIsDataFetched] = useState<boolean>(false); // Track if data has been fetched successfully+ const [isDataFetched, setIsDataFetched] = useState<boolean>(false);useEffect(() => {const storedToken = localStorage.getItem("token");@@ -46,11 +46,11 @@ export const App: React.FC = () => {console.log("API Response:", userDataResponse);setUserData(userDataResponse);setError(null);- setIsDataFetched(true); // Set to true when data is successfully fetched+ setIsDataFetched(true);} catch (error) {console.error("Error fetching data:", error);setError((error as Error).message);- setIsDataFetched(false); // Set to false if there's an error fetching data+ setIsDataFetched(false);}};@@ -113,7 +113,7 @@ export const App: React.FC = () => {displayValue = value;}} else if (typeof value === "object" && value !== null) {- displayValue = JSON.stringify(value, null, 2); // Pretty print JSON+ displayValue = JSON.stringify(value, null, 2);} else if (value === null) {displayValue = "null";} else if (@@ -124,7 +124,7 @@ export const App: React.FC = () => {} else if (typeof value === "undefined") {displayValue = "undefined";} else {- displayValue = value as string; // Fallback for any other types+ displayValue = value as string;}return (@@ -157,7 +157,7 @@ export const App: React.FC = () => {const handleKeyPress = (event: React.KeyboardEvent<HTMLFormElement>) => {if (event.key === "Enter") {- event.preventDefault(); // Prevent form submission+ event.preventDefault();fetchData().catch((error: unknown) =>console.error("Fetch data error:", error),);diff --git a/infra/staff/src/components/Sidebar.tsx b/infra/staff/src/components/Sidebar.tsxindex 8e60b98f7c..a16aebf238 100644--- a/infra/staff/src/components/Sidebar.tsx+++ b/infra/staff/src/components/Sidebar.tsx@@ -1,6 +1,7 @@-import React, { useState } from "react";+import React, { useEffect, useRef, useState } from "react";import "../App.css";import { apiOrigin } from "../services/support";+import UpdateSubscription from "./UpdateSubscription"; // Import the UpdateSubscription componentinterface SidebarProps {token: string;@@ -12,18 +13,36 @@ interface UserData {ID: string;};}+interface ActionResponse {+ success?: boolean;+ message?: string;+}export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {- const [, /*userId*/ setUserId] = useState<string | null>(null);+ const [userId, setUserId] = useState<string | null>(null);const [error, setError] = useState<string | null>(null);const [message, setMessage] = useState<string | null>(null);const [dropdownVisible, setDropdownVisible] = useState<boolean>(false);+ const [showUpdateSubscription, setShowUpdateSubscription] =+ useState<boolean>(false); // State to control UpdateSubscription popup++ const dropdownRef = useRef<HTMLDivElement>(null);- interface ApiResponse {- data: {- userId: string;+ useEffect(() => {+ document.addEventListener("mousedown", handleClickOutside);+ return () => {+ document.removeEventListener("mousedown", handleClickOutside);};- }+ }, []);++ const handleClickOutside = (event: MouseEvent) => {+ if (+ dropdownRef.current &&+ !dropdownRef.current.contains(event.target as Node)+ ) {+ setDropdownVisible(false);+ }+ };const fetchData = async (): Promise<string | null> => {if (!email || !token) {@@ -32,9 +51,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {}try {- const url = `${apiOrigin}/admin/user?email=${encodeURIComponent(- email,- )}&token=${encodeURIComponent(token)}`;+ 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");@@ -70,9 +87,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {Closefamily: "/admin/user/close-family",};- const url = `${apiOrigin}${actionUrls[action]}?id=${encodeURIComponent(- userId,- )}&token=${encodeURIComponent(token)}`;+ const url = `${apiOrigin}${actionUrls[action]}?id=${encodeURIComponent(userId)}&token=${encodeURIComponent(token)}`;const response = await fetch(url, {method: "POST",headers: { "Content-Type": "application/json" },@@ -85,7 +100,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {);}- const result = (await response.json()) as ApiResponse;+ const result = (await response.json()) as ActionResponse;console.log("API Response:", result);setMessage(`${action} completed successfully`);@@ -109,8 +124,55 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {}};+ const deleteUser = async () => {+ try {+ const url = `${apiOrigin}/admin/user/delete?email=${encodeURIComponent(email)}&token=${encodeURIComponent(token)}`;+ const response = await fetch(url, {+ method: "DELETE",+ });++ if (!response.ok) {+ throw new Error(+ `Network response was not ok: ${response.status}`,+ );+ }++ setMessage("Delete Account completed successfully");+ setError(null);+ setTimeout(() => {+ setMessage(null);+ }, 1000);+ setDropdownVisible(false);+ } catch (error) {+ console.error(`Error deleting account:`, error);+ setError(+ error instanceof Error && typeof error.message === "string"+ ? error.message+ : "An unexpected error occurred",+ );++ setTimeout(() => {+ setError(null);+ }, 1000);+ setMessage(null);+ }+ };+const handleActionClick = async (action: string) => {try {+ if (action === "UpdateSubscription") {+ const fetchedUserId = await fetchData();+ if (fetchedUserId) {+ setShowUpdateSubscription(true);+ }+ return;+ }++ if (action === "DeleteAccount") {+ await deleteUser();+ return;+ }+const fetchedUserId = await fetchData();if (!fetchedUserId) {throw new Error("Incorrect email id or token");@@ -140,6 +202,8 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {{ value: "Disable2FA", label: "Disable 2FA" },{ value: "Closefamily", label: "Close Family" },{ value: "DisablePasskeys", label: "Disable Passkeys" },+ { value: "DeleteAccount", label: "Delete Account" },+ { value: "UpdateSubscription", label: "Update Subscription" }, // New option added here];return (@@ -149,7 +213,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {MORE</button>{dropdownVisible && (- <div className="dropdown-menu">+ <div className="dropdown-menu" ref={dropdownRef}><ul>{dropdownOptions.map((option) => (<li key={option.value}>@@ -178,6 +242,13 @@ export const Sidebar: React.FC<SidebarProps> = ({ token, email }) => {{error ? `Error: ${error}` : `Success: ${message}`}</div>)}+ {showUpdateSubscription && userId && (+ <UpdateSubscription+ token={token}+ userId={userId}+ onClose={() => setShowUpdateSubscription(false)}+ />+ )}</div>);};diff --git a/infra/staff/src/components/UpdateSubscription.tsx b/infra/staff/src/components/UpdateSubscription.tsxnew file mode 100644index 0000000000..2794bdb6b8--- /dev/null+++ b/infra/staff/src/components/UpdateSubscription.tsx@@ -0,0 +1,183 @@+import React, { useEffect, useState } from "react";+import DatePicker from "react-datepicker";+import "react-datepicker/dist/react-datepicker.css";+import "../App.css";+interface UpdateSubscriptionProps {+ token: string;+ userId: string;+ onClose: () => void;+}++export const UpdateSubscription: React.FC<UpdateSubscriptionProps> = ({+ token,+ userId,+ onClose,+}) => {+ const [expiryTime, setExpiryTime] = useState<Date | null>(null);+ const [productId, setProductId] = useState<string>("50gb_monthly");+ const [paymentProvider, setPaymentProvider] = useState<string>("bitpay");+ const [transactionId, setTransactionId] = useState<string>("");+ const [message, setMessage] = useState<string | null>(null);+ const [error, setError] = useState<string | null>(null);+ const [storage, setStorage] = useState<number | "">("");+++ useEffect(() => {+ if (productId === "50gb_yearly" || productId === "50gb_monthly") {+ setStorage(50 * 1024 * 1024 * 1024);+ } else if (+ productId === "200gb_yearly" ||+ productId === "200gb_monthly"+ ) {+ setStorage(200 * 1024 * 1024 * 1024);+ } else if (+ productId === "500gb_yearly" ||+ productId === "500gb_monthly"+ ) {+ setStorage(500 * 1024 * 1024 * 1024);+ } else if (+ productId === "2000gb_yearly" ||+ productId === "2000gb_monthly"+ ) {+ setStorage(2000 * 1024 * 1024 * 1024);+ } else {+ setStorage("");+ }+ }, [productId]);++ const handleSubmit = async (event: React.FormEvent) => {+ event.preventDefault();+++ const expiryTimeTimestamp = expiryTime+ ? expiryTime.getTime() * 1000+ : "";++ const url = `http://localhost:8080/admin/user/subscription`;+ const body = {+ userId,+ storage,+ expiryTime: expiryTimeTimestamp,+ productId,+ paymentProvider,+ transactionId,+ };++ try {+ const response = await fetch(url, {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ "X-AUTH-TOKEN": token,+ },+ body: JSON.stringify(body),+ });++ if (!response.ok) {+ throw new Error(+ `Network response was not ok: ${response.status}`,+ );+ }++ setMessage("Subscription updated successfully");+ setError(null);+ setTimeout(() => {+ setMessage(null);+ onClose();+ }, 1000);+ } catch (error) {+ console.error("Error updating subscription:", error);+ setError(+ error instanceof Error && typeof error.message === "string"+ ? error.message+ : "An unexpected error occurred",+ );+ setTimeout(() => {+ setError(null);+ }, 1000);+ }+ };++ const handleSubmitWrapper = (event: React.FormEvent) => {+ handleSubmit(event).catch((error: unknown) => {+ console.error("Error in handleSubmit:", error);+ });+ };++ return (+ <div className="update-subscription-popup">+ <div className="popup-content">+ <button className="close-button" onClick={onClose}>+ X+ </button>+ <h2>Update Subscription</h2>+ <form onSubmit={handleSubmitWrapper}>+ <div className="form-group">+ <label htmlFor="expiry-time">Expiry Time:</label>+ <DatePicker+ id="expiry-time"+ selected={expiryTime}+ onChange={(date) => setExpiryTime(date)}+ dateFormat="dd/MM/yyyy"+ showYearDropdown+ scrollableYearDropdown+ yearDropdownItemNumber={15}+ />+ </div>+ <div className="form-group">+ <label htmlFor="product-id">Choose Your Plan:</label>+ <select+ id="product-id"+ value={productId}+ onChange={(e) => setProductId(e.target.value)}+ >+ <option value="50gb_monthly">50GB/Month</option>+ <option value="50gb_yearly">50GB/Year</option>+ <option value="200gb_monthly">200GB/Month</option>+ <option value="200gb_yearly">200GB/Year</option>+ <option value="500gb_monthly">500GB/Month</option>+ <option value="500gb_yearly">500GB/Year</option>+ <option value="2000gb_monthly">2000GB/Month</option>+ <option value="2000gb_yearly">2000GB/Year</option>+ </select>+ </div>+ <div className="form-group">+ <label htmlFor="payment-provider">+ Payment Provider:+ </label>+ <select+ id="payment-provider"+ value={paymentProvider}+ onChange={(e) => setPaymentProvider(e.target.value)}+ >+ <option value="bitpay">BitPay</option>+ <option value="paypal">PayPal</option>+ </select>+ </div>+ <div className="form-group">+ <label htmlFor="transaction-id">Transaction ID:</label>+ <input+ id="transaction-id"+ type="text"+ value={transactionId}+ onChange={(e) => setTransactionId(e.target.value)}+ />+ </div>+ <button+ type="submit"+ id="submitbtn"+ >+ Update+ </button>+ </form>+ {(error ?? message) && (+ <div className={`message ${error ? "error" : "success"}`}>+ {error ? `Error: ${error}` : `Success: ${message}`}+ </div>+ )}+ </div>+ </div>+ );+};++export default UpdateSubscription;