slates: adds limit per user

This commit is contained in:
@wwwjim 2020-09-09 03:01:49 -07:00
parent af9d11f3f6
commit 7b053ce30a
2 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import * as Constants from "~/common/constants";
import * as System from "~/components/system";
import * as Validations from "~/common/validations";
const SLATE_LIMIT = 20;
export default class SidebarCreateSlate extends React.Component {
state = {
name: "",
@ -11,6 +13,11 @@ export default class SidebarCreateSlate extends React.Component {
};
_handleSubmit = async () => {
if (this.props.viewer.slates.length >= SLATE_LIMIT) {
alert("You have reached the limit of 20 Slates.");
return;
}
this.setState({ loading: true });
if (!Validations.slatename(this.state.name)) {
@ -72,7 +79,8 @@ export default class SidebarCreateSlate extends React.Component {
full
style={{ marginTop: 48 }}
onClick={this._handleSubmit}
loading={this.state.loading}>
loading={this.state.loading}
>
Create {this.state.name}
</System.ButtonPrimary>
</div>

View File

@ -2,6 +2,8 @@ import * as Utilities from "~/node_common/utilities";
import * as Data from "~/node_common/data";
import * as Strings from "~/common/strings";
const SLATE_LIMIT = 20;
export default async (req, res) => {
const id = Utilities.getIdFromCookie(req);
if (!id) {
@ -38,6 +40,13 @@ export default async (req, res) => {
.send({ decorator: "SERVER_EXISTING_SLATE", error: true });
}
const slates = await Data.getSlatesByUserId({ userId: id });
if (slates.length >= SLATE_LIMIT) {
return res
.status(500)
.send({ decorator: "SERVER_SLATE_LIMIT", error: true });
}
const slate = await Data.createSlate({
slatename: Strings.createSlug(req.body.data.name),
data: {