import * as React from "react";
import * as Actions from "~/common/actions";
import * as Constants from "~/common/constants";
import * as System from "~/components/system";
import { css } from "@emotion/react";
const STYLES_GROUP = css`
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
overflow-wrap: break-word;
white-space: pre-wrap;
`;
const STYLES_LEFT = css`
padding: 12px 0 0 0;
min-width: 10%;
overflow-wrap: break-word;
white-space: pre-wrap;
`;
const STYLES_RIGHT = css`
padding-left: 48px;
padding-top: 24px;
flex-shrink: 0;
`;
export default class SidebarSingleSlateSettings extends React.Component {
state = {
slatename: this.props.data.slatename,
public: this.props.data.data.public,
body: this.props.data.data.body,
layouts: this.props.data.data.layouts,
loading: false,
};
_handleSubmit = async () => {
this.setState({ loading: true });
const response = await Actions.updateSlate({
id: this.props.data.slateId,
slatename: this.state.slatename,
data: {
objects: this.props.data.data.objects,
layouts: this.props.data.data.layouts,
public: this.state.public,
body: this.state.body,
},
});
if (!response) {
alert("TODO: Server Error");
return this.setState({ loading: false });
}
if (response.error) {
alert(`TODO: ${response.decorator}`);
return this.setState({ loading: false });
}
await this.props.onSubmit({});
};
_handleCancel = () => {
this.props.onCancel();
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
_handleDelete = async (e) => {
this.setState({ loading: true });
if (!window.confirm("Are you sure you want to delete this Slate? This action is irreversible.")) {
return this.setState({ loading: false });
}
const response = await Actions.deleteSlate({
id: this.props.data.slateId,
});
if (!response) {
alert("TODO: Server Error");
return this.setState({ loading: false });
}
if (response.error) {
alert(`TODO: ${response.decorator}`);
return this.setState({ loading: false });
}
await this.props.onAction({
type: "NAVIGATE",
value: "V1_NAVIGATION_SLATES",
});
return await this.props.onRehydrate();
};
render() {
const { slatename } = this.state;
const url = `/${this.props.viewer.username}/${slatename}`;
return (