mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 05:25:44 +01:00
implemented create repository
This commit is contained in:
@@ -11,26 +11,50 @@ import {
|
||||
getRepositoryTypes,
|
||||
isFetchRepositoryTypesPending
|
||||
} from "../modules/repository-types";
|
||||
import {
|
||||
createRepo,
|
||||
createRepoReset,
|
||||
getCreateRepoFailure,
|
||||
isCreateRepoPending
|
||||
} from "../modules/repos";
|
||||
import type { Repository } from "../types/Repositories";
|
||||
import type { History } from "history";
|
||||
|
||||
type Props = {
|
||||
repositoryTypes: RepositoryType[],
|
||||
typesLoading: boolean,
|
||||
createLoading: boolean,
|
||||
error: Error,
|
||||
|
||||
// dispatch functions
|
||||
fetchRepositoryTypesIfNeeded: () => void,
|
||||
createRepo: (Repository, callback: () => void) => void,
|
||||
resetForm: () => void,
|
||||
|
||||
// context props
|
||||
t: string => string
|
||||
t: string => string,
|
||||
history: History
|
||||
};
|
||||
|
||||
class Create extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
this.props.resetForm();
|
||||
this.props.fetchRepositoryTypesIfNeeded();
|
||||
}
|
||||
|
||||
repoCreated = () => {
|
||||
const { history } = this.props;
|
||||
history.push("/repos");
|
||||
};
|
||||
|
||||
render() {
|
||||
const { typesLoading, repositoryTypes, error } = this.props;
|
||||
const {
|
||||
typesLoading,
|
||||
createLoading,
|
||||
repositoryTypes,
|
||||
createRepo,
|
||||
error
|
||||
} = this.props;
|
||||
|
||||
const { t } = this.props;
|
||||
return (
|
||||
@@ -39,8 +63,15 @@ class Create extends React.Component<Props> {
|
||||
subtitle={t("create.subtitle")}
|
||||
loading={typesLoading}
|
||||
error={error}
|
||||
showContentOnError={true}
|
||||
>
|
||||
<RepositoryForm repositoryTypes={repositoryTypes} />
|
||||
<RepositoryForm
|
||||
repositoryTypes={repositoryTypes}
|
||||
loading={createLoading}
|
||||
submitForm={repo => {
|
||||
createRepo(repo, this.repoCreated);
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
@@ -49,10 +80,13 @@ class Create extends React.Component<Props> {
|
||||
const mapStateToProps = state => {
|
||||
const repositoryTypes = getRepositoryTypes(state);
|
||||
const typesLoading = isFetchRepositoryTypesPending(state);
|
||||
const error = getFetchRepositoryTypesFailure(state);
|
||||
const createLoading = isCreateRepoPending(state);
|
||||
const error =
|
||||
getFetchRepositoryTypesFailure(state) || getCreateRepoFailure(state);
|
||||
return {
|
||||
repositoryTypes,
|
||||
typesLoading,
|
||||
createLoading,
|
||||
error
|
||||
};
|
||||
};
|
||||
@@ -61,6 +95,12 @@ const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchRepositoryTypesIfNeeded: () => {
|
||||
dispatch(fetchRepositoryTypesIfNeeded());
|
||||
},
|
||||
createRepo: (repository: Repository, callback: () => void) => {
|
||||
dispatch(createRepo(repository, callback));
|
||||
},
|
||||
resetForm: () => {
|
||||
dispatch(createRepoReset());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user