import * as React from "react"; import * as System from "~/components/system"; import * as Actions from "~/common/actions"; import * as Strings from "~/common/strings"; import * as Validations from "~/common/validations"; import * as Window from "~/common/window"; import * as Constants from "~/common/constants"; import * as FileUtilities from "~/common/file-utilities"; import * as UserBehaviors from "~/common/user-behaviors"; import * as Events from "~/common/custom-events"; import * as SVG from "~/common/svg"; import { css } from "@emotion/react"; import { SecondaryTabGroup } from "~/components/core/TabGroup"; import { ConfirmationModal } from "~/components/core/ConfirmationModal"; import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper"; import ScenePage from "~/components/core/ScenePage"; import ScenePageHeader from "~/components/core/ScenePageHeader"; import Avatar from "~/components/core/Avatar"; const STYLES_FILE_HIDDEN = css` height: 1px; width: 1px; opacity: 0; visibility: hidden; position: fixed; top: -1px; left: -1px; `; const STYLES_COPY_INPUT = css` pointer-events: none; position: absolute; opacity: 0; `; const STYLES_HEADER = css` font-family: ${Constants.font.semiBold}; margin-top: 32px; margin-bottom: 16px; `; export default class SceneEditAccount extends React.Component { state = { username: this.props.viewer.username, password: "", confirm: "", body: this.props.viewer.data.body, photo: this.props.viewer.data.photo, name: this.props.viewer.data.name, deleting: false, allow_filecoin_directory_listing: this.props.viewer.data.settings ?.allow_filecoin_directory_listing, allow_automatic_data_storage: this.props.viewer.data.settings?.allow_automatic_data_storage, allow_encrypted_data_storage: this.props.viewer.data.settings?.allow_encrypted_data_storage, changingPassword: false, changingAvatar: false, savingNameBio: false, changingFilecoin: false, modalShow: false, showPassword: false, }; _handleUpload = async (e) => { this.setState({ changingAvatar: true }); let file = await UserBehaviors.uploadImage(e.target.files[0], this.props.resources, true); if (!file) { this.setState({ changingAvatar: false }); return; } const cid = file.cid; const url = Strings.getURLfromCID(cid); let updateResponse = await Actions.updateViewer({ data: { photo: Strings.getURLfromCID(cid), }, }); Events.hasError(updateResponse); this.setState({ changingAvatar: false, photo: url }); }; _handleSaveFilecoin = async (e) => { this.setState({ changingFilecoin: true }); let response = await Actions.updateViewer({ data: { settings: { allow_filecoin_directory_listing: this.state.allow_filecoin_directory_listing, allow_automatic_data_storage: this.state.allow_automatic_data_storage, allow_encrypted_data_storage: this.state.allow_encrypted_data_storage, }, }, }); Events.hasError(response); this.setState({ changingFilecoin: false }); }; _handleSave = async (e) => { if (!Validations.username(this.state.username)) { Events.dispatchMessage({ message: "Please include only letters and numbers in your username", }); return; } let data = { ...this.props.viewer.data, body: this.state.body, name: this.state.name }; this.props.onAction({ type: "UPDATE_VIEWER", viewer: { username: this.state.username, data } }); this.setState({ savingNameBio: true }); let response = await Actions.updateViewer({ username: this.state.username, data: { photo: this.state.photo, body: this.state.body, name: this.state.name, }, }); Events.hasError(response); this.setState({ savingNameBio: false }); }; _handleUsernameChange = (e) => { this.setState({ [e.target.name]: e.target.value.toLowerCase() }); }; _handleChangePassword = async (e) => { if (this.state.password !== this.state.confirm) { Events.dispatchMessage({ message: "Passwords did not match" }); return; } if (!Validations.password(this.state.password)) { Events.dispatchMessage({ message: "Password length must be more than 8 characters" }); return; } this.setState({ changingPassword: true }); let response = await Actions.updateViewer({ type: "CHANGE_PASSWORD", password: this.state.password, }); if (Events.hasError(response)) { this.setState({ changingPassword: false }); return; } this.setState({ changingPassword: false, password: "", confirm: "" }); }; _handleDelete = async (res) => { if (!res) { this.setState({ modalShow: false }); return; } this.setState({ deleting: true }); this.setState({ modalShow: false }); await Window.delay(100); await UserBehaviors.deleteMe({ viewer: this.props.viewer }); window.location.replace("/_/auth"); this.setState({ deleting: false }); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { let tab = this.props.page.params?.tab || "profile"; return ( {tab === "profile" ? (
Your Avatar
Upload avatar
Display name
Bio
Save
) : null} {tab === "storage" ? (
Allow Slate to make Filecoin archive storage deals on your behalf
If this box is checked, then we will make Filecoin archive storage deals on your behalf. By default these storage deals are not encrypted and anyone can retrieve them from the Filecoin Network.
Show your successful deals on a directory page where others can retrieve them. Allow Slate to make archive storage deals on your behalf to the Filecoin Network. You will get a receipt in the Filecoin section. Force encryption on archive storage deals (only you can see retrieved data from the Filecoin network).
Save
) : null} {tab === "security" ? (
Change password
Passwords must be a minimum of eight characters.
this.setState({ showPassword: !this.state.showPassword })} icon={this.state.showPassword ? SVG.EyeOff : SVG.Eye} />
Change password
) : null} {tab === "account" ? (
Change username
Username must be unique.
Changing your username will make any links to your profile or slates that you previously shared invalid.
Change my username
Delete your account
If you choose to delete your account you will lose your Textile Hub and Powergate key.
this.setState({ modalShow: true })} loading={this.state.deleting} style={{ width: "200px" }} > Delete my account
) : null} { this._ref = c; }} value={this.state.copyValue} tabIndex="-1" css={STYLES_COPY_INPUT} />{" "} {this.state.modalShow && ( )}
); } }