/* Copyright 2019 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React from 'react'; import {_t} from "../../../../languageHandler"; import MatrixClientPeg from "../../../../MatrixClientPeg"; import GroupUserSettings from "../../groups/GroupUserSettings"; import PropTypes from "prop-types"; import {MatrixClient} from "matrix-js-sdk"; import { DragDropContext } from 'react-beautiful-dnd'; import ProfileSettings from "../ProfileSettings"; import EmailAddresses from "../EmailAddresses"; import PhoneNumbers from "../PhoneNumbers"; import Field from "../../elements/Field"; import * as languageHandler from "../../../../languageHandler"; import {SettingLevel} from "../../../../settings/SettingsStore"; import SettingsStore from "../../../../settings/SettingsStore"; import LanguageDropdown from "../../elements/LanguageDropdown"; import AccessibleButton from "../../elements/AccessibleButton"; import DeactivateAccountDialog from "../../dialogs/DeactivateAccountDialog"; const PlatformPeg = require("../../../../PlatformPeg"); const sdk = require('../../../../index'); const Modal = require("../../../../Modal"); const dis = require("../../../../dispatcher"); export default class GeneralSettingsTab extends React.Component { static childContextTypes = { matrixClient: PropTypes.instanceOf(MatrixClient), }; constructor() { super(); this.state = { language: languageHandler.getCurrentLanguage(), theme: SettingsStore.getValueAt(SettingLevel.ACCOUNT, "theme"), }; } getChildContext() { return { matrixClient: MatrixClientPeg.get(), }; } _onLanguageChange = (newLanguage) => { if (this.state.language === newLanguage) return; SettingsStore.setValue("language", null, SettingLevel.DEVICE, newLanguage); this.setState({language: newLanguage}); PlatformPeg.get().reload(); }; _onThemeChange = (e) => { const newTheme = e.target.value; if (this.state.theme === newTheme) return; SettingsStore.setValue("theme", null, SettingLevel.ACCOUNT, newTheme); dis.dispatch({action: 'set_theme', value: newTheme}); }; _onPasswordChangeError = (err) => { // TODO: Figure out a design that doesn't involve replacing the current dialog let errMsg = err.error || ""; if (err.httpStatus === 403) { errMsg = _t("Failed to change password. Is your password correct?"); } else if (err.httpStatus) { errMsg += ` (HTTP status ${err.httpStatus})`; } const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); console.error("Failed to change password: " + errMsg); Modal.createTrackedDialog('Failed to change password', '', ErrorDialog, { title: _t("Error"), description: errMsg, }); }; _onPasswordChanged = () => { // TODO: Figure out a design that doesn't involve replacing the current dialog const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createTrackedDialog('Password changed', '', ErrorDialog, { title: _t("Success"), description: _t( "Your password was successfully changed. You will not receive " + "push notifications on other devices until you log back in to them", ) + ".", }); }; _onDeactivateClicked = () => { Modal.createTrackedDialog('Deactivate Account', '', DeactivateAccountDialog, {}); }; _renderProfileSection() { // HACK/TODO: Using DragDropContext feels wrong, but we need it. return (
{_t("Profile")} {_t("Flair")}
); } _renderAccountSection() { const ChangePassword = sdk.getComponent("views.settings.ChangePassword"); const passwordChangeForm = ( ); return (
{_t("Account")}

{_t("Set a new account password...")}

{passwordChangeForm} {_t("Email addresses")} {_t("Phone numbers")}
); } _renderLanguageSection() { // TODO: Convert to new-styled Field return (
{_t("Language and region")}
); } _renderThemeSection() { // TODO: Re-enable theme selection once the themes actually work const SettingsFlag = sdk.getComponent("views.elements.SettingsFlag"); return (
{_t("Theme")}
); } _renderManagementSection() { // TODO: Improve warning text for account deactivation return (
{_t("Account management")} {_t("Deactivating your account is a permanent action - be careful!")} {_t("Close Account")}
); } render() { return (
{_t("General")}
{this._renderProfileSection()} {this._renderAccountSection()} {this._renderLanguageSection()} {this._renderThemeSection()} {this._renderManagementSection()}
); } }