Skip to content

Commit

Permalink
ft(create-github-repo): implement create github-repo
Browse files Browse the repository at this point in the history
- add transform-runtime in .babelrc for asyn/await support
- install babel-plugin-transform-runtime for built-ins ES 6
- add functionality to create github-repo

[Finishes #161033134]
  • Loading branch information
phemonick committed Oct 8, 2018
1 parent 09908a0 commit f95c865
Show file tree
Hide file tree
Showing 6 changed files with 3,417 additions and 3,367 deletions.
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"plugins": [
"transform-class-properties",
"transform-object-rest-spread",
"transform-decorators-legacy"
"transform-decorators-legacy",
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
]
}
10 changes: 6 additions & 4 deletions client/src/modules/CreateTeam/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Dropdown } from 'semantic-ui-react'
import slack from '../../../../public/resources/images/slack.png';
import pt from '../../../../public/resources/images/pt.jpg'
import pt from '../../../../public/resources/images/pt.jpg';

const Form = ({
handleChange,
name,
desc,
checked,
handleSubmit,
submitting
submitting,
menuChange
}) => {
let showSubmitButton = false;
let teamName = 'example';
Expand Down Expand Up @@ -88,8 +89,9 @@ const Form = ({
</div>
</div>
<div className="team-accounts top-margin">
<i className="fab fa-github integration-icon"></i>
<Dropdown placeholder='Repo name' fluid multiple selection search options={githubOptions} />
<i className="fab fa-github integration-icon">`</i>
<Dropdown name='github' onChange={menuChange} placeholder='Repo name'
fluid multiple selection search options={githubOptions} />
</div>
<div className="team-accounts top-margin">
<img src={pt} className="integration-icon small-icon" alt="pt-image"/>
Expand Down
21 changes: 17 additions & 4 deletions client/src/modules/CreateTeam/container/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class CreateTeam extends Component {
name: '',
description: '',
visibility: false,
submitting: false
submitting: false,
integrations: {
github: []
}
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
Expand Down Expand Up @@ -58,11 +61,12 @@ class CreateTeam extends Component {

handleSubmit(event) {
event.preventDefault();
const { name, visibility, description } = this.state;
const { name, visibility, description, integrations } = this.state;
const data = {
name,
description,
private: visibility
private: visibility,
integrations
};
if (!name.trim() || !description.trim()) {
return errorMessage('All fields are required');
Expand All @@ -75,15 +79,22 @@ class CreateTeam extends Component {
submitting: !prevState.submitting
}));
}

handleChange(event) {
this.setState({
[event.target.name]: event.target.value
});
}

menuChange = (event, item) => {
this.setState({
integrations: {...this.state.integrations, [item.name]: item.value }
})
}

render() {
const {
name, description, visibility
name, description, visibility, github
} = this.state;
return (
<React.Fragment>
Expand All @@ -93,9 +104,11 @@ class CreateTeam extends Component {
<Form
handleSubmit={this.handleSubmit}
handleChange={this.handleChange}
menuChange={this.menuChange}
name={name}
desc={description}
checked={visibility}
github={github}
submitting={this.props.isFetching.isLoading}
/>
</div>
Expand Down
47 changes: 34 additions & 13 deletions client/src/redux/actions/teams/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,43 @@ export const fetchTeams = (limit, offset, query = '') => dispatch => {
});
};

export const createTeam = data => dispatch => {
export const createTeam = data => async (dispatch) => {
dispatch(isLoading(true));
return instance
.post('teams', data)
.then(response => {
dispatch(success(CREATE_TEAM, response.data));
dispatch(isLoading(false));
if (response.data.errors) {
errorMessage(response.data.errors[0]);
return;
try {
const teamInfo = {
name: data.name,
description: data.description,
private: data.private,
}
const githubArray = data.integrations.github;

const response = await instance.post('teams', teamInfo)
if (response.data.errors) {
errorMessage(response.data.errors[0]);
return;
}
successMessage(`${data.name} successfully created`);

githubArray.length && githubArray.map( async (repoName) => {
let githubInfo = {
name: repoName,
type: 'github_repo'
}
try {
let gitRepo = await instance.post(`teams/${response.data.data.team.id}/accounts`, githubInfo)
if (gitRepo.data.errors) {
errorMessage(gitRepo.data.errors[0]);
return
}
successMessage(`${repoName} successfully created`);
} catch(error) {
errorMessage(`failed to create ${repoName}`);
}
successMessage(`${data.name} successfully created`);
})
.catch(error => {
dispatch(isLoading(false));
});

} catch(error) {
dispatch(isLoading(false));
}
};

export const clearTeams = () => dispatch => {
Expand Down
Loading

0 comments on commit f95c865

Please sign in to comment.