2018-08-02 16:09:58 +02:00
|
|
|
// @flow
|
|
|
|
import React from "react";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import { translate } from "react-i18next";
|
2018-09-05 14:32:49 +02:00
|
|
|
import { Page } from "@scm-manager/ui-components";
|
2018-08-06 10:08:28 +02:00
|
|
|
import RepositoryForm from "../components/form";
|
2018-09-05 14:32:49 +02:00
|
|
|
import type { Repository, RepositoryType } from "@scm-manager/ui-types";
|
2018-08-02 16:09:58 +02:00
|
|
|
import {
|
|
|
|
fetchRepositoryTypesIfNeeded,
|
|
|
|
getFetchRepositoryTypesFailure,
|
|
|
|
getRepositoryTypes,
|
|
|
|
isFetchRepositoryTypesPending
|
2018-08-07 14:00:29 +02:00
|
|
|
} from "../modules/repositoryTypes";
|
2018-08-03 08:52:02 +02:00
|
|
|
import {
|
|
|
|
createRepo,
|
|
|
|
createRepoReset,
|
|
|
|
getCreateRepoFailure,
|
|
|
|
isCreateRepoPending
|
|
|
|
} from "../modules/repos";
|
|
|
|
import type { History } from "history";
|
2018-10-11 08:19:50 +02:00
|
|
|
import { getRepositoriesLink } from "../../modules/indexResource";
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
repositoryTypes: RepositoryType[],
|
|
|
|
typesLoading: boolean,
|
2018-08-03 08:52:02 +02:00
|
|
|
createLoading: boolean,
|
2018-08-02 16:09:58 +02:00
|
|
|
error: Error,
|
2018-10-11 08:19:50 +02:00
|
|
|
repoLink: string,
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
// dispatch functions
|
|
|
|
fetchRepositoryTypesIfNeeded: () => void,
|
2018-10-11 08:19:50 +02:00
|
|
|
createRepo: (link: string, Repository, callback: () => void) => void,
|
2018-08-03 08:52:02 +02:00
|
|
|
resetForm: () => void,
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
// context props
|
2018-08-03 08:52:02 +02:00
|
|
|
t: string => string,
|
|
|
|
history: History
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Create extends React.Component<Props> {
|
|
|
|
componentDidMount() {
|
2018-08-03 08:52:02 +02:00
|
|
|
this.props.resetForm();
|
2018-08-02 16:09:58 +02:00
|
|
|
this.props.fetchRepositoryTypesIfNeeded();
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:50:45 +01:00
|
|
|
repoCreated = (repo: Repository) => {
|
2018-08-03 08:52:02 +02:00
|
|
|
const { history } = this.props;
|
2019-01-22 10:50:45 +01:00
|
|
|
//TODO: Problem: repo name can be set in history, but repo namespace is not known without fetching anything
|
2018-08-03 08:52:02 +02:00
|
|
|
history.push("/repos");
|
|
|
|
};
|
|
|
|
|
2018-08-02 16:09:58 +02:00
|
|
|
render() {
|
2018-08-03 08:52:02 +02:00
|
|
|
const {
|
|
|
|
typesLoading,
|
|
|
|
createLoading,
|
|
|
|
repositoryTypes,
|
|
|
|
createRepo,
|
|
|
|
error
|
|
|
|
} = this.props;
|
2018-08-02 16:09:58 +02:00
|
|
|
|
2018-10-11 08:19:50 +02:00
|
|
|
const { t, repoLink } = this.props;
|
2018-08-02 16:09:58 +02:00
|
|
|
return (
|
|
|
|
<Page
|
|
|
|
title={t("create.title")}
|
|
|
|
subtitle={t("create.subtitle")}
|
|
|
|
loading={typesLoading}
|
|
|
|
error={error}
|
2018-08-03 08:52:02 +02:00
|
|
|
showContentOnError={true}
|
2018-08-02 16:09:58 +02:00
|
|
|
>
|
2018-08-03 08:52:02 +02:00
|
|
|
<RepositoryForm
|
|
|
|
repositoryTypes={repositoryTypes}
|
|
|
|
loading={createLoading}
|
|
|
|
submitForm={repo => {
|
2019-01-22 10:50:45 +01:00
|
|
|
createRepo(repoLink, repo, () => this.repoCreated(repo));
|
2018-08-03 08:52:02 +02:00
|
|
|
}}
|
|
|
|
/>
|
2018-08-02 16:09:58 +02:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
const repositoryTypes = getRepositoryTypes(state);
|
|
|
|
const typesLoading = isFetchRepositoryTypesPending(state);
|
2018-08-03 08:52:02 +02:00
|
|
|
const createLoading = isCreateRepoPending(state);
|
|
|
|
const error =
|
|
|
|
getFetchRepositoryTypesFailure(state) || getCreateRepoFailure(state);
|
2018-10-11 08:19:50 +02:00
|
|
|
const repoLink = getRepositoriesLink(state);
|
2018-08-02 16:09:58 +02:00
|
|
|
return {
|
|
|
|
repositoryTypes,
|
|
|
|
typesLoading,
|
2018-08-03 08:52:02 +02:00
|
|
|
createLoading,
|
2018-10-11 08:19:50 +02:00
|
|
|
error,
|
|
|
|
repoLink
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
fetchRepositoryTypesIfNeeded: () => {
|
|
|
|
dispatch(fetchRepositoryTypesIfNeeded());
|
2018-08-03 08:52:02 +02:00
|
|
|
},
|
2018-10-11 08:19:50 +02:00
|
|
|
createRepo: (
|
|
|
|
link: string,
|
|
|
|
repository: Repository,
|
|
|
|
callback: () => void
|
|
|
|
) => {
|
|
|
|
dispatch(createRepo(link, repository, callback));
|
2018-08-03 08:52:02 +02:00
|
|
|
},
|
|
|
|
resetForm: () => {
|
|
|
|
dispatch(createRepoReset());
|
2018-08-02 16:09:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(translate("repos")(Create));
|