-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check team and project name validity (#3034)
* moved the input of the team name into a form that validates the entered name * fixed flow errors * added changelog entry * added regex matching to the check in the backend to the project name * updated changelog entry * changed messages displayed when the entered project name is invalid * changed naming of variables * corrected spelling mistake * update changelog * fine-tune validation messages in team/project creation forms
- Loading branch information
1 parent
50cbed6
commit c98dabd
Showing
3 changed files
with
37 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 29 additions & 38 deletions
67
app/assets/javascripts/admin/team/create_team_modal_view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.teamName, | ||
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("teamName", { | ||
rules: [ | ||
{ | ||
required: true, | ||
pattern: "^[A-Za-z0-9\\-_\\. ß]+$", | ||
message: "The team name must not contain any special characters.", | ||
}, | ||
], | ||
})(<Input icon="tag-o" placeholder="Team Name" autoFocus />)} | ||
</FormItem> | ||
</Form> | ||
</Modal> | ||
); | ||
} | ||
} | ||
const CreateTeamModalView = Form.create()(CreateTeamModalForm); | ||
export default CreateTeamModalView; |