slate/components/sidebars/SidebarCreateSlate.js

87 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-07-27 04:51:51 +03:00
import * as React from "react";
import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
import * as SVG from "~/components/system/svg";
import * as System from "~/components/system";
import { css } from "@emotion/react";
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
export default class SidebarCreateSlate extends React.Component {
state = {
name: "",
loading: false,
};
_handleSubmit = async () => {
this.setState({ loading: true });
2020-07-27 12:50:25 +03:00
if (Strings.isEmpty(this.state.name)) {
2020-07-27 04:51:51 +03:00
alert("TODO: Provide a name");
2020-07-27 12:50:25 +03:00
this.setState({ loading: false });
2020-07-27 04:51:51 +03:00
return;
}
const response = await this.props.onSubmit({
type: "CREATE_SLATE",
name: this.state.name,
});
if (response && response.error) {
2020-07-27 04:51:51 +03:00
// TODO(jim): Error task.
alert(response.decorator);
}
this.setState({ loading: false });
};
_handleCancel = () => {
this.props.onCancel();
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
return (
<div>
<System.P style={{ fontFamily: Constants.font.semiBold }}>
Create Slate
</System.P>
<System.Input
containerStyle={{ marginTop: 24 }}
label="Slate name"
name="name"
value={this.state.name}
onChange={this._handleChange}
/>
<System.P style={{ marginTop: 24 }}>
This will create a new slate address at https://slate.host/
2020-07-27 04:51:51 +03:00
{this.props.viewer.username}/{Strings.createSlug(this.state.name)}
</System.P>
2020-08-02 22:17:13 +03:00
<System.ButtonPrimary
full
2020-07-27 04:51:51 +03:00
style={{ marginTop: 48 }}
onClick={this._handleSubmit}
loading={this.state.loading}
>
Create {this.state.name}
2020-08-02 22:17:13 +03:00
</System.ButtonPrimary>
2020-07-27 04:51:51 +03:00
2020-08-02 22:17:13 +03:00
<System.ButtonSecondary
full
2020-07-27 04:51:51 +03:00
style={{ marginTop: 16 }}
onClick={this._handleCancel}
2020-07-27 04:51:51 +03:00
>
Cancel
2020-08-02 22:17:13 +03:00
</System.ButtonSecondary>
2020-07-27 04:51:51 +03:00
</div>
);
}
}