mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-22 21:45:56 +03:00
slates: adds limit per user
This commit is contained in:
parent
af9d11f3f6
commit
7b053ce30a
@ -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>
|
||||
|
@ -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: {
|
||||
|
Loading…
Reference in New Issue
Block a user