-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check team and project name validity #3034
Changes from 4 commits
79bc459
0eab688
aa046ae
2162f03
aaccd7d
ac47775
56614f4
9331c6e
6d21757
ee4403d
133f8c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,8 +99,14 @@ class ProjectCreateView extends React.PureComponent<Props, State> { | |
rules: [ | ||
{ | ||
required: true, | ||
pattern: "^[a-zA-Z0-9_-]*$", | ||
message: "invalide project name, there are no whitespaces allowed", | ||
}, | ||
{ | ||
min: 3, | ||
required: true, | ||
message: "project name must be at least 3 characters long", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Project name [...] ." (capitalization and full stop) |
||
}, | ||
{ min: 3 }, | ||
], | ||
})(<Input autoFocus disabled={isEditMode} />)} | ||
</FormItem> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,60 @@ | ||
// @flow | ||
import * as React from "react"; | ||
import { Modal, Input, Button } from "antd"; | ||
import { Modal, Input, Form } from "antd"; | ||
import { createTeam } from "admin/admin_rest_api"; | ||
|
||
const FormItem = Form.Item; | ||
|
||
type Props = { | ||
onOk: Function, | ||
onCancel: Function, | ||
isVisible: boolean, | ||
form: Object, | ||
}; | ||
|
||
type State = { | ||
newTeamName: string, | ||
}; | ||
|
||
class CreateTeamModalView extends React.PureComponent<Props, State> { | ||
state = { | ||
newTeamName: "", | ||
}; | ||
|
||
class CreateTeamModalForm extends React.PureComponent<Props> { | ||
onOk = async () => { | ||
if (this.state.newTeamName !== "") { | ||
this.props.form.validateFields(async (err, values) => { | ||
if (err) { | ||
return; | ||
} | ||
const newTeam = { | ||
name: this.state.newTeamName, | ||
name: values["Team Name"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This syntax (having a string instead of a variable inside the square brackets) is usually a sign that something is weird :) In this case, you should rename "Team Name" to "teamName" in your |
||
roles: [{ name: "admin" }, { name: "user" }], | ||
}; | ||
|
||
const team = await createTeam(newTeam); | ||
this.setState({ | ||
newTeamName: "", | ||
}); | ||
|
||
this.props.onOk(team); | ||
} | ||
}); | ||
}; | ||
|
||
isInputValid(): boolean { | ||
return this.state.newTeamName !== ""; | ||
} | ||
|
||
render() { | ||
const { getFieldDecorator } = this.props.form; | ||
return ( | ||
<Modal | ||
title="Add a New Team" | ||
visible={this.props.isVisible} | ||
title="Add a New Team" | ||
okText="Ok" | ||
onCancel={this.props.onCancel} | ||
footer={ | ||
<div> | ||
<Button onClick={this.props.onCancel}>Cancel</Button> | ||
<Button type="primary" onClick={this.onOk} disabled={!this.isInputValid()}> | ||
Ok | ||
</Button> | ||
</div> | ||
} | ||
onOk={this.onOk} | ||
> | ||
<Input | ||
value={this.state.newTeamName} | ||
onChange={(event: SyntheticInputEvent<*>) => | ||
this.setState({ newTeamName: event.target.value }) | ||
} | ||
icon="tag-o" | ||
placeholder="Team Name" | ||
autoFocus | ||
/> | ||
<Form layout="vertical"> | ||
<FormItem label="Team Name"> | ||
{getFieldDecorator("Team Name", { | ||
rules: [ | ||
{ | ||
required: true, | ||
pattern: "^[A-Za-z0-9\\-_\\. ß]+$", | ||
message: "Please enter a valide team name.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. valid without e :) |
||
}, | ||
], | ||
})(<Input icon="tag-o" placeholder="Team Name" autoFocus />)} | ||
</FormItem> | ||
</Form> | ||
</Modal> | ||
); | ||
} | ||
} | ||
const CreateTeamModalView = Form.create()(CreateTeamModalForm); | ||
export default CreateTeamModalView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "The project name must not contain whitespace." (with fullstop), since this is a user-facing message.