import * as React from "react"; import * as Strings from "~/common/strings"; import * as Constants from "~/common/constants"; import * as System from "~/components/system"; import * as Validations from "~/common/validations"; import * as Actions from "~/common/actions"; import * as Events from "~/common/custom-events"; import * as SVG from "~/common/svg"; import * as UserBehaviors from "~/common/user-behaviors"; import { RadioGroup } from "~/components/system/components/RadioGroup"; import { css } from "@emotion/react"; const STYLES_TEXT = css` color: ${Constants.semantic.textGray}; font-size: ${Constants.typescale.lvl0}; `; const STYLES_HEADER = css` font-family: ${Constants.font.semiBold}; `; const STYLES_GROUPING = css` width: 100%; border: 1px solid rgba(196, 196, 196, 0.5); background-color: ${Constants.system.white}; border-radius: 6px; padding: 16px; margin-bottom: 24px; `; export default class SidebarCreateSlate extends React.Component { state = { name: "", isPublic: true, body: "", loading: false, }; _handleSubmit = async () => { this.setState({ loading: true }); if (!Validations.slatename(this.state.name)) { Events.dispatchMessage({ message: "Please provide a name between 1-48 characters." }); this.setState({ loading: false }); return; } const response = await Actions.createSlate({ name: this.state.name, isPublic: this.state.isPublic, body: this.state.body, }); console.log(response); if (Events.hasError(response)) { this.setState({ loading: false }); return; } if (this.props.sidebarData && this.props.sidebarData.files) { await UserBehaviors.saveCopy({ slate: response.slate, files: this.props.sidebarData.files, }); // if (Events.hasError(addResponse)) { // this.setState({ loading: false }); // return; // } // const { added, skipped } = addResponse; // let message = Strings.formatAsUploadMessage(added, skipped, true); // if (message) { // Events.dispatchMessage({ message, status: !added ? null : "INFO" }); // } } this.setState({ loading: false }); window.setTimeout( () => this.props.onAction({ type: "NAVIGATE", href: `/$/slate/${response.slate.id}`, }), 200 ); }; _handleCancel = () => { this.props.onCancel(); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { const slug = Strings.createSlug(this.state.name); const url = `/${this.props.viewer.username}/${slug}`; return (