diff --git a/src/components/SettingsPage/index.jsx b/src/components/SettingsPage/index.jsx deleted file mode 100644 index facfadd..0000000 --- a/src/components/SettingsPage/index.jsx +++ /dev/null @@ -1,1970 +0,0 @@ -import React from "react"; -import Header from "../Header/Header"; -import axios from "../../axiosInterceptor"; -import env from "../../enviroment/envFrontEnd"; -import Swal from "sweetalert2"; -import bytes from "bytes"; -import moment from "moment"; -import capitalize from "../../utils/capitalize"; -import { resetCurrentRoute } from "../../actions/routes"; -import { setFolders } from "../../actions/folders"; -import { setQuickFiles } from "../../actions/quickFiles"; -import { hideSettings } from "../../actions/settings"; -import { startLogout, startLogoutAll } from "../../actions/auth"; -import { setFiles, startResetCache } from "../../actions/files"; -import { connect } from "react-redux"; -import { setParent } from "../../actions/parent"; -import uuid from "uuid"; -import { setUpdateSettingsID } from "../../utils/updateSettings"; -import HomepageSpinner from "../HomepageSpinner/HomepageSpinner"; -import { setLoading } from "../../actions/main"; -import withNavigate from "../HocComponent"; -// import {updateSettingsID} from "../MainSection" -// import { resetSettingsMain } from "../../actions/main"; - -class SettingsPageContainer extends React.Component { - constructor(props) { - super(props); - - this.state = { - sideBarOpen: false, - mode: "general", - loaded: false, - userDetails: {}, - addS3AccountOpen: false, - s3ID: "", - s3Key: "", - s3Bucket: "", - addGoogleAccountOpen: false, - googleID: "", - googleSecret: "", - invoiceData: {}, - invoices: [], - invoicesLoaded: false, - showChangePassword: false, - oldPassword: "", - newPassword: "", - verifyNewPassword: "", - showAddName: false, - name: "", - listView: true, - dateSort: true, - descendingSort: true, - dropToUpload: true, - doubleClickFolders: false, - hideFolderTree: false, - showFolderTreeScrollBars: false, - }; - - this.uploadReference = React.createRef(); - } - - getUserDetails = () => { - this.props.dispatch(setLoading(true)); - - axios - .get("/user-service/user-detailed") - .then((response) => { - env.name = response.data.name; - env.emailAddress = response.data.email; - this.props.dispatch(setParent(uuid.v4())); - - this.setState( - () => { - return { - ...this.state, - loaded: true, - userDetails: response.data, - }; - }, - () => { - // this.getInvoiceData(); - this.props.dispatch(setLoading(false)); - } - ); - }) - .catch((err) => { - console.log("Loading user details error", err); - - Swal.fire({ - title: "Error loading user account", - text: "There was an error loading your account, would you like to logout?", - icon: "warning", - showCancelButton: true, - confirmButtonText: "Yes, logout", - cancelButtonText: "No", - }).then((result) => { - if (result.value) { - console.log("Confirm logout"); - - axios - .post("/user-service/logout") - .then(() => { - window.location.assign(env.url); - }) - .catch((e) => { - window.location.assign(env.url); - }); - } - }); - }); - }; - - componentDidMount = () => { - this.getUserDetails(); - this.setSettings(); - - //console.log("env sub", this.state.userDetails.activeSubscription) - }; - - setSettings = () => { - const gridMode = window.localStorage.getItem("grid-mode"); - const nameMode = window.localStorage.getItem("name-mode"); - const ascMode = window.localStorage.getItem("asc-mode"); - const dropToUpload = window.localStorage.getItem("non_drop-mode"); - const doubleClickFolders = window.localStorage.getItem( - "double-click-folders" - ); - const hideFolderTree = window.localStorage.getItem("hide-folder-tree"); - const showFolderTreeScrollBars = window.localStorage.getItem( - "show-folder-tree-scroll-bars" - ); - - this.setState(() => { - return { - ...this.state, - listView: !gridMode, - dateSort: !nameMode, - descendingSort: !ascMode, - dropToUpload: !dropToUpload, - doubleClickFolders: doubleClickFolders, - hideFolderTree: hideFolderTree, - showFolderTreeScrollBars, - }; - }); - }; - - showSideBar = () => { - this.setState(() => { - return { - ...this.state, - sideBarOpen: !this.state.sideBarOpen, - }; - }); - }; - - modeChangeFullScreen = (type) => { - this.setState(() => { - return { - ...this.state, - mode: type, - }; - }); - }; - - modeChange = (type) => { - this.setState( - () => { - return { - ...this.state, - mode: type, - }; - }, - () => { - this.showSideBar(); - } - ); - //this.showSideBar() - }; - - getProfilePicName = () => { - if (!this.state.loaded) return "?"; - - if (this.state.userDetails.name) { - if (this.state.userDetails.name.length >= 1) { - return this.state.userDetails.name.substring(0, 1).toUpperCase(); - } else { - return "?"; - } - } else if (this.state.userDetails.email.length >= 1) { - return this.state.userDetails.email.substring(0, 1).toUpperCase(); - } else { - return "?"; - } - }; - - onChangeS3ID = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - s3ID: value, - }; - }); - }; - - onChangeS3Bucket = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - s3Bucket: value, - }; - }); - }; - - onChangeS3Key = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - s3Key: value, - }; - }); - }; - - onChangeGoogleID = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - googleID: value, - }; - }); - }; - - onChangeGoogleSecret = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - googleSecret: value, - }; - }); - }; - - showS3Account = () => { - this.setState(() => { - return { - ...this.state, - addS3AccountOpen: !this.state.addS3AccountOpen, - }; - }); - }; - - showGoogleAccount = () => { - this.setState(() => { - return { - ...this.state, - addGoogleAccountOpen: !this.state.addGoogleAccountOpen, - }; - }); - }; - - submitS3Account = (e) => { - e.preventDefault(); - - const data = { - id: this.state.s3ID, - bucket: this.state.s3Bucket, - key: this.state.s3Key, - }; - - axios - .post("/user-service/add-s3-storage", data) - .then((response) => { - Swal.fire( - "S3 Account Added", - "Amazon S3 Account has been linked with myDrive", - "success" - ).then(() => { - //window.location.assign(env.url); - env.s3Enabled = true; - - this.getUserDetails(); - this.showS3Account(); - // let newUser = this.state.userDetails; - // newUser = {...newUser, s3Enabled: true} - }); - }) - .catch((err) => { - Swal.fire({ - icon: "error", - title: "Add S3 Account Error", - text: "Invalid S3 Credentials", - }); - }); - }; - - getInvoiceData = () => { - if (!env.commercialMode || !this.state.userDetails.activeSubscription) - return; - - axios - .get("/user-service/payments") - .then((response) => { - const invoices = response.data.invoices; - - let invoiceDetails = response.data; - //delete invoiceDetails.invoices; - - this.setState(() => { - return { - ...this.state, - invoiceData: invoiceDetails, - invoices, - invoicesLoaded: true, - }; - }); - }) - .catch((e) => { - console.log("invoice err", e); - }); - }; - - removeS3Account = (e) => { - if (e) e.preventDefault(); - - Swal.fire({ - title: "Remove S3 Account?", - text: "This will unlink your Amazon S3 Account from myDrive.", - icon: "warning", - showCancelButton: true, - confirmButtonColor: "#3085d6", - cancelButtonColor: "#d33", - confirmButtonText: "Yes, remove account", - }).then((result) => { - if (result.value) { - axios - .delete("/user-service/remove-s3-storage") - .then((response) => { - let newUser = this.state.userDetails; - delete newUser.s3Enabled; - - env.s3Enabled = undefined; - this.setState(() => { - return { - ...this.state, - userDetails: newUser, - }; - }); - - this.showS3Account(); - Swal.fire( - "S3 Account Removed", - "Your Amazon S3 Account has been unlinked from myDrive", - "success" - ); - }) - .catch((err) => { - console.log("could not remove google account", err); - }); - } - }); - }; - - refreshStorageSize = () => { - axios - .patch("/user-service/refresh-storage-size", undefined) - .then((response) => { - this.getUserDetails(); - }) - .catch((err) => { - console.log("refresh storage error"); - }); - }; - - submitGoogleAccount = (e) => { - e.preventDefault(); - - const clientID = this.state.googleID; - const clientKey = this.state.googleSecret; - const clientRedirect = "/add-google-account"; - - const data = { - clientID, - clientKey, - clientRedirect, - }; - - axios - .post("/user-service/create-google-storage-url", data) - .then((response) => { - const googleURL = response.data; - - window.location.assign(googleURL); - }) - .catch((err) => { - console.log("create url error", err); - }); - }; - - removeGoogleAccount = (e) => { - e.preventDefault(); - - axios.delete("/user-service/remove-google-storage").then((response) => { - env.googleDriveEnable = undefined; - this.showGoogleAccount(); - this.getUserDetails(); - Swal.fire( - "Google Account Removed", - "Your Google Account has been unlinked from myDrive", - "success" - ).then(() => { - // window.location.assign(env.url) - }); - }); - }; - - getStoragePercentage = () => { - let value = Math.floor( - (this.state.userDetails.storageData.storageSize / - this.state.userDetails.storageData.storageLimit) * - 100 - ); - - if (value < 0) value = 0; - if (value > 100) value = 100; - - return value; - }; - - getStoragePercentageGoogle = () => { - let value = Math.floor( - (this.state.userDetails.storageDataGoogle.storageSize / - this.state.userDetails.storageDataGoogle.storageLimit) * - 100 - ); - - if (value < 0) value = 0; - if (value > 100) value = 100; - - return value; - }; - - launchStoragePage = () => { - window.location.assign(env.url + "/add-storage"); - }; - - logout = () => { - this.props.dispatch(resetCurrentRoute()); - this.props.dispatch(setFolders([])); - this.props.dispatch(setFiles([])); - this.props.dispatch(setQuickFiles([])); - this.props.dispatch(hideSettings()); - this.props.dispatch(startLogout()); - }; - - logoutAll = () => { - this.props.dispatch(resetCurrentRoute()); - this.props.dispatch(setFolders([])); - this.props.dispatch(setFiles([])); - this.props.dispatch(setQuickFiles([])); - this.props.dispatch(hideSettings()); - this.props.dispatch(startLogoutAll()); - }; - - changeShowChangePassword = () => { - this.setState(() => { - return { - ...this.state, - showChangePassword: !this.state.showChangePassword, - oldPassword: "", - newPassword: "", - verifyNewPassword: "", - }; - }); - }; - - goHome = () => { - this.props.navigate("/"); - }; - - onChangeOldPassword = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - oldPassword: value, - }; - }); - }; - - onChangeNewPassword = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - newPassword: value, - }; - }); - }; - - onChangeVerifyNewPassword = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - verifyNewPassword: value, - }; - }); - }; - - submitPasswordChange = (e) => { - e.preventDefault(); - - if ( - this.state.oldPassword.length === 0 || - this.state.newPassword.length === 0 || - this.state.verifyNewPassword.length === 0 - ) { - Swal.fire({ - icon: "error", - title: "Error", - text: "Enter All Required Fields", - }); - } - - if (this.state.verifyNewPassword !== this.state.newPassword) { - Swal.fire({ - icon: "error", - title: "Error", - text: "New passwords do not match", - }); - return; - } - - const data = { - newPassword: this.state.newPassword, - oldPassword: this.state.oldPassword, - }; - - axios - .post(`/user-service/change-password/`, data) - .then((results) => { - //const newToken = results.data; - // window.localStorage.setItem("token", newToken); - - this.changeShowChangePassword(); - //this.getUserDetails() - - Swal.fire( - "Password Changed", - "All other sessions have been logged out", - "success" - ); - }) - .catch((err) => { - console.log(err); - Swal.fire({ - icon: "error", - title: "Error", - text: "Error changing password", - }); - }); - }; - - onChangeAddName = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - name: value, - }; - }); - }; - - doubleClickOnChange = (e) => { - if (this.state.doubleClickFolders) { - localStorage.removeItem("double-click-folders"); - } else { - localStorage.setItem("double-click-folders", "true"); - } - - this.setState(() => { - return { - ...this.state, - doubleClickFolders: !this.state.doubleClickFolders, - }; - }); - - //this.props.dispatch(resetSettingsMain(uuid.v4())); - // updateSettingsID = uuid.v4(); - // setUpdateSettingsID(uuid.v4()); - }; - - changeShowAddName = () => { - this.setState(() => { - return { - ...this.state, - showAddName: !this.state.showAddName, - name: "", - }; - }); - }; - - submitAddName = (e) => { - e.preventDefault(); - - if (this.state.name.length === 0) return; - - const data = { - name: this.state.name, - }; - - axios - .patch("/user-service/add-name", data) - .then((response) => { - this.changeShowAddName(); - this.getUserDetails(); - Swal.fire( - "Name Updated", - "Your name has been sucessfully updated", - "success" - ); - }) - .catch(() => { - console.log("could not change name"); - Swal.fire({ - icon: "error", - title: "Error", - text: "Error changing name", - }); - }); - }; - - goHome = () => { - this.props.navigate("/"); - }; - - downloadPersonalFileList = (e) => { - e.preventDefault(); - - axios.post("/user-service/get-token").then((response) => { - const finalUrl = `/user-service/download-personal-file-list`; - - const link = document.createElement("a"); - document.body.appendChild(link); - link.href = finalUrl; - link.setAttribute("type", "hidden"); - link.setAttribute("download", true); - link.click(); - }); - }; - - uploadPersonalFileList = (e) => { - e.preventDefault(); - - if ( - this.uploadReference.current.files && - this.uploadReference.current.files[0] - ) { - const currentFile = this.uploadReference.current.files[0]; - - const config = { - headers: { - "Content-Type": "application/json", - }, - }; - - axios - .post("/user-service/upload-personal-file-list", currentFile, config) - .then((response) => { - this.uploadReference.current.value = ""; - - Swal.fire( - "Personal Data Uploaded", - "Your Peronsal Metadata has been uploaded to myDrive successfully", - "success" - ); - }) - .catch((err) => { - console.log("upload personal file list error", err); - Swal.fire({ - icon: "error", - title: "Error", - text: "Error uploading personal file list", - }); - }); - } - }; - - removeS3Metadata = (e) => { - e.preventDefault(); - - Swal.fire({ - title: "Remove S3 Metadata?", - text: "This will remove all S3 Metadata from myDrive, please download your metadata list before removing.", - icon: "warning", - showCancelButton: true, - confirmButtonColor: "#3085d6", - cancelButtonColor: "#d33", - confirmButtonText: "Yes, remove metadata", - }).then((result) => { - if (result.value) { - axios - .delete("/user-service/remove-s3-metadata") - .then((response) => { - Swal.fire( - "S3 Metadata removed", - "Your S3 metadata has been removed from myDrive successfully.", - "success" - ); - }) - .catch((err) => { - console.log("delete s3 data err", err); - Swal.fire({ - icon: "error", - title: "Error", - text: "Error deleting S3 metadata", - }); - }); - } - }); - }; - - listViewOnChange = (e) => { - if (this.state.listView) { - window.localStorage.setItem("grid-mode", true); - } else { - window.localStorage.removeItem("grid-mode"); - } - - this.setState(() => { - return { - ...this.state, - listView: !this.state.listView, - }; - }); - - // this.setSettings(); - }; - - sortByDateChange = () => { - if (this.state.dateSort) { - window.localStorage.setItem("name-mode", true); - } else { - window.localStorage.removeItem("name-mode"); - } - - this.setState(() => { - return { - ...this.state, - dateSort: !this.state.dateSort, - }; - }); - }; - - sortByDescendingChange = () => { - if (this.state.descendingSort) { - window.localStorage.setItem("asc-mode", true); - } else { - window.localStorage.removeItem("asc-mode"); - } - - this.setState(() => { - return { - ...this.state, - descendingSort: !this.state.descendingSort, - }; - }); - }; - - dropOnChange = () => { - if (this.state.dropToUpload) { - window.localStorage.setItem("non_drop-mode", true); - } else { - window.localStorage.removeItem("non_drop-mode"); - } - - this.setState(() => { - return { - ...this.state, - dropToUpload: !this.state.dropToUpload, - }; - }); - }; - - hideFolderTreeOnChange = () => { - if (this.state.hideFolderTree) { - window.localStorage.removeItem("hide-folder-tree"); - } else { - console.log("setting hide folder tree to true"); - - window.localStorage.setItem("hide-folder-tree", true); - } - - this.setState(() => ({ - ...this.state, - hideFolderTree: !this.state.hideFolderTree, - })); - }; - - showFolderTreeScrollBarsOnChange = () => { - if (this.state.showFolderTreeScrollBars) { - window.localStorage.removeItem("show-folder-tree-scroll-bars"); - } else { - window.localStorage.setItem("show-folder-tree-scroll-bars", true); - } - - this.setState(() => ({ - ...this.state, - showFolderTreeScrollBars: !this.state.showFolderTreeScrollBars, - })); - }; - - render() { - if (this.props.loading) { - return ; - } - - return ( -
-
-
- -
- -
- - - -
-
- - - - {/* - - */} -
-
-
-
-
-

Personal info

-
-
-
-

Profile picture

-
-
-
-

- - {this.getProfilePicName()} - -

-
-
-
- {/* Upload */} -
-
-
-
-

Name

-
-
-

- {this.state.loaded - ? this.state.userDetails.name - ? capitalize(this.state.userDetails.name) - : "No Name Set" - : "Loading..."} -

-
-
- Change -
-
-
-
-
-

Security

-
-
-
-

Logout Account

-
-
-

-
-
- Logout -
-
-
-
-

Email

-
-
-

- {this.state.loaded - ? this.state.userDetails.email - : "Loading..."} -

-
-
- {/* Change */} -
-
- -
-
-

Password

-
-
-

- {this.state.loaded - ? this.state.userDetails.passwordLastModified - ? `Updated ${moment( - this.state.userDetails.passwordLastModified - ).calendar()}` - : "Password Not Updated Yet" - : "Loading..."} -

-
- -
- -
-
-

Logout All Accounts

-
-
-

-
- -
- {/*
-
-

Two factor authentication

-
-
-

Disabled

-
-
- Enable -
-
*/} -
- -
-
-

Preferences

-
-
-
-

Language

-
-
-

English

-
-
- Change -
-
-
-
-

Date format

-
-
-

MM / DD / YYYY

-
-
- Change -
-
- -
-
-

Date Time zone

-
-
-

GMT +7

-
-
- Change -
-
-
-
-
-
-
-

Storage Accounts

-
-
-
-
-
-

- {env.commercialMode ? "myDrive" : "Local Storage"} -

- - {!this.state.loaded - ? "Loading..." - : env.commercialMode && - this.state.userDetails.activeSubscription - ? "Plan Type" - : ""} - -
-
-
-
-
-
-
- - {!this.state.loaded - ? "Loading..." - : env.commercialMode && - this.state.userDetails.activeSubscription - ? `${bytes( - this.state.userDetails.storageData - .storageSize - )} of - ${bytes( - this.state.userDetails.storageData.storageLimit - )} used` - : !env.commercialMode - ? `${bytes( - this.state.userDetails.storageData - .storageSize - )} used` - : ""} - -
-
- -
-
-

- star{" "} - Earn more free space. Get an additional - 10GB of storage for every friend you invite. -

- Invite Friends -
-
-
-
-
-

Google Drive

- - {!this.state.loaded - ? "Loading..." - : this.state.userDetails.googleDriveEnabled - ? this.state.userDetails.googleDriveData.id - : "No Google Account"} - -
-
-
-
-
-
-
- - {this.state.userDetails.googleDriveEnabled - ? !this.state.userDetails.storageDataGoogle.failed - ? `${bytes( - this.state.userDetails.storageDataGoogle - .storageSize - )} of - ${bytes( - this.state.userDetails.storageDataGoogle.storageLimit - )} used` - : "Failed" - : ""} - -
-
- -
- -
-
-
-

Amazon S3

- - {!this.state.loaded - ? "Loading..." - : this.state.userDetails.s3Enabled - ? this.state.userDetails.s3Data.bucket - : "S3 Not Enabled"} - -
-
-
-
-
-
-
- - {this.state.userDetails.s3Enabled - ? !this.state.userDetails.storageDataPersonal - .failed - ? `${bytes( - this.state.userDetails.storageDataPersonal - .storageSize - )} used` - : "Failed" - : ""} - -
-
- -
-
-
-
-

Add more accounts

-
-
-

More Storage Options Coming Soon!

-
-
-
-

BackBlaze

-
-
- Enable -
-
-
-
-

Sia Network

-
-
- Enable -
-
-
-
-

Localhost

-
-
- Enable -
-
-
-
- -
-
-
-

Payment

-
-
-
-

Payment method

-
-
-

- {this.state.loaded && this.state.invoicesLoaded - ? !this.state.invoiceData.card - ? "No Payment Method" - : `${this.state.invoiceData.card.brand} ending in ${this.state.invoiceData.card.last4}` - : "No Payment Method"} -

-
-
- Change -
-
-
-
-

Billing cycle

-
-
-

- {this.state.loaded && this.state.invoicesLoaded - ? !this.state.invoiceData.subscription - ? "No Subscription" - : capitalize( - this.state.invoiceData.subscription.plan - .interval - ) - : "No Subscription"} -

-
-
- Change -
-
-
-
-
-

History

-
-
- - - - - - - - - - {/* - - - - - - - - - - - - - - - - - - - - */} -
DATEPLANAMOUNTSTATUS
May 1, 2020myDrive Standard Plan$9.99Unpaid - Invoice -
May 1, 2020myDrive Standard Plan$9.99Paid - Receipt -
May 1, 2020myDrive Standard Plan$9.99Paid - Receipt -
-
-
-
- -
-
-
-

Customization

-
-
- Set Defaults -

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-
-
- - {/*
-
-

Marketing

-
-
- Email me about -

- - -

-

- - -

-

- - -

-
-
*/} -
-
-
-
-
- -
-
-
-
-

- {!this.state.loaded - ? "Loading..." - : this.state.userDetails.s3Enabled - ? "Edit Amazon S3 Account" - : "Add Amazon S3 Account"} -

-
- - close - -
-
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
- {/* */} - -
-
-
-
-
- -

Upload S3 Metadata List

-
- {/* */} -
-
-
-
- {/* */} - -
-
-
-
-
-
- -
-
-
-
-

- {!this.state.loaded - ? "Loading..." - : this.state.userDetails.googleDriveEnabled - ? "Remove Google Drive Account" - : "Add Google Drive Account"} -

-
- - close - -
-
-
-
-
- -
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-

Update password

-
- - close - -
-
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-

{"Update Name"}

-
- - close - -
-
-
-
-
- -
-
- -
-
-
-
-
-
-
- ); - } -} - -const connectStoreToProp = (state) => ({ - loading: state.main.loading, -}); - -export default connect(connectStoreToProp)(withNavigate(SettingsPageContainer)); diff --git a/src/routers/AppRouter.jsx b/src/routers/AppRouter.jsx index bd4ee69..5f7001d 100755 --- a/src/routers/AppRouter.jsx +++ b/src/routers/AppRouter.jsx @@ -14,9 +14,8 @@ import DownloadPage from "../components/DownloadPage/DownloadPage"; import VerifyEmailPage from "../components/VerifyEmailPage"; import uuid from "uuid"; import ResetPasswordPage from "../components/ResetPasswordPage"; -import SettingsPage from "../components/SettingsPage"; +import SettingsPage from "../components/SettingsPage/SettingsPage"; import Homepage from "../components/Homepage/Homepage"; -import SettingsPage2 from "../components/SettingsPage/SettingsPage"; // export const history = createHistory(); @@ -103,13 +102,11 @@ const AppRouter = () => { /> } /> } /> - } /> - + } />