2018-08-06 15:41:20 +02:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import RepositoryForm from "../components/form";
|
|
|
|
|
import type { Repository } from "../types/Repositories";
|
|
|
|
|
import {
|
|
|
|
|
modifyRepo,
|
|
|
|
|
isModifyRepoPending,
|
|
|
|
|
getModifyRepoFailure
|
|
|
|
|
} from "../modules/repos";
|
|
|
|
|
import { withRouter } from "react-router-dom";
|
|
|
|
|
import type { History } from "history";
|
2018-08-07 15:08:44 +02:00
|
|
|
import ErrorNotification from "../../components/ErrorNotification";
|
2018-08-06 15:41:20 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
|
|
|
|
modifyRepo: (Repository, () => void) => void,
|
2018-08-07 15:08:44 +02:00
|
|
|
loading: boolean,
|
2018-08-06 15:41:20 +02:00
|
|
|
error: Error,
|
|
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
t: string => string,
|
|
|
|
|
history: History
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Edit extends React.Component<Props> {
|
|
|
|
|
repoModified = () => {
|
|
|
|
|
const { history, repository } = this.props;
|
|
|
|
|
history.push(`/repo/${repository.namespace}/${repository.name}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-08-07 15:08:44 +02:00
|
|
|
const { loading, error } = this.props;
|
2018-08-06 15:41:20 +02:00
|
|
|
return (
|
2018-08-07 15:08:44 +02:00
|
|
|
<div>
|
|
|
|
|
<ErrorNotification error={error} />
|
2018-08-06 15:41:20 +02:00
|
|
|
<RepositoryForm
|
|
|
|
|
repository={this.props.repository}
|
2018-08-07 15:08:44 +02:00
|
|
|
loading={loading}
|
2018-08-06 15:41:20 +02:00
|
|
|
submitForm={repo => {
|
|
|
|
|
this.props.modifyRepo(repo, this.repoModified);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2018-08-07 15:08:44 +02:00
|
|
|
</div>
|
2018-08-06 15:41:20 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const { namespace, name } = ownProps.repository;
|
2018-08-07 15:08:44 +02:00
|
|
|
const loading = isModifyRepoPending(state, namespace, name);
|
2018-08-06 15:41:20 +02:00
|
|
|
const error = getModifyRepoFailure(state, namespace, name);
|
|
|
|
|
return {
|
2018-08-07 15:08:44 +02:00
|
|
|
loading,
|
2018-08-06 15:41:20 +02:00
|
|
|
error
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
modifyRepo: (repo: Repository, callback: () => void) => {
|
|
|
|
|
dispatch(modifyRepo(repo, callback));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(translate("repos")(withRouter(Edit)));
|